organizr-functions.php 44 KB

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