organizr-functions.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. <?php
  2. function wizardConfig($array){
  3. foreach ($array['data'] as $items) {
  4. foreach ($items as $key => $value) {
  5. if($key == 'name'){
  6. $newKey = $value;
  7. }
  8. if($key == 'value'){
  9. $newValue = $value;
  10. }
  11. if(isset($newKey) && isset($newValue)){
  12. $$newKey = $newValue;
  13. }
  14. }
  15. }
  16. $location = cleanDirectory($location);
  17. $dbName = $dbName.'.db';
  18. $configVersion = $GLOBALS['installedVersion'];
  19. $configArray = array(
  20. 'dbName' => $dbName,
  21. 'dbLocation' => $location,
  22. 'license' => $license,
  23. 'organizrHash' => $hashKey,
  24. 'organizrAPI' => $api,
  25. 'registrationPassword' => $registrationPassword,
  26. );
  27. // Create Config
  28. if(createConfig($configArray)){
  29. // Call DB Create
  30. if(createDB($location,$dbName)){
  31. // Add in first user
  32. if(createFirstAdmin($location,$dbName,$username,$password,$email)){
  33. if(createToken($username,$email,gravatar($email),'Admin',0,$hashKey,1)){
  34. return true;
  35. }else{
  36. return 'token';
  37. }
  38. }else{
  39. return 'admin';
  40. }
  41. }else{
  42. return 'db';
  43. }
  44. }else{
  45. return 'config';
  46. }
  47. return false;
  48. }
  49. function register($array){
  50. // Grab username and password from login form
  51. foreach ($array['data'] as $items) {
  52. foreach ($items as $key => $value) {
  53. if($key == 'name'){
  54. $newKey = $value;
  55. }
  56. if($key == 'value'){
  57. $newValue = $value;
  58. }
  59. if(isset($newKey) && isset($newValue)){
  60. $$newKey = $newValue;
  61. }
  62. }
  63. }
  64. if($registrationPassword == $GLOBALS['registrationPassword']){
  65. $defaults = defaultUserGroup();
  66. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  67. if(createUser($username,$password,$defaults,$email)){
  68. writeLog('success', 'Registration Function - A User has registered', $username);
  69. if(createToken($username,$email,gravatar($email),$defaults['group'],$defaults['group_id'],$GLOBALS['organizrHash'],1)){
  70. writeLoginLog($username, 'success');
  71. writeLog('success', 'Login Function - A User has logged in', $username);
  72. return true;
  73. }
  74. }else{
  75. writeLog('error', 'Registration Function - An error occured', $username);
  76. return 'username taken';
  77. }
  78. }else{
  79. writeLog('warning', 'Registration Function - Wrong Password', $username);
  80. return 'mismatch';
  81. }
  82. }
  83. function editUser($array){
  84. return $array;
  85. }
  86. function logout(){
  87. coookie('delete','organizrToken');
  88. $GLOBALS['organizrUser'] = false;
  89. return true;
  90. }
  91. function qualifyRequest($accessLevelNeeded){
  92. if(getUserLevel() <= $accessLevelNeeded){
  93. return true;
  94. }else{
  95. return false;
  96. }
  97. }
  98. function getUserLevel(){
  99. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  100. // Check token or API key
  101. // If API key, return 0 for admin
  102. if(strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']){
  103. //DO API CHECK
  104. return 0;
  105. }elseif(isset($GLOBALS['organizrUser'])){
  106. return $GLOBALS['organizrUser']['groupID'];
  107. }
  108. // All else fails? return guest id
  109. return 999;
  110. }
  111. function organizrStatus(){
  112. $status = array();
  113. $dependenciesActive = array();
  114. $dependenciesInactive = array();
  115. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  116. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  117. foreach($extensions as $check){
  118. if(extension_loaded($check)){
  119. array_push($dependenciesActive,$check);
  120. }else{
  121. array_push($dependenciesInactive,$check);
  122. }
  123. }
  124. foreach($functions as $check){
  125. if(function_exists($check)){
  126. array_push($dependenciesActive,$check);
  127. }else{
  128. array_push($dependenciesInactive,$check);
  129. }
  130. }
  131. if(!file_exists('config'.DIRECTORY_SEPARATOR.'config.php')){
  132. $status['status'] = "wizard";//wizard - ok for test
  133. }
  134. if(count($dependenciesInactive)>0 || !is_writable(dirname(__DIR__,2))){
  135. $status['status'] = "dependencies";
  136. }
  137. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  138. $status['writable'] = is_writable(dirname(__DIR__,2)) ? 'yes' : 'no';
  139. $status['dependenciesActive'] = $dependenciesActive;
  140. $status['dependenciesInactive'] = $dependenciesInactive;
  141. $status['version'] = $GLOBALS['installedVersion'];
  142. $status['os'] = getOS();
  143. $status['php'] = phpversion();
  144. return $status;
  145. }
  146. function getSettingsMain(){
  147. return array(
  148. 'Github' => array(
  149. array(
  150. 'type' => 'select',
  151. 'name' => 'branch',
  152. 'label' => 'Branch',
  153. 'value' => $GLOBALS['branch'],
  154. 'options' => getBranches()
  155. ),
  156. array(
  157. 'type' => 'button',
  158. 'label' => 'Force Install Branch',
  159. 'class' => 'updateNow',
  160. 'icon' => 'fa fa-paper-plane',
  161. 'text' => 'Retrieve'
  162. )
  163. ),
  164. 'API' => array(
  165. array(
  166. 'type' => 'input',
  167. 'name' => 'organizrAPI',
  168. 'label' => 'Organizr API',
  169. 'value' => $GLOBALS['organizrAPI']
  170. ),
  171. array(
  172. 'type' => 'button',
  173. 'label' => 'Generate New API Key',
  174. 'class' => 'newAPIKey',
  175. 'icon' => 'fa fa-paper-plane',
  176. 'text' => 'Generate'
  177. )
  178. ),
  179. 'Authentication' => array(
  180. array(
  181. 'type' => 'select',
  182. 'name' => 'authType',
  183. 'id' => 'authSelect',
  184. 'label' => 'Authentication Type',
  185. 'value' => $GLOBALS['authType'],
  186. 'options' => getAuthTypes()
  187. ),
  188. array(
  189. 'type' => 'select',
  190. 'name' => 'authBackend',
  191. 'id' => 'authBackendSelect',
  192. 'label' => 'Authentication Backend',
  193. 'class' => 'backendAuth switchAuth',
  194. 'value' => $GLOBALS['authBackend'],
  195. 'options' => getAuthBackends()
  196. ),
  197. array(
  198. 'type' => 'input',
  199. 'name' => 'plexToken',
  200. 'class' => 'plexAuth switchAuth',
  201. 'label' => 'Plex Token',
  202. 'value' => $GLOBALS['plexToken'],
  203. 'placeholder' => 'Use Get Token Button'
  204. ),
  205. array(
  206. 'type' => 'button',
  207. 'label' => 'Get Plex Token',
  208. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  209. 'icon' => 'fa fa-paper-plane',
  210. 'text' => 'Retrieve',
  211. 'href' => '#auth-plex-token-form',
  212. 'attr' => 'data-effect="mfp-3d-unfold"'
  213. ),
  214. array(
  215. 'type' => 'input',
  216. 'name' => 'plexID',
  217. 'class' => 'plexAuth switchAuth',
  218. 'label' => 'Plex Machine',
  219. 'value' => $GLOBALS['plexID'],
  220. 'placeholder' => 'Use Get Plex Machine Button'
  221. ),
  222. array(
  223. 'type' => 'button',
  224. 'label' => 'Get Plex Machine',
  225. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  226. 'icon' => 'fa fa-paper-plane',
  227. 'text' => 'Retrieve',
  228. 'href' => '#auth-plex-machine-form',
  229. 'attr' => 'data-effect="mfp-3d-unfold"'
  230. ),
  231. array(
  232. 'type' => 'input',
  233. 'name' => 'authBackendHost',
  234. 'class' => 'ldapAuth ftpAuth switchAuth',
  235. 'label' => 'Host Address',
  236. 'value' => $GLOBALS['authBackendHost'],
  237. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  238. ),
  239. array(
  240. 'type' => 'input',
  241. 'name' => 'authBaseDN',
  242. 'class' => 'ldapAuth switchAuth',
  243. 'label' => 'Host Base DN',
  244. 'value' => $GLOBALS['authBaseDN'],
  245. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  246. ),
  247. array(
  248. 'type' => 'input',
  249. 'name' => 'embyURL',
  250. 'class' => 'embyAuth switchAuth',
  251. 'label' => 'Emby URL',
  252. 'value' => $GLOBALS['embyURL'],
  253. 'placeholder' => 'http(s)://hostname:port'
  254. ),
  255. array(
  256. 'type' => 'input',
  257. 'name' => 'embyToken',
  258. 'class' => 'embyAuth switchAuth',
  259. 'label' => 'Emby Token',
  260. 'value' => $GLOBALS['embyToken'],
  261. 'placeholder' => ''
  262. )
  263. /*array(
  264. 'type' => 'button',
  265. 'label' => 'Send Test',
  266. 'class' => 'phpmSendTestEmail',
  267. 'icon' => 'fa fa-paper-plane',
  268. 'text' => 'Send'
  269. )*/
  270. )
  271. );
  272. }
  273. function getSSO(){
  274. return array(
  275. 'Plex' => array(
  276. array(
  277. 'type' => 'input',
  278. 'name' => 'plexToken',
  279. 'label' => 'Plex Token',
  280. 'value' => $GLOBALS['plexToken'],
  281. 'placeholder' => 'Use Get Token Button'
  282. ),
  283. array(
  284. 'type' => 'button',
  285. 'label' => 'Get Plex Token',
  286. 'class' => 'popup-with-form getPlexTokenSSO',
  287. 'icon' => 'fa fa-paper-plane',
  288. 'text' => 'Retrieve',
  289. 'href' => '#sso-plex-token-form',
  290. 'attr' => 'data-effect="mfp-3d-unfold"'
  291. ),
  292. array(
  293. 'type' => 'input',
  294. 'name' => 'plexID',
  295. 'label' => 'Plex Machine',
  296. 'value' => $GLOBALS['plexID'],
  297. 'placeholder' => 'Use Get Plex Machine Button'
  298. ),
  299. array(
  300. 'type' => 'button',
  301. 'label' => 'Get Plex Machine',
  302. 'class' => 'popup-with-form getPlexMachineSSO',
  303. 'icon' => 'fa fa-paper-plane',
  304. 'text' => 'Retrieve',
  305. 'href' => '#sso-plex-machine-form',
  306. 'attr' => 'data-effect="mfp-3d-unfold"'
  307. ),
  308. array(
  309. 'type' => 'input',
  310. 'name' => 'plexAdmin',
  311. 'label' => 'Admin Username',
  312. 'value' => $GLOBALS['plexAdmin'],
  313. 'placeholder' => 'Admin username for Plex'
  314. ),
  315. array(
  316. 'type' => 'blank',
  317. 'label' => ''
  318. ),
  319. array(
  320. 'type' => 'html',
  321. 'label' => 'Plex Note',
  322. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  323. ),
  324. array(
  325. 'type' => 'switch',
  326. 'name' => 'ssoPlex',
  327. 'label' => 'Enable',
  328. 'value' => $GLOBALS['ssoPlex']
  329. )
  330. ),
  331. 'Ombi' => array(
  332. array(
  333. 'type' => 'input',
  334. 'name' => 'ombiURL',
  335. 'label' => 'Ombi URL',
  336. 'value' => $GLOBALS['ombiURL'],
  337. 'placeholder' => 'http(s)://hostname:port'
  338. ),
  339. array(
  340. 'type' => 'switch',
  341. 'name' => 'ssoOmbi',
  342. 'label' => 'Enable',
  343. 'value' => $GLOBALS['ssoOmbi']
  344. )
  345. ),
  346. 'Tautulli' => array(
  347. array(
  348. 'type' => 'input',
  349. 'name' => 'tautulliURL',
  350. 'label' => 'Tautulli URL',
  351. 'value' => $GLOBALS['tautulliURL'],
  352. 'placeholder' => 'http(s)://hostname:port'
  353. ),
  354. array(
  355. 'type' => 'switch',
  356. 'name' => 'ssoTautulli',
  357. 'label' => 'Enable',
  358. 'value' => $GLOBALS['ssoTautulli']
  359. )
  360. )
  361. );
  362. }
  363. function loadAppearance(){
  364. $appearance = array();
  365. $appearance['logo'] = $GLOBALS['logo'];
  366. $appearance['title'] = $GLOBALS['title'];
  367. $appearance['useLogo'] = $GLOBALS['useLogo'];
  368. $appearance['headerColor'] = $GLOBALS['headerColor'];
  369. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  370. return $appearance;
  371. }
  372. function getCustomizeAppearance(){
  373. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  374. return array(
  375. 'Top Bar' => array(
  376. array(
  377. 'type' => 'input',
  378. 'name' => 'logo',
  379. 'label' => 'Logo',
  380. 'value' => $GLOBALS['logo']
  381. ),
  382. array(
  383. 'type' => 'input',
  384. 'name' => 'title',
  385. 'label' => 'Title',
  386. 'value' => $GLOBALS['title']
  387. ),
  388. array(
  389. 'type' => 'switch',
  390. 'name' => 'useLogo',
  391. 'label' => 'Use Logo instead of Title',
  392. 'value' => $GLOBALS['useLogo']
  393. )
  394. ),
  395. 'Login Page' => array(
  396. array(
  397. 'type' => 'input',
  398. 'name' => 'loginWallpaper',
  399. 'label' => 'Login Wallpaper',
  400. 'value' => $GLOBALS['loginWallpaper']
  401. )
  402. ),
  403. 'Colors & Themes' => array(
  404. array(
  405. 'type' => 'input',
  406. 'name' => 'headerColor',
  407. 'label' => 'Nav Bar Color',
  408. 'value' => $GLOBALS['headerColor'],
  409. 'class' => 'colorpicker',
  410. 'disabled' => true
  411. ),
  412. array(
  413. 'type' => 'input',
  414. 'name' => 'headerTextColor',
  415. 'label' => 'Nav Bar Text Color',
  416. 'value' => $GLOBALS['headerTextColor'],
  417. 'class' => 'colorpicker',
  418. 'disabled' => true
  419. ),
  420. array(
  421. 'type' => 'input',
  422. 'name' => 'sidebarColor',
  423. 'label' => 'Side Bar Color',
  424. 'value' => $GLOBALS['sidebarColor'],
  425. 'class' => 'colorpicker',
  426. 'disabled' => true
  427. ),
  428. array(
  429. 'type' => 'input',
  430. 'name' => 'sidebarTextColor',
  431. 'label' => 'Side Bar Text Color',
  432. 'value' => $GLOBALS['sidebarTextColor'],
  433. 'class' => 'colorpicker',
  434. 'disabled' => true
  435. ),
  436. array(
  437. 'type' => 'select',
  438. 'name' => 'theme',
  439. 'label' => 'Theme',
  440. 'class' => 'themeChanger',
  441. 'value' => $GLOBALS['theme'],
  442. 'options' => getThemes()
  443. ),
  444. array(
  445. 'type' => 'select',
  446. 'name' => 'style',
  447. 'label' => 'Style',
  448. 'class' => 'styleChanger',
  449. 'value' => $GLOBALS['style'],
  450. 'options' => array(
  451. array(
  452. 'name' => 'Light',
  453. 'value' => 'light'
  454. ),
  455. array(
  456. 'name' => 'Dark',
  457. 'value' => 'dark'
  458. ),
  459. array(
  460. 'name' => 'Horizontal',
  461. 'value' => 'horizontal'
  462. )
  463. )
  464. )
  465. )
  466. );
  467. }
  468. }
  469. function editAppearance($array){
  470. switch ($array['data']['value']) {
  471. case 'true':
  472. $array['data']['value'] = (bool) true;
  473. break;
  474. case 'false':
  475. $array['data']['value'] = (bool) false;
  476. break;
  477. default:
  478. $array['data']['value'] = $array['data']['value'];
  479. }
  480. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  481. switch ($array['data']['action']) {
  482. case 'editCustomizeAppearance':
  483. $newItem = array(
  484. $array['data']['name'] => $array['data']['value']
  485. );
  486. return (updateConfig($newItem)) ? true : false;
  487. break;
  488. default:
  489. # code...
  490. break;
  491. }
  492. }
  493. function updateConfigItem($array){
  494. switch ($array['data']['value']) {
  495. case 'true':
  496. $array['data']['value'] = (bool) true;
  497. break;
  498. case 'false':
  499. $array['data']['value'] = (bool) false;
  500. break;
  501. default:
  502. $array['data']['value'] = $array['data']['value'];
  503. }
  504. // Hash
  505. if($array['data']['type'] == 'password'){
  506. $array['data']['value'] = encrypt($array['data']['value']);
  507. }
  508. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  509. $newItem = array(
  510. $array['data']['name'] => $array['data']['value']
  511. );
  512. return (updateConfig($newItem)) ? true : false;
  513. }
  514. function getPlugins(){
  515. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  516. $pluginList = array();
  517. foreach($GLOBALS['plugins'] as $plugin){
  518. foreach ($plugin as $key => $value) {
  519. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'].'-enabled'];
  520. }
  521. $pluginList = array_merge($pluginList, $plugin);
  522. }
  523. return $pluginList;
  524. }
  525. return false;
  526. }
  527. function editPlugins($array){
  528. switch ($array['data']['action']) {
  529. case 'enable':
  530. $newItem = array(
  531. $array['data']['configName'] => true
  532. );
  533. writeLog('success', 'Plugin Function - Enabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  534. return (updateConfig($newItem)) ? true : false;
  535. break;
  536. case 'disable':
  537. $newItem = array(
  538. $array['data']['configName'] => false
  539. );
  540. writeLog('success', 'Plugin Function - Disabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  541. return (updateConfig($newItem)) ? true : false;
  542. break;
  543. default:
  544. # code...
  545. break;
  546. }
  547. }
  548. function auth(){
  549. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  550. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  551. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  552. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  553. $group = isset($_GET['group']) ? $_GET['group'] : 0;
  554. $currentIP = userIP();
  555. $currentUser = $GLOBALS['organizrUser']['username'];
  556. if ($whitelist) {
  557. if(in_array($currentIP, arrayIP($whitelist))) {
  558. !$debug ? exit(http_response_code(200)) : die("$currentIP Whitelist Authorized");
  559. }
  560. }
  561. if ($blacklist) {
  562. if(in_array($currentIP, arrayIP($blacklist))) {
  563. !$debug ? exit(http_response_code(401)) : die("$currentIP Blacklisted");
  564. }
  565. }
  566. if($group !== null){
  567. if(qualifyRequest($group)){
  568. !$debug ? exit(http_response_code(200)) : die("$currentUser on $currentIP Authorized");
  569. }else{
  570. !$debug ? exit(http_response_code(401)) : die("$currentUser on $currentIP Not Authorized");
  571. }
  572. }else{
  573. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  574. }
  575. }
  576. function logoOrText(){
  577. if($GLOBALS['useLogo'] == false){
  578. return '<h1>'.$GLOBALS['title'].'</h1>';
  579. }else{
  580. return '<img style="max-width: 350px;" src="'.$GLOBALS['logo'].'" alt="Home" />';
  581. }
  582. }
  583. function getImages(){
  584. $dirname = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  585. $path = 'plugins/images/tabs/';
  586. $images = scandir($dirname);
  587. $ignore = Array(".", "..", "._.DS_Store", ".DS_Store");
  588. $allIcons = array();
  589. foreach($images as $image){
  590. if(!in_array($image, $ignore)) {
  591. $allIcons[] = $path.$image;
  592. }
  593. }
  594. return $allIcons;
  595. }
  596. function editImages(){
  597. $array = array();
  598. $postCheck = array_filter($_POST);
  599. $filesCheck = array_filter($_FILES);
  600. if(!empty($postCheck)){
  601. if($_POST['data']['action'] == 'deleteImage'){
  602. if(file_exists(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])){
  603. writeLog('success', 'Image Manager Function - Deleted Image ['.$_POST['data']['imageName'].']', $GLOBALS['organizrUser']['username']);
  604. return (unlink(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) ? true : false;
  605. }
  606. }
  607. }
  608. if(!empty($filesCheck)){
  609. ini_set('upload_max_filesize', '10M');
  610. ini_set('post_max_size', '10M');
  611. $tempFile = $_FILES['file']['tmp_name'];
  612. $targetPath = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  613. $targetFile = $targetPath. $_FILES['file']['name'];
  614. return (move_uploaded_file($tempFile,$targetFile)) ? true : false;
  615. }
  616. return false;
  617. }
  618. function getThemes(){
  619. $themes = array();
  620. foreach (glob(dirname(__DIR__,2).DIRECTORY_SEPARATOR.'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename){
  621. $themes[] = array(
  622. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  623. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  624. );
  625. }
  626. return $themes;
  627. }
  628. function getBranches(){
  629. return array(
  630. array(
  631. 'name' => 'Develop',
  632. 'value' => 'v2-develop'
  633. ),
  634. array(
  635. 'name' => 'Master',
  636. 'value' => 'v2-master'
  637. )
  638. );
  639. }
  640. function getAuthTypes(){
  641. return array(
  642. array(
  643. 'name' => 'Organizr DB',
  644. 'value' => 'internal'
  645. ),
  646. array(
  647. 'name' => 'Organizr DB + Backend',
  648. 'value' => 'both'
  649. ),
  650. array(
  651. 'name' => 'Backend Only',
  652. 'value' => 'external'
  653. )
  654. );
  655. }
  656. function getAuthBackends(){
  657. $backendOptions = array();
  658. $backendOptions[] = array(
  659. 'name' => 'Choose Backend',
  660. 'value' => false,
  661. 'disabled' => true
  662. );
  663. foreach (array_filter(get_defined_functions()['user'],function($v) { return strpos($v, 'plugin_auth_') === 0; }) as $value) {
  664. $name = str_replace('plugin_auth_','',$value);
  665. if (strpos($name, 'disabled') === false) {
  666. $backendOptions[] = array(
  667. 'name' => ucwords(str_replace('_',' ',$name)),
  668. 'value' => $name
  669. );
  670. } else {
  671. $backendOptions[] = array(
  672. 'name' => $value(),
  673. 'value' => 'none',
  674. 'disabled' => true,
  675. );
  676. }
  677. }
  678. ksort($backendOptions);
  679. return $backendOptions;
  680. }
  681. function wizardPath($array){
  682. $path = $array['data']['path'];
  683. if(file_exists($path)){
  684. if(is_writable($path)){
  685. return true;
  686. }
  687. }else{
  688. if(is_writable(dirname($path, 1))){
  689. if(mkdir($path, 0760, true)) {
  690. return true;
  691. }
  692. }
  693. }
  694. return 'permissions';
  695. }
  696. function groupSelect(){
  697. $groups = allGroups();
  698. $select = array();
  699. foreach ($groups as $key => $value) {
  700. $select[] = array(
  701. 'name' => $value['group'],
  702. 'value' => $value['group_id']
  703. );
  704. }
  705. return $select;
  706. }
  707. function getImage() {
  708. $refresh = false;
  709. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  710. if (!file_exists($cacheDirectory)) {
  711. mkdir($cacheDirectory, 0777, true);
  712. }
  713. @$image_url = $_GET['img'];
  714. @$key = $_GET['key'];
  715. @$image_height = $_GET['height'];
  716. @$image_width = $_GET['width'];
  717. @$source = $_GET['source'];
  718. @$itemType = $_GET['type'];
  719. if(strpos($key, '$') !== false){
  720. $key = explode('$', $key)[0];
  721. $refresh = true;
  722. }
  723. switch ($source) {
  724. case 'plex':
  725. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  726. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  727. break;
  728. case 'emby':
  729. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  730. $imgParams = array();
  731. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  732. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  733. $image_src = $embyAddress . '/Items/'.$image_url.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  734. break;
  735. default:
  736. # code...
  737. break;
  738. }
  739. if(isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  740. $cachefile = $cacheDirectory.$key.'.jpg';
  741. $cachetime = 604800;
  742. // Serve from the cache if it is younger than $cachetime
  743. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  744. header("Content-type: image/jpeg");
  745. //@readfile($cachefile);
  746. echo @curl('get',$cachefile)['content'];
  747. exit;
  748. }
  749. ob_start(); // Start the output buffer
  750. header('Content-type: image/jpeg');
  751. //@readfile($image_src);
  752. echo @curl('get',$image_src)['content'];
  753. // Cache the output to a file
  754. $fp = fopen($cachefile, 'wb');
  755. fwrite($fp, ob_get_contents());
  756. fclose($fp);
  757. ob_end_flush(); // Send the output to the browser
  758. die();
  759. } else {
  760. die("Invalid Request");
  761. }
  762. }
  763. function downloader($array){
  764. switch ($array['data']['source']) {
  765. case 'sabnzbd':
  766. switch ($array['data']['action']) {
  767. case 'resume':
  768. case 'pause':
  769. sabnzbdAction($array['data']['action'],$array['data']['target']);
  770. break;
  771. default:
  772. # code...
  773. break;
  774. }
  775. break;
  776. case 'nzbget':
  777. break;
  778. default:
  779. # code...
  780. break;
  781. }
  782. }
  783. function sabnzbdAction($action=null, $target=null) {
  784. if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
  785. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  786. switch ($action) {
  787. case 'pause':
  788. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value='.$target.'&' : 'mode=pause';
  789. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  790. break;
  791. case 'resume':
  792. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value='.$target.'&' : 'mode=resume';
  793. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  794. break;
  795. default:
  796. # code...
  797. break;
  798. }
  799. try{
  800. $options = (localURL($url)) ? array('verify' => false ) : array();
  801. $response = Requests::get($url, array(), $options);
  802. if($response->success){
  803. $api['content'] = json_decode($response->body, true);
  804. }
  805. }catch( Requests_Exception $e ) {
  806. writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  807. };
  808. $api['content'] = isset($api['content']) ? $api['content'] : false;
  809. return $api;
  810. }
  811. }
  812. /*
  813. function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  814. try {
  815. $mail = new PHPMailer(true);
  816. $mail->isSMTP();
  817. $mail->Host = $GLOBALS['smtpHost'];
  818. $mail->SMTPAuth = $GLOBALS['smtpHostAuth'];
  819. $mail->Username = $GLOBALS['smtpHostUsername'];
  820. $mail->Password = $GLOBALS['smtpHostPassword'];
  821. $mail->SMTPSecure = $GLOBALS['smtpHostType'];
  822. $mail->Port = $GLOBALS['smtpHostPort'];
  823. $mail->setFrom($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  824. $mail->addReplyTo($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  825. $mail->isHTML(true);
  826. if($email){
  827. $mail->addAddress($email, $username);
  828. }
  829. if($cc){
  830. $mail->addCC($cc);
  831. }
  832. if($bcc){
  833. if(strpos($bcc , ',') === false){
  834. $mail->addBCC($bcc);
  835. }else{
  836. $allEmails = explode(",",$bcc);
  837. foreach($allEmails as $gotEmail){
  838. $mail->addBCC($gotEmail);
  839. }
  840. }
  841. }
  842. $mail->Subject = $subject;
  843. $mail->Body = $body;
  844. $mail->send();
  845. writeLog('success', 'Mail Function - E-Mail Sent', $GLOBALS['organizrUser']['username']);
  846. return true;
  847. } catch (Exception $e) {
  848. writeLog('error', 'Mail Function - E-Mail Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  849. return false;
  850. }
  851. return false;
  852. }
  853. //EMAIL SHIT
  854. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  855. try {
  856. $mail = new PHPMailer(true);
  857. $mail->isSMTP();
  858. $mail->Host = $host;
  859. $mail->SMTPAuth = $auth;
  860. $mail->Username = $username;
  861. $mail->Password = $password;
  862. $mail->SMTPSecure = $type;
  863. $mail->Port = $port;
  864. $mail->setFrom($from, $sendername);
  865. $mail->addReplyTo($from, $sendername);
  866. $mail->isHTML(true);
  867. $mail->addAddress($to, "Organizr Admin");
  868. $mail->Subject = "Organizr Test E-Mail";
  869. $mail->Body = "This was just a test!";
  870. $mail->send();
  871. writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']);
  872. return true;
  873. } catch (Exception $e) {
  874. writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  875. return false;
  876. }
  877. return false;
  878. }
  879. */