organizr-functions.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. <?php
  2. function organizrSpecialSettings()
  3. {
  4. $refreshSearch = "Refresh";
  5. return array(
  6. 'homepage' => array(
  7. 'refresh' => array_filter($GLOBALS, function ($k) use ($refreshSearch) {
  8. return stripos($k, $refreshSearch) !== false;
  9. }, ARRAY_FILTER_USE_KEY),
  10. 'search' => array(
  11. 'enabled' => (qualifyRequest($GLOBALS['mediaSearchAuth']) && $GLOBALS['mediaSearch'] == true && $GLOBALS['plexToken']) ? true : false,
  12. 'type' => $GLOBALS['mediaSearchType'],
  13. ),
  14. 'ombi' => array(
  15. 'enabled' => (qualifyRequest($GLOBALS['homepageOmbiAuth']) && $GLOBALS['homepageOmbiEnabled'] == true && $GLOBALS['ssoOmbi'] && isset($_COOKIE['Auth'])) ? true : false,
  16. 'auth' => (qualifyRequest($GLOBALS['homepageOmbiAuth'])) ? true : false,
  17. 'sso' => ($GLOBALS['ssoOmbi']) ? true : false,
  18. 'cookie' => (isset($_COOKIE['Auth'])) ? true : false,
  19. ),
  20. 'options' => array(
  21. 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
  22. )
  23. )
  24. );
  25. }
  26. function wizardConfig($array)
  27. {
  28. foreach ($array['data'] as $items) {
  29. foreach ($items as $key => $value) {
  30. if ($key == 'name') {
  31. $newKey = $value;
  32. }
  33. if ($key == 'value') {
  34. $newValue = $value;
  35. }
  36. if (isset($newKey) && isset($newValue)) {
  37. $$newKey = $newValue;
  38. }
  39. }
  40. }
  41. $location = cleanDirectory($location);
  42. $dbName = $dbName . '.db';
  43. $configVersion = $GLOBALS['installedVersion'];
  44. $configArray = array(
  45. 'dbName' => $dbName,
  46. 'dbLocation' => $location,
  47. 'license' => $license,
  48. 'organizrHash' => $hashKey,
  49. 'organizrAPI' => $api,
  50. 'registrationPassword' => $registrationPassword,
  51. );
  52. // Create Config
  53. $GLOBALS['dbLocation'] = $location;
  54. $GLOBALS['dbName'] = $dbName;
  55. if (createConfig($configArray)) {
  56. // Call DB Create
  57. if (createDB($location, $dbName)) {
  58. // Add in first user
  59. if (createFirstAdmin($location, $dbName, $username, $password, $email)) {
  60. if (createToken($username, $email, gravatar($email), 'Admin', 0, $hashKey, 1)) {
  61. return true;
  62. } else {
  63. return 'token';
  64. }
  65. } else {
  66. return 'admin';
  67. }
  68. } else {
  69. return 'db';
  70. }
  71. } else {
  72. return 'config';
  73. }
  74. return false;
  75. }
  76. function register($array)
  77. {
  78. // Grab username and password from login form
  79. foreach ($array['data'] as $items) {
  80. foreach ($items as $key => $value) {
  81. if ($key == 'name') {
  82. $newKey = $value;
  83. }
  84. if ($key == 'value') {
  85. $newValue = $value;
  86. }
  87. if (isset($newKey) && isset($newValue)) {
  88. $$newKey = $newValue;
  89. }
  90. }
  91. }
  92. if ($registrationPassword == $GLOBALS['registrationPassword']) {
  93. $defaults = defaultUserGroup();
  94. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  95. if (createUser($username, $password, $defaults, $email)) {
  96. writeLog('success', 'Registration Function - A User has registered', $username);
  97. if (createToken($username, $email, gravatar($email), $defaults['group'], $defaults['group_id'], $GLOBALS['organizrHash'], 1)) {
  98. writeLoginLog($username, 'success');
  99. writeLog('success', 'Login Function - A User has logged in', $username);
  100. return true;
  101. }
  102. } else {
  103. writeLog('error', 'Registration Function - An error occured', $username);
  104. return 'username taken';
  105. }
  106. } else {
  107. writeLog('warning', 'Registration Function - Wrong Password', $username);
  108. return 'mismatch';
  109. }
  110. }
  111. function removeFile($array)
  112. {
  113. $filePath = $array['data']['path'];
  114. $fileName = $array['data']['name'];
  115. if (file_exists($filePath)) {
  116. if (unlink($filePath)) {
  117. writeLog('success', 'Log Management Function - Log: ' . $fileName . ' has been purged/deleted', 'SYSTEM');
  118. return true;
  119. } else {
  120. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' - Error Occured', 'SYSTEM');
  121. return false;
  122. }
  123. } else {
  124. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' does not exist', 'SYSTEM');
  125. return false;
  126. }
  127. }
  128. function recover($array)
  129. {
  130. $email = $array['data']['email'];
  131. $newPassword = randString(10);
  132. try {
  133. $connect = new Dibi\Connection([
  134. 'driver' => 'sqlite3',
  135. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  136. ]);
  137. $isUser = $connect->fetch('SELECT * FROM users WHERE email = ? COLLATE NOCASE', $email);
  138. if ($isUser) {
  139. $connect->query('
  140. UPDATE users SET', [
  141. 'password' => password_hash($newPassword, PASSWORD_BCRYPT)
  142. ], '
  143. WHERE email=? COLLATE NOCASE', $email);
  144. if ($GLOBALS['PHPMAILER-enabled']) {
  145. $emailTemplate = array(
  146. 'type' => 'reset',
  147. 'body' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'],
  148. 'subject' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'],
  149. 'user' => $isUser['username'],
  150. 'password' => $newPassword,
  151. 'inviteCode' => null,
  152. );
  153. $emailTemplate = phpmEmailTemplate($emailTemplate);
  154. $sendEmail = array(
  155. 'to' => $email,
  156. 'user' => $isUser['username'],
  157. 'subject' => $emailTemplate['subject'],
  158. 'body' => phpmBuildEmail($emailTemplate),
  159. );
  160. phpmSendEmail($sendEmail);
  161. }
  162. writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
  163. return true;
  164. } else {
  165. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  166. return 'an error occured';
  167. }
  168. } catch (Dibi\Exception $e) {
  169. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  170. return 'an error occured';
  171. }
  172. }
  173. function editUser($array)
  174. {
  175. if ($array['data']['username'] == '' && $array['data']['username'] == '') {
  176. return 'Username/email not set';
  177. }
  178. try {
  179. $connect = new Dibi\Connection([
  180. 'driver' => 'sqlite3',
  181. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  182. ]);
  183. if (!usernameTakenExcept($array['data']['username'], $array['data']['email'], $GLOBALS['organizrUser']['userID'])) {
  184. $connect->query('
  185. UPDATE users SET', [
  186. 'username' => $array['data']['username'],
  187. 'email' => $array['data']['email'],
  188. ], '
  189. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  190. if (!empty($array['data']['password'])) {
  191. $connect->query('
  192. UPDATE users SET', [
  193. 'password' => password_hash($array['data']['password'], PASSWORD_BCRYPT)
  194. ], '
  195. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  196. }
  197. writeLog('success', 'User Management Function - User: ' . $array['data']['username'] . '\'s info was changed', $GLOBALS['organizrUser']['username']);
  198. return true;
  199. } else {
  200. return 'Username/Email Already Taken';
  201. }
  202. } catch (Dibi\Exception $e) {
  203. writeLog('error', 'User Management Function - Error - User: ' . $array['data']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  204. return 'an error occured';
  205. }
  206. }
  207. function logout()
  208. {
  209. coookie('delete', 'organizrToken');
  210. coookie('delete', 'mpt');
  211. coookie('delete', 'Auth');
  212. $GLOBALS['organizrUser'] = false;
  213. return true;
  214. }
  215. function qualifyRequest($accessLevelNeeded)
  216. {
  217. if (getUserLevel() <= $accessLevelNeeded) {
  218. return true;
  219. } else {
  220. return false;
  221. }
  222. }
  223. function getUserLevel()
  224. {
  225. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  226. // Check token or API key
  227. // If API key, return 0 for admin
  228. if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
  229. //DO API CHECK
  230. return 0;
  231. } elseif (isset($GLOBALS['organizrUser'])) {
  232. return $GLOBALS['organizrUser']['groupID'];
  233. }
  234. // All else fails? return guest id
  235. return 999;
  236. }
  237. function organizrStatus()
  238. {
  239. $status = array();
  240. $dependenciesActive = array();
  241. $dependenciesInactive = array();
  242. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  243. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  244. foreach ($extensions as $check) {
  245. if (extension_loaded($check)) {
  246. array_push($dependenciesActive, $check);
  247. } else {
  248. array_push($dependenciesInactive, $check);
  249. }
  250. }
  251. foreach ($functions as $check) {
  252. if (function_exists($check)) {
  253. array_push($dependenciesActive, $check);
  254. } else {
  255. array_push($dependenciesInactive, $check);
  256. }
  257. }
  258. if (!file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
  259. $status['status'] = "wizard";//wizard - ok for test
  260. }
  261. if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, '7.0.0') >= 0)) {
  262. $status['status'] = "dependencies";
  263. }
  264. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  265. $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
  266. $status['minVersion'] = (version_compare(PHP_VERSION, '7.0.0') >= 0) ? 'yes' : 'no';
  267. $status['dependenciesActive'] = $dependenciesActive;
  268. $status['dependenciesInactive'] = $dependenciesInactive;
  269. $status['version'] = $GLOBALS['installedVersion'];
  270. $status['os'] = getOS();
  271. $status['php'] = phpversion();
  272. return $status;
  273. }
  274. function getSettingsMain()
  275. {
  276. return array(
  277. 'Github' => array(
  278. array(
  279. 'type' => 'select',
  280. 'name' => 'branch',
  281. 'label' => 'Branch',
  282. 'value' => $GLOBALS['branch'],
  283. 'options' => getBranches()
  284. ),
  285. array(
  286. 'type' => 'button',
  287. 'label' => 'Force Install Branch',
  288. 'class' => 'updateNow',
  289. 'icon' => 'fa fa-download',
  290. 'text' => 'Retrieve'
  291. )
  292. ),
  293. 'API' => array(
  294. array(
  295. 'type' => 'password-alt',
  296. 'name' => 'organizrAPI',
  297. 'label' => 'Organizr API',
  298. 'value' => $GLOBALS['organizrAPI']
  299. ),
  300. array(
  301. 'type' => 'button',
  302. 'label' => 'Generate New API Key',
  303. 'class' => 'newAPIKey',
  304. 'icon' => 'fa fa-refresh',
  305. 'text' => 'Generate'
  306. )
  307. ),
  308. 'Authentication' => array(
  309. array(
  310. 'type' => 'select',
  311. 'name' => 'authType',
  312. 'id' => 'authSelect',
  313. 'label' => 'Authentication Type',
  314. 'value' => $GLOBALS['authType'],
  315. 'options' => getAuthTypes()
  316. ),
  317. array(
  318. 'type' => 'select',
  319. 'name' => 'authBackend',
  320. 'id' => 'authBackendSelect',
  321. 'label' => 'Authentication Backend',
  322. 'class' => 'backendAuth switchAuth',
  323. 'value' => $GLOBALS['authBackend'],
  324. 'options' => getAuthBackends()
  325. ),
  326. array(
  327. 'type' => 'password-alt',
  328. 'name' => 'plexToken',
  329. 'class' => 'plexAuth switchAuth',
  330. 'label' => 'Plex Token',
  331. 'value' => $GLOBALS['plexToken'],
  332. 'placeholder' => 'Use Get Token Button'
  333. ),
  334. array(
  335. 'type' => 'button',
  336. 'label' => 'Get Plex Token',
  337. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  338. 'icon' => 'fa fa-ticket',
  339. 'text' => 'Retrieve',
  340. 'href' => '#auth-plex-token-form',
  341. 'attr' => 'data-effect="mfp-3d-unfold"'
  342. ),
  343. array(
  344. 'type' => 'password-alt',
  345. 'name' => 'plexID',
  346. 'class' => 'plexAuth switchAuth',
  347. 'label' => 'Plex Machine',
  348. 'value' => $GLOBALS['plexID'],
  349. 'placeholder' => 'Use Get Plex Machine Button'
  350. ),
  351. array(
  352. 'type' => 'button',
  353. 'label' => 'Get Plex Machine',
  354. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  355. 'icon' => 'fa fa-id-badge',
  356. 'text' => 'Retrieve',
  357. 'href' => '#auth-plex-machine-form',
  358. 'attr' => 'data-effect="mfp-3d-unfold"'
  359. ),
  360. array(
  361. 'type' => 'input',
  362. 'name' => 'authBackendHost',
  363. 'class' => 'ldapAuth ftpAuth switchAuth',
  364. 'label' => 'Host Address',
  365. 'value' => $GLOBALS['authBackendHost'],
  366. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  367. ),
  368. array(
  369. 'type' => 'input',
  370. 'name' => 'authBaseDN',
  371. 'class' => 'ldapAuth switchAuth',
  372. 'label' => 'Host Base DN',
  373. 'value' => $GLOBALS['authBaseDN'],
  374. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  375. ),
  376. array(
  377. 'type' => 'input',
  378. 'name' => 'embyURL',
  379. 'class' => 'embyAuth switchAuth',
  380. 'label' => 'Emby URL',
  381. 'value' => $GLOBALS['embyURL'],
  382. 'placeholder' => 'http(s)://hostname:port'
  383. ),
  384. array(
  385. 'type' => 'password-alt',
  386. 'name' => 'embyToken',
  387. 'class' => 'embyAuth switchAuth',
  388. 'label' => 'Emby Token',
  389. 'value' => $GLOBALS['embyToken'],
  390. 'placeholder' => ''
  391. )
  392. /*array(
  393. 'type' => 'button',
  394. 'label' => 'Send Test',
  395. 'class' => 'phpmSendTestEmail',
  396. 'icon' => 'fa fa-paper-plane',
  397. 'text' => 'Send'
  398. )*/
  399. ),
  400. 'Misc' => array(
  401. array(
  402. 'type' => 'password-alt',
  403. 'name' => 'registrationPassword',
  404. 'label' => 'Registration Password',
  405. 'value' => $GLOBALS['registrationPassword'],
  406. ),
  407. array(
  408. 'type' => 'switch',
  409. 'name' => 'hideRegistration',
  410. 'label' => 'Hide Registration',
  411. 'value' => $GLOBALS['hideRegistration']
  412. )
  413. )
  414. );
  415. }
  416. function getSSO()
  417. {
  418. return array(
  419. 'Plex' => array(
  420. array(
  421. 'type' => 'password-alt',
  422. 'name' => 'plexToken',
  423. 'label' => 'Plex Token',
  424. 'value' => $GLOBALS['plexToken'],
  425. 'placeholder' => 'Use Get Token Button'
  426. ),
  427. array(
  428. 'type' => 'button',
  429. 'label' => 'Get Plex Token',
  430. 'class' => 'popup-with-form getPlexTokenSSO',
  431. 'icon' => 'fa fa-ticket',
  432. 'text' => 'Retrieve',
  433. 'href' => '#sso-plex-token-form',
  434. 'attr' => 'data-effect="mfp-3d-unfold"'
  435. ),
  436. array(
  437. 'type' => 'password-alt',
  438. 'name' => 'plexID',
  439. 'label' => 'Plex Machine',
  440. 'value' => $GLOBALS['plexID'],
  441. 'placeholder' => 'Use Get Plex Machine Button'
  442. ),
  443. array(
  444. 'type' => 'button',
  445. 'label' => 'Get Plex Machine',
  446. 'class' => 'popup-with-form getPlexMachineSSO',
  447. 'icon' => 'fa fa-id-badge',
  448. 'text' => 'Retrieve',
  449. 'href' => '#sso-plex-machine-form',
  450. 'attr' => 'data-effect="mfp-3d-unfold"'
  451. ),
  452. array(
  453. 'type' => 'input',
  454. 'name' => 'plexAdmin',
  455. 'label' => 'Admin Username',
  456. 'value' => $GLOBALS['plexAdmin'],
  457. 'placeholder' => 'Admin username for Plex'
  458. ),
  459. array(
  460. 'type' => 'blank',
  461. 'label' => ''
  462. ),
  463. array(
  464. 'type' => 'html',
  465. 'label' => 'Plex Note',
  466. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  467. ),
  468. array(
  469. 'type' => 'switch',
  470. 'name' => 'ssoPlex',
  471. 'label' => 'Enable',
  472. 'value' => $GLOBALS['ssoPlex']
  473. )
  474. ),
  475. 'Ombi' => array(
  476. array(
  477. 'type' => 'input',
  478. 'name' => 'ombiURL',
  479. 'label' => 'Ombi URL',
  480. 'value' => $GLOBALS['ombiURL'],
  481. 'placeholder' => 'http(s)://hostname:port'
  482. ),
  483. array(
  484. 'type' => 'switch',
  485. 'name' => 'ssoOmbi',
  486. 'label' => 'Enable',
  487. 'value' => $GLOBALS['ssoOmbi']
  488. )
  489. ),
  490. 'Tautulli' => array(
  491. array(
  492. 'type' => 'input',
  493. 'name' => 'tautulliURL',
  494. 'label' => 'Tautulli URL',
  495. 'value' => $GLOBALS['tautulliURL'],
  496. 'placeholder' => 'http(s)://hostname:port'
  497. ),
  498. array(
  499. 'type' => 'switch',
  500. 'name' => 'ssoTautulli',
  501. 'label' => 'Enable',
  502. 'value' => $GLOBALS['ssoTautulli']
  503. )
  504. )
  505. );
  506. }
  507. function loadAppearance()
  508. {
  509. $appearance = array();
  510. $appearance['logo'] = $GLOBALS['logo'];
  511. $appearance['title'] = $GLOBALS['title'];
  512. $appearance['useLogo'] = $GLOBALS['useLogo'];
  513. $appearance['headerColor'] = $GLOBALS['headerColor'];
  514. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  515. $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
  516. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  517. $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
  518. $appearance['accentColor'] = $GLOBALS['accentColor'];
  519. $appearance['accentTextColor'] = $GLOBALS['accentTextColor'];
  520. $appearance['buttonColor'] = $GLOBALS['buttonColor'];
  521. $appearance['buttonTextColor'] = $GLOBALS['buttonTextColor'];
  522. $appearance['buttonTextHoverColor'] = $GLOBALS['buttonTextHoverColor'];
  523. $appearance['buttonHoverColor'] = $GLOBALS['buttonHoverColor'];
  524. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  525. $appearance['customCss'] = $GLOBALS['customCss'];
  526. return $appearance;
  527. }
  528. function getCustomizeAppearance()
  529. {
  530. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  531. return array(
  532. 'Top Bar' => array(
  533. array(
  534. 'type' => 'input',
  535. 'name' => 'logo',
  536. 'label' => 'Logo',
  537. 'value' => $GLOBALS['logo']
  538. ),
  539. array(
  540. 'type' => 'input',
  541. 'name' => 'title',
  542. 'label' => 'Title',
  543. 'value' => $GLOBALS['title']
  544. ),
  545. array(
  546. 'type' => 'switch',
  547. 'name' => 'useLogo',
  548. 'label' => 'Use Logo instead of Title',
  549. 'value' => $GLOBALS['useLogo']
  550. )
  551. ),
  552. 'Login Page' => array(
  553. array(
  554. 'type' => 'input',
  555. 'name' => 'loginWallpaper',
  556. 'label' => 'Login Wallpaper',
  557. 'value' => $GLOBALS['loginWallpaper']
  558. )
  559. ),
  560. 'Options' => array(
  561. array(
  562. 'type' => 'switch',
  563. 'name' => 'alternateHomepageHeaders',
  564. 'label' => 'Alternate Homepage Titles',
  565. 'value' => $GLOBALS['alternateHomepageHeaders']
  566. )
  567. ),
  568. 'custom' => '
  569. <div class="row">
  570. <div class="col-lg-12">
  571. <div class="panel panel-info">
  572. <div class="panel-heading">
  573. <span lang="en">Notice</span>
  574. </div>
  575. <div class="panel-wrapper collapse in" aria-expanded="true">
  576. <div class="panel-body">
  577. <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
  578. </div>
  579. </div>
  580. </div>
  581. </div>
  582. </div>
  583. ',
  584. 'Colors & Themes' => array(
  585. array(
  586. 'type' => 'input',
  587. 'name' => 'headerColor',
  588. 'label' => 'Nav Bar Color',
  589. 'value' => $GLOBALS['headerColor'],
  590. 'class' => 'pick-a-color',
  591. 'attr' => 'data-original="' . $GLOBALS['headerColor'] . '"'
  592. ),
  593. array(
  594. 'type' => 'input',
  595. 'name' => 'headerTextColor',
  596. 'label' => 'Nav Bar Text Color',
  597. 'value' => $GLOBALS['headerTextColor'],
  598. 'class' => 'pick-a-color',
  599. 'attr' => 'data-original="' . $GLOBALS['headerTextColor'] . '"'
  600. ),
  601. array(
  602. 'type' => 'input',
  603. 'name' => 'sidebarColor',
  604. 'label' => 'Side Bar Color',
  605. 'value' => $GLOBALS['sidebarColor'],
  606. 'class' => 'pick-a-color',
  607. 'attr' => 'data-original="' . $GLOBALS['sidebarColor'] . '"'
  608. ),
  609. array(
  610. 'type' => 'input',
  611. 'name' => 'sidebarTextColor',
  612. 'label' => 'Side Bar Text Color',
  613. 'value' => $GLOBALS['sidebarTextColor'],
  614. 'class' => 'pick-a-color',
  615. 'attr' => 'data-original="' . $GLOBALS['sidebarTextColor'] . '"'
  616. ),
  617. array(
  618. 'type' => 'input',
  619. 'name' => 'accentColor',
  620. 'label' => 'Accent Color',
  621. 'value' => $GLOBALS['accentColor'],
  622. 'class' => 'pick-a-color',
  623. 'attr' => 'data-original="' . $GLOBALS['accentColor'] . '"'
  624. ),
  625. array(
  626. 'type' => 'input',
  627. 'name' => 'accentTextColor',
  628. 'label' => 'Accent Text Color',
  629. 'value' => $GLOBALS['accentTextColor'],
  630. 'class' => 'pick-a-color',
  631. 'attr' => 'data-original="' . $GLOBALS['accentTextColor'] . '"'
  632. ),
  633. array(
  634. 'type' => 'input',
  635. 'name' => 'buttonColor',
  636. 'label' => 'Button Color',
  637. 'value' => $GLOBALS['buttonColor'],
  638. 'class' => 'pick-a-color',
  639. 'attr' => 'data-original="' . $GLOBALS['buttonColor'] . '"'
  640. ),
  641. array(
  642. 'type' => 'input',
  643. 'name' => 'buttonTextColor',
  644. 'label' => 'Button Text Color',
  645. 'value' => $GLOBALS['buttonTextColor'],
  646. 'class' => 'pick-a-color',
  647. 'attr' => 'data-original="' . $GLOBALS['buttonTextColor'] . '"'
  648. ),/*
  649. array(
  650. 'type' => 'input',
  651. 'name' => 'buttonHoverColor',
  652. 'label' => 'Button Hover Color',
  653. 'value' => $GLOBALS['buttonHoverColor'],
  654. 'class' => 'pick-a-color',
  655. 'disabled' => true
  656. ),
  657. array(
  658. 'type' => 'input',
  659. 'name' => 'buttonTextHoverColor',
  660. 'label' => 'Button Hover Text Color',
  661. 'value' => $GLOBALS['buttonTextHoverColor'],
  662. 'class' => 'pick-a-color',
  663. 'disabled' => true
  664. ),*/
  665. array(
  666. 'type' => 'select',
  667. 'name' => 'theme',
  668. 'label' => 'Theme',
  669. 'class' => 'themeChanger',
  670. 'value' => $GLOBALS['theme'],
  671. 'options' => getThemes()
  672. ),
  673. array(
  674. 'type' => 'select',
  675. 'name' => 'style',
  676. 'label' => 'Style',
  677. 'class' => 'styleChanger',
  678. 'value' => $GLOBALS['style'],
  679. 'options' => array(
  680. array(
  681. 'name' => 'Light',
  682. 'value' => 'light'
  683. ),
  684. array(
  685. 'name' => 'Dark',
  686. 'value' => 'dark'
  687. ),
  688. array(
  689. 'name' => 'Horizontal',
  690. 'value' => 'horizontal'
  691. )
  692. )
  693. ),
  694. array(
  695. 'type' => 'textbox',
  696. 'name' => 'customCss',
  697. 'class' => 'hidden cssTextarea',
  698. 'label' => '',
  699. 'value' => $GLOBALS['customCss'],
  700. 'placeholder' => 'No <style> tags needed',
  701. 'attr' => 'rows="10"',
  702. ),
  703. array(
  704. 'type' => 'html',
  705. 'override' => 12,
  706. 'label' => 'Custom CSS [Can replace colors from above]',
  707. 'html' => '<button type="button" class="hidden saveCss btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customCSSEditor" style="height:300px">' . $GLOBALS['customCss'] . '</div>'
  708. ),
  709. )
  710. );
  711. }
  712. }
  713. function editAppearance($array)
  714. {
  715. switch ($array['data']['value']) {
  716. case 'true':
  717. $array['data']['value'] = (bool)true;
  718. break;
  719. case 'false':
  720. $array['data']['value'] = (bool)false;
  721. break;
  722. default:
  723. $array['data']['value'] = $array['data']['value'];
  724. }
  725. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  726. switch ($array['data']['action']) {
  727. case 'editCustomizeAppearance':
  728. $newItem = array(
  729. $array['data']['name'] => $array['data']['value']
  730. );
  731. return (updateConfig($newItem)) ? true : false;
  732. break;
  733. default:
  734. # code...
  735. break;
  736. }
  737. }
  738. function updateConfigMultiple($array)
  739. {
  740. return (updateConfig($array['data']['payload'])) ? true : false;
  741. }
  742. function updateConfigMultipleForm($array)
  743. {
  744. $newItem = array();
  745. foreach ($array['data']['payload'] as $k => $v) {
  746. switch ($v['value']) {
  747. case 'true':
  748. $v['value'] = (bool)true;
  749. break;
  750. case 'false':
  751. $v['value'] = (bool)false;
  752. break;
  753. default:
  754. $v['value'] = $v['value'];
  755. }
  756. // Hash
  757. if ($v['type'] == 'password') {
  758. if (strpos($v['value'], '==') !== false) {
  759. $v['value'] = $v['value'];
  760. } else {
  761. $v['value'] = encrypt($v['value']);
  762. }
  763. }
  764. $newItem[$v['name']] = $v['value'];
  765. }
  766. //return $newItem;
  767. return (updateConfig($newItem)) ? true : false;
  768. }
  769. function updateConfigItem($array)
  770. {
  771. switch ($array['data']['value']) {
  772. case 'true':
  773. $array['data']['value'] = (bool)true;
  774. break;
  775. case 'false':
  776. $array['data']['value'] = (bool)false;
  777. break;
  778. default:
  779. $array['data']['value'] = $array['data']['value'];
  780. }
  781. // Hash
  782. if ($array['data']['type'] == 'password') {
  783. $array['data']['value'] = encrypt($array['data']['value']);
  784. }
  785. $newItem = array(
  786. $array['data']['name'] => $array['data']['value']
  787. );
  788. return (updateConfig($newItem)) ? true : false;
  789. }
  790. function getPlugins()
  791. {
  792. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  793. $pluginList = [];
  794. foreach ($GLOBALS['plugins'] as $plugin) {
  795. foreach ($plugin as $key => $value) {
  796. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  797. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
  798. $pluginList[$key] = $plugin[$key];
  799. }
  800. }
  801. }
  802. return $pluginList;
  803. }
  804. return false;
  805. }
  806. function editPlugins($array)
  807. {
  808. switch ($array['data']['action']) {
  809. case 'enable':
  810. $newItem = array(
  811. $array['data']['configName'] => true
  812. );
  813. writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  814. return (updateConfig($newItem)) ? true : false;
  815. break;
  816. case 'disable':
  817. $newItem = array(
  818. $array['data']['configName'] => false
  819. );
  820. writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  821. return (updateConfig($newItem)) ? true : false;
  822. break;
  823. default:
  824. # code...
  825. break;
  826. }
  827. }
  828. function auth()
  829. {
  830. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  831. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  832. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  833. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  834. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  835. $currentIP = userIP();
  836. if (isset($GLOBALS['organizrUser'])) {
  837. $currentUser = $GLOBALS['organizrUser']['username'];
  838. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  839. } else {
  840. $currentUser = 'Guest';
  841. $currentGroup = getUserLevel();
  842. }
  843. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  844. if ($whitelist) {
  845. if (in_array($currentIP, arrayIP($whitelist))) {
  846. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  847. }
  848. }
  849. if ($blacklist) {
  850. if (in_array($currentIP, arrayIP($blacklist))) {
  851. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  852. }
  853. }
  854. if ($group !== null) {
  855. if (qualifyRequest($group)) {
  856. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  857. } else {
  858. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  859. }
  860. } else {
  861. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  862. }
  863. }
  864. function logoOrText()
  865. {
  866. if ($GLOBALS['useLogo'] == false) {
  867. return '<h1>' . $GLOBALS['title'] . '</h1>';
  868. } else {
  869. return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
  870. }
  871. }
  872. function showLogin()
  873. {
  874. if ($GLOBALS['hideRegistration'] == false) {
  875. return '<p><span lang="en">Don\'t have an account?</span><a href="#" class="text-primary m-l-5 to-register"><b lang="en">Sign Up</b></a></p>';
  876. }
  877. }
  878. function getImages()
  879. {
  880. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  881. $path = 'plugins/images/tabs/';
  882. $images = scandir($dirname);
  883. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  884. $allIcons = array();
  885. foreach ($images as $image) {
  886. if (!in_array($image, $ignore)) {
  887. $allIcons[] = $path . $image;
  888. }
  889. }
  890. return $allIcons;
  891. }
  892. function editImages()
  893. {
  894. $array = array();
  895. $postCheck = array_filter($_POST);
  896. $filesCheck = array_filter($_FILES);
  897. if (!empty($postCheck)) {
  898. if ($_POST['data']['action'] == 'deleteImage') {
  899. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
  900. writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
  901. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
  902. }
  903. }
  904. }
  905. if (!empty($filesCheck)) {
  906. ini_set('upload_max_filesize', '10M');
  907. ini_set('post_max_size', '10M');
  908. $tempFile = $_FILES['file']['tmp_name'];
  909. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  910. $targetFile = $targetPath . $_FILES['file']['name'];
  911. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  912. }
  913. return false;
  914. }
  915. function getThemes()
  916. {
  917. $themes = array();
  918. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  919. $themes[] = array(
  920. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  921. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  922. );
  923. }
  924. return $themes;
  925. }
  926. function getBranches()
  927. {
  928. return array(
  929. array(
  930. 'name' => 'Develop',
  931. 'value' => 'v2-develop'
  932. ),
  933. array(
  934. 'name' => 'Master',
  935. 'value' => 'v2-master'
  936. )
  937. );
  938. }
  939. function getAuthTypes()
  940. {
  941. return array(
  942. array(
  943. 'name' => 'Organizr DB',
  944. 'value' => 'internal'
  945. ),
  946. array(
  947. 'name' => 'Organizr DB + Backend',
  948. 'value' => 'both'
  949. ),
  950. array(
  951. 'name' => 'Backend Only',
  952. 'value' => 'external'
  953. )
  954. );
  955. }
  956. function getAuthBackends()
  957. {
  958. $backendOptions = array();
  959. $backendOptions[] = array(
  960. 'name' => 'Choose Backend',
  961. 'value' => false,
  962. 'disabled' => true
  963. );
  964. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  965. return strpos($v, 'plugin_auth_') === 0;
  966. }) as $value) {
  967. $name = str_replace('plugin_auth_', '', $value);
  968. if (strpos($name, 'disabled') === false) {
  969. $backendOptions[] = array(
  970. 'name' => ucwords(str_replace('_', ' ', $name)),
  971. 'value' => $name
  972. );
  973. } else {
  974. $backendOptions[] = array(
  975. 'name' => $value(),
  976. 'value' => 'none',
  977. 'disabled' => true,
  978. );
  979. }
  980. }
  981. ksort($backendOptions);
  982. return $backendOptions;
  983. }
  984. function wizardPath($array)
  985. {
  986. $path = $array['data']['path'];
  987. if (file_exists($path)) {
  988. if (is_writable($path)) {
  989. return true;
  990. }
  991. } else {
  992. if (is_writable(dirname($path, 1))) {
  993. if (mkdir($path, 0760, true)) {
  994. return true;
  995. }
  996. }
  997. }
  998. return 'permissions';
  999. }
  1000. function groupSelect()
  1001. {
  1002. $groups = allGroups();
  1003. $select = array();
  1004. foreach ($groups as $key => $value) {
  1005. $select[] = array(
  1006. 'name' => $value['group'],
  1007. 'value' => $value['group_id']
  1008. );
  1009. }
  1010. return $select;
  1011. }
  1012. function getImage()
  1013. {
  1014. $refresh = false;
  1015. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1016. if (!file_exists($cacheDirectory)) {
  1017. mkdir($cacheDirectory, 0777, true);
  1018. }
  1019. @$image_url = $_GET['img'];
  1020. @$key = $_GET['key'];
  1021. @$image_height = $_GET['height'];
  1022. @$image_width = $_GET['width'];
  1023. @$source = $_GET['source'];
  1024. @$itemType = $_GET['type'];
  1025. if (strpos($key, '$') !== false) {
  1026. $key = explode('$', $key)[0];
  1027. $refresh = true;
  1028. }
  1029. switch ($source) {
  1030. case 'plex':
  1031. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  1032. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  1033. break;
  1034. case 'emby':
  1035. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  1036. $imgParams = array();
  1037. if (isset($_GET['height'])) {
  1038. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  1039. }
  1040. if (isset($_GET['width'])) {
  1041. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  1042. }
  1043. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  1044. break;
  1045. default:
  1046. # code...
  1047. break;
  1048. }
  1049. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  1050. $cachefile = $cacheDirectory . $key . '.jpg';
  1051. $cachetime = 604800;
  1052. // Serve from the cache if it is younger than $cachetime
  1053. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1054. header("Content-type: image/jpeg");
  1055. //@readfile($cachefile);
  1056. echo @curl('get', $cachefile)['content'];
  1057. exit;
  1058. }
  1059. ob_start(); // Start the output buffer
  1060. header('Content-type: image/jpeg');
  1061. //@readfile($image_src);
  1062. echo @curl('get', $image_src)['content'];
  1063. // Cache the output to a file
  1064. $fp = fopen($cachefile, 'wb');
  1065. fwrite($fp, ob_get_contents());
  1066. fclose($fp);
  1067. ob_end_flush(); // Send the output to the browser
  1068. die();
  1069. } else {
  1070. die("Invalid Request");
  1071. }
  1072. }
  1073. function cacheImage($url, $name)
  1074. {
  1075. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1076. if (!file_exists($cacheDirectory)) {
  1077. mkdir($cacheDirectory, 0777, true);
  1078. }
  1079. $cachefile = $cacheDirectory . $name . '.jpg';
  1080. copy($url, $cachefile);
  1081. }
  1082. function downloader($array)
  1083. {
  1084. switch ($array['data']['source']) {
  1085. case 'sabnzbd':
  1086. switch ($array['data']['action']) {
  1087. case 'resume':
  1088. case 'pause':
  1089. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1090. break;
  1091. default:
  1092. # code...
  1093. break;
  1094. }
  1095. break;
  1096. case 'nzbget':
  1097. break;
  1098. default:
  1099. # code...
  1100. break;
  1101. }
  1102. }
  1103. function sabnzbdAction($action = null, $target = null)
  1104. {
  1105. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1106. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1107. switch ($action) {
  1108. case 'pause':
  1109. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
  1110. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1111. break;
  1112. case 'resume':
  1113. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
  1114. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1115. break;
  1116. default:
  1117. # code...
  1118. break;
  1119. }
  1120. try {
  1121. $options = (localURL($url)) ? array('verify' => false) : array();
  1122. $response = Requests::get($url, array(), $options);
  1123. if ($response->success) {
  1124. $api['content'] = json_decode($response->body, true);
  1125. }
  1126. } catch (Requests_Exception $e) {
  1127. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1128. };
  1129. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1130. return $api;
  1131. }
  1132. }
  1133. // Deluge API isn't working ATM - will get with dev.
  1134. function delugeAction($action = null, $target = null)
  1135. {
  1136. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  1137. $url = qualifyURL($GLOBALS['delugeURL']);
  1138. try {
  1139. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1140. switch ($action) {
  1141. case 'pause':
  1142. $torrents = $deluge->pauseTorrent($target);
  1143. break;
  1144. case 'pauseAll':
  1145. $torrents = $deluge->pauseAllTorrents();
  1146. break;
  1147. case 'resume':
  1148. $torrents = $deluge->resumeTorrent($target);
  1149. break;
  1150. case 'resumeAll':
  1151. $torrents = $deluge->resumeAllTorrents();
  1152. break;
  1153. default:
  1154. # code...
  1155. break;
  1156. }
  1157. $api['content'] = $torrents;
  1158. } catch (Excecption $e) {
  1159. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1160. }
  1161. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1162. return $api;
  1163. }
  1164. return false;
  1165. }
  1166. function getOrgUsers()
  1167. {
  1168. $result = allUsers();
  1169. if (is_array($result) || is_object($result)) {
  1170. foreach ($result['users'] as $k => $v) {
  1171. $return[$v['username']] = $v['email'];
  1172. }
  1173. return $return;
  1174. }
  1175. }
  1176. function convertPlexName($user, $type)
  1177. {
  1178. $array = libraryList('plex');
  1179. switch ($type) {
  1180. case "username":
  1181. case "u":
  1182. $plexUser = array_search($user, $array['users']);
  1183. break;
  1184. case "id":
  1185. if (array_key_exists(strtolower($user), $array['users'])) {
  1186. $plexUser = $array['users'][strtolower($user)];
  1187. }
  1188. break;
  1189. default:
  1190. $plexUser = false;
  1191. }
  1192. return (!empty($plexUser) ? $plexUser : null);
  1193. }
  1194. function libraryList($type = null)
  1195. {
  1196. switch ($type) {
  1197. case 'plex':
  1198. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1199. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
  1200. try {
  1201. $headers = array(
  1202. "Accept" => "application/json",
  1203. "X-Plex-Token" => $GLOBALS['plexToken']
  1204. );
  1205. $response = Requests::get($url, $headers, array());
  1206. libxml_use_internal_errors(true);
  1207. if ($response->success) {
  1208. $libraryList = array();
  1209. $plex = simplexml_load_string($response->body);
  1210. foreach ($plex->SharedServer->Section as $child) {
  1211. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1212. }
  1213. foreach ($plex->SharedServer as $child) {
  1214. if (!empty($child['username'])) {
  1215. $username = (string)strtolower($child['username']);
  1216. $email = (string)strtolower($child['email']);
  1217. $libraryList['users'][$username] = (string)$child['id'];
  1218. $libraryList['emails'][$email] = (string)$child['id'];
  1219. $libraryList['both'][$username] = $email;
  1220. }
  1221. }
  1222. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1223. return $libraryList;
  1224. }
  1225. } catch (Requests_Exception $e) {
  1226. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1227. };
  1228. }
  1229. break;
  1230. default:
  1231. # code...
  1232. break;
  1233. }
  1234. return false;
  1235. }
  1236. function plexJoinAPI($array)
  1237. {
  1238. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1239. }
  1240. function plexJoin($username, $email, $password)
  1241. {
  1242. try {
  1243. $url = 'https://plex.tv/users.json';
  1244. $headers = array(
  1245. 'Accept' => 'application/json',
  1246. 'Content-Type' => 'application/x-www-form-urlencoded',
  1247. 'X-Plex-Product' => 'Organizr',
  1248. 'X-Plex-Version' => '2.0',
  1249. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1250. );
  1251. $data = array(
  1252. 'user[email]' => $email,
  1253. 'user[username]' => $username,
  1254. 'user[password]' => $password,
  1255. );
  1256. $response = Requests::post($url, $headers, $data, array());
  1257. $json = json_decode($response->body, true);
  1258. $errors = (!empty($json['errors']) ? true : false);
  1259. $success = (!empty($json['user']) ? true : false);
  1260. //Use This for later
  1261. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1262. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1263. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1264. $errorMessage = "";
  1265. if ($errors) {
  1266. if ($usernameError) {
  1267. $errorMessage .= "[Username Error: " . $usernameError . "]";
  1268. }
  1269. if ($emailError) {
  1270. $errorMessage .= "[Email Error: " . $emailError . "]";
  1271. }
  1272. if ($passwordError) {
  1273. $errorMessage .= "[Password Error: " . $passwordError . "]";
  1274. }
  1275. }
  1276. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1277. } catch (Requests_Exception $e) {
  1278. writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1279. };
  1280. return false;
  1281. }
  1282. function checkFrame($array, $url)
  1283. {
  1284. if (array_key_exists("x-frame-options", $array)) {
  1285. if ($array['x-frame-options'] == "deny") {
  1286. return false;
  1287. } elseif ($array['x-frame-options'] == "sameorgin") {
  1288. $digest = parse_url($url);
  1289. $host = (isset($digest['host']) ? $digest['host'] : '');
  1290. if (getServer() == $host) {
  1291. return true;
  1292. } else {
  1293. return false;
  1294. }
  1295. }
  1296. } else {
  1297. if (!$array) {
  1298. return false;
  1299. }
  1300. return true;
  1301. }
  1302. }
  1303. function frameTest($url)
  1304. {
  1305. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  1306. $url = qualifyURL($url);
  1307. if (checkFrame($array, $url)) {
  1308. return true;
  1309. } else {
  1310. return false;
  1311. }
  1312. }