organizr-functions.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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. 'Colors & Themes' => array(
  558. array(
  559. 'type' => 'input',
  560. 'name' => 'headerColor',
  561. 'label' => 'Nav Bar Color',
  562. 'value' => $GLOBALS['headerColor'],
  563. 'class' => 'pick-a-color',
  564. 'attr' => 'data-original="'.$GLOBALS['headerColor'].'"'
  565. ),
  566. array(
  567. 'type' => 'input',
  568. 'name' => 'headerTextColor',
  569. 'label' => 'Nav Bar Text Color',
  570. 'value' => $GLOBALS['headerTextColor'],
  571. 'class' => 'pick-a-color',
  572. 'attr' => 'data-original="'.$GLOBALS['headerTextColor'].'"'
  573. ),
  574. array(
  575. 'type' => 'input',
  576. 'name' => 'sidebarColor',
  577. 'label' => 'Side Bar Color',
  578. 'value' => $GLOBALS['sidebarColor'],
  579. 'class' => 'pick-a-color',
  580. 'attr' => 'data-original="'.$GLOBALS['sidebarColor'].'"'
  581. ),
  582. array(
  583. 'type' => 'input',
  584. 'name' => 'sidebarTextColor',
  585. 'label' => 'Side Bar Text Color',
  586. 'value' => $GLOBALS['sidebarTextColor'],
  587. 'class' => 'pick-a-color',
  588. 'attr' => 'data-original="'.$GLOBALS['sidebarTextColor'].'"'
  589. ),
  590. array(
  591. 'type' => 'input',
  592. 'name' => 'accentColor',
  593. 'label' => 'Accent Color',
  594. 'value' => $GLOBALS['accentColor'],
  595. 'class' => 'pick-a-color',
  596. 'attr' => 'data-original="'.$GLOBALS['accentColor'].'"'
  597. ),
  598. array(
  599. 'type' => 'input',
  600. 'name' => 'accentTextColor',
  601. 'label' => 'Accent Text Color',
  602. 'value' => $GLOBALS['accentTextColor'],
  603. 'class' => 'pick-a-color',
  604. 'attr' => 'data-original="'.$GLOBALS['accentTextColor'].'"'
  605. ),
  606. array(
  607. 'type' => 'input',
  608. 'name' => 'buttonColor',
  609. 'label' => 'Button Color',
  610. 'value' => $GLOBALS['buttonColor'],
  611. 'class' => 'pick-a-color',
  612. 'attr' => 'data-original="'.$GLOBALS['buttonColor'].'"'
  613. ),
  614. array(
  615. 'type' => 'input',
  616. 'name' => 'buttonTextColor',
  617. 'label' => 'Button Text Color',
  618. 'value' => $GLOBALS['buttonTextColor'],
  619. 'class' => 'pick-a-color',
  620. 'attr' => 'data-original="'.$GLOBALS['buttonTextColor'].'"'
  621. ),/*
  622. array(
  623. 'type' => 'input',
  624. 'name' => 'buttonHoverColor',
  625. 'label' => 'Button Hover Color',
  626. 'value' => $GLOBALS['buttonHoverColor'],
  627. 'class' => 'pick-a-color',
  628. 'disabled' => true
  629. ),
  630. array(
  631. 'type' => 'input',
  632. 'name' => 'buttonTextHoverColor',
  633. 'label' => 'Button Hover Text Color',
  634. 'value' => $GLOBALS['buttonTextHoverColor'],
  635. 'class' => 'pick-a-color',
  636. 'disabled' => true
  637. ),*/
  638. array(
  639. 'type' => 'select',
  640. 'name' => 'theme',
  641. 'label' => 'Theme',
  642. 'class' => 'themeChanger',
  643. 'value' => $GLOBALS['theme'],
  644. 'options' => getThemes()
  645. ),
  646. array(
  647. 'type' => 'select',
  648. 'name' => 'style',
  649. 'label' => 'Style',
  650. 'class' => 'styleChanger',
  651. 'value' => $GLOBALS['style'],
  652. 'options' => array(
  653. array(
  654. 'name' => 'Light',
  655. 'value' => 'light'
  656. ),
  657. array(
  658. 'name' => 'Dark',
  659. 'value' => 'dark'
  660. ),
  661. array(
  662. 'name' => 'Horizontal',
  663. 'value' => 'horizontal'
  664. )
  665. )
  666. ),
  667. array(
  668. 'type' => 'textbox',
  669. 'name' => 'customCss',
  670. 'class' => 'hidden cssTextarea',
  671. 'label' => '',
  672. 'value' => $GLOBALS['customCss'],
  673. 'placeholder' => 'No <style> tags needed',
  674. 'attr' => 'rows="10"',
  675. ),
  676. array(
  677. 'type' => 'html',
  678. 'override' => 12,
  679. 'label' => 'Custom CSS [Can replace colors from above]',
  680. '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>'
  681. ),
  682. )
  683. );
  684. }
  685. }
  686. function editAppearance($array)
  687. {
  688. switch ($array['data']['value']) {
  689. case 'true':
  690. $array['data']['value'] = (bool) true;
  691. break;
  692. case 'false':
  693. $array['data']['value'] = (bool) false;
  694. break;
  695. default:
  696. $array['data']['value'] = $array['data']['value'];
  697. }
  698. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  699. switch ($array['data']['action']) {
  700. case 'editCustomizeAppearance':
  701. $newItem = array(
  702. $array['data']['name'] => $array['data']['value']
  703. );
  704. return (updateConfig($newItem)) ? true : false;
  705. break;
  706. default:
  707. # code...
  708. break;
  709. }
  710. }
  711. function updateConfigMultiple($array)
  712. {
  713. return (updateConfig($array['data']['payload'])) ? true : false;
  714. }
  715. function updateConfigItem($array)
  716. {
  717. switch ($array['data']['value']) {
  718. case 'true':
  719. $array['data']['value'] = (bool) true;
  720. break;
  721. case 'false':
  722. $array['data']['value'] = (bool) false;
  723. break;
  724. default:
  725. $array['data']['value'] = $array['data']['value'];
  726. }
  727. // Hash
  728. if ($array['data']['type'] == 'password') {
  729. $array['data']['value'] = encrypt($array['data']['value']);
  730. }
  731. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  732. $newItem = array(
  733. $array['data']['name'] => $array['data']['value']
  734. );
  735. return (updateConfig($newItem)) ? true : false;
  736. }
  737. function getPlugins()
  738. {
  739. if (file_exists(dirname(__DIR__, 1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')) {
  740. $pluginList = [];
  741. foreach ($GLOBALS['plugins'] as $plugin) {
  742. foreach ($plugin as $key => $value) {
  743. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  744. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'].'-enabled'];
  745. $pluginList[$key] = $plugin[$key];
  746. }
  747. }
  748. }
  749. return $pluginList;
  750. }
  751. return false;
  752. }
  753. function editPlugins($array)
  754. {
  755. switch ($array['data']['action']) {
  756. case 'enable':
  757. $newItem = array(
  758. $array['data']['configName'] => true
  759. );
  760. writeLog('success', 'Plugin Function - Enabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  761. return (updateConfig($newItem)) ? true : false;
  762. break;
  763. case 'disable':
  764. $newItem = array(
  765. $array['data']['configName'] => false
  766. );
  767. writeLog('success', 'Plugin Function - Disabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  768. return (updateConfig($newItem)) ? true : false;
  769. break;
  770. default:
  771. # code...
  772. break;
  773. }
  774. }
  775. function auth()
  776. {
  777. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  778. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  779. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  780. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  781. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  782. $currentIP = userIP();
  783. if (isset($GLOBALS['organizrUser'])) {
  784. $currentUser = $GLOBALS['organizrUser']['username'];
  785. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  786. } else {
  787. $currentUser = 'Guest';
  788. $currentGroup = getUserLevel();
  789. }
  790. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  791. if ($whitelist) {
  792. if (in_array($currentIP, arrayIP($whitelist))) {
  793. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  794. }
  795. }
  796. if ($blacklist) {
  797. if (in_array($currentIP, arrayIP($blacklist))) {
  798. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  799. }
  800. }
  801. if ($group !== null) {
  802. if (qualifyRequest($group)) {
  803. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  804. } else {
  805. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  806. }
  807. } else {
  808. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  809. }
  810. }
  811. function logoOrText()
  812. {
  813. if ($GLOBALS['useLogo'] == false) {
  814. return '<h1>'.$GLOBALS['title'].'</h1>';
  815. } else {
  816. return '<img style="max-width: 350px;" src="'.$GLOBALS['logo'].'" alt="Home" />';
  817. }
  818. }
  819. function getImages()
  820. {
  821. $dirname = dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  822. $path = 'plugins/images/tabs/';
  823. $images = scandir($dirname);
  824. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  825. $allIcons = array();
  826. foreach ($images as $image) {
  827. if (!in_array($image, $ignore)) {
  828. $allIcons[] = $path.$image;
  829. }
  830. }
  831. return $allIcons;
  832. }
  833. function editImages()
  834. {
  835. $array = array();
  836. $postCheck = array_filter($_POST);
  837. $filesCheck = array_filter($_FILES);
  838. if (!empty($postCheck)) {
  839. if ($_POST['data']['action'] == 'deleteImage') {
  840. if (file_exists(dirname(__DIR__, 2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) {
  841. writeLog('success', 'Image Manager Function - Deleted Image ['.$_POST['data']['imageName'].']', $GLOBALS['organizrUser']['username']);
  842. return (unlink(dirname(__DIR__, 2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) ? true : false;
  843. }
  844. }
  845. }
  846. if (!empty($filesCheck)) {
  847. ini_set('upload_max_filesize', '10M');
  848. ini_set('post_max_size', '10M');
  849. $tempFile = $_FILES['file']['tmp_name'];
  850. $targetPath = dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  851. $targetFile = $targetPath. $_FILES['file']['name'];
  852. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  853. }
  854. return false;
  855. }
  856. function getThemes()
  857. {
  858. $themes = array();
  859. foreach (glob(dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  860. $themes[] = array(
  861. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  862. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  863. );
  864. }
  865. return $themes;
  866. }
  867. function getBranches()
  868. {
  869. return array(
  870. array(
  871. 'name' => 'Develop',
  872. 'value' => 'v2-develop'
  873. ),
  874. array(
  875. 'name' => 'Master',
  876. 'value' => 'v2-master'
  877. )
  878. );
  879. }
  880. function getAuthTypes()
  881. {
  882. return array(
  883. array(
  884. 'name' => 'Organizr DB',
  885. 'value' => 'internal'
  886. ),
  887. array(
  888. 'name' => 'Organizr DB + Backend',
  889. 'value' => 'both'
  890. ),
  891. array(
  892. 'name' => 'Backend Only',
  893. 'value' => 'external'
  894. )
  895. );
  896. }
  897. function getAuthBackends()
  898. {
  899. $backendOptions = array();
  900. $backendOptions[] = array(
  901. 'name' => 'Choose Backend',
  902. 'value' => false,
  903. 'disabled' => true
  904. );
  905. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  906. return strpos($v, 'plugin_auth_') === 0;
  907. }) as $value) {
  908. $name = str_replace('plugin_auth_', '', $value);
  909. if (strpos($name, 'disabled') === false) {
  910. $backendOptions[] = array(
  911. 'name' => ucwords(str_replace('_', ' ', $name)),
  912. 'value' => $name
  913. );
  914. } else {
  915. $backendOptions[] = array(
  916. 'name' => $value(),
  917. 'value' => 'none',
  918. 'disabled' => true,
  919. );
  920. }
  921. }
  922. ksort($backendOptions);
  923. return $backendOptions;
  924. }
  925. function wizardPath($array)
  926. {
  927. $path = $array['data']['path'];
  928. if (file_exists($path)) {
  929. if (is_writable($path)) {
  930. return true;
  931. }
  932. } else {
  933. if (is_writable(dirname($path, 1))) {
  934. if (mkdir($path, 0760, true)) {
  935. return true;
  936. }
  937. }
  938. }
  939. return 'permissions';
  940. }
  941. function groupSelect()
  942. {
  943. $groups = allGroups();
  944. $select = array();
  945. foreach ($groups as $key => $value) {
  946. $select[] = array(
  947. 'name' => $value['group'],
  948. 'value' => $value['group_id']
  949. );
  950. }
  951. return $select;
  952. }
  953. function getImage()
  954. {
  955. $refresh = false;
  956. $cacheDirectory = dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  957. if (!file_exists($cacheDirectory)) {
  958. mkdir($cacheDirectory, 0777, true);
  959. }
  960. @$image_url = $_GET['img'];
  961. @$key = $_GET['key'];
  962. @$image_height = $_GET['height'];
  963. @$image_width = $_GET['width'];
  964. @$source = $_GET['source'];
  965. @$itemType = $_GET['type'];
  966. if (strpos($key, '$') !== false) {
  967. $key = explode('$', $key)[0];
  968. $refresh = true;
  969. }
  970. switch ($source) {
  971. case 'plex':
  972. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  973. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  974. break;
  975. case 'emby':
  976. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  977. $imgParams = array();
  978. if (isset($_GET['height'])) {
  979. $imgParams['height'] = 'maxHeight='.$_GET['height'];
  980. }
  981. if (isset($_GET['width'])) {
  982. $imgParams['width'] = 'maxWidth='.$_GET['width'];
  983. }
  984. $image_src = $embyAddress . '/Items/'.$image_url.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  985. break;
  986. default:
  987. # code...
  988. break;
  989. }
  990. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  991. $cachefile = $cacheDirectory.$key.'.jpg';
  992. $cachetime = 604800;
  993. // Serve from the cache if it is younger than $cachetime
  994. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  995. header("Content-type: image/jpeg");
  996. //@readfile($cachefile);
  997. echo @curl('get', $cachefile)['content'];
  998. exit;
  999. }
  1000. ob_start(); // Start the output buffer
  1001. header('Content-type: image/jpeg');
  1002. //@readfile($image_src);
  1003. echo @curl('get', $image_src)['content'];
  1004. // Cache the output to a file
  1005. $fp = fopen($cachefile, 'wb');
  1006. fwrite($fp, ob_get_contents());
  1007. fclose($fp);
  1008. ob_end_flush(); // Send the output to the browser
  1009. die();
  1010. } else {
  1011. die("Invalid Request");
  1012. }
  1013. }
  1014. function cacheImage($url, $name)
  1015. {
  1016. $cacheDirectory = dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  1017. if (!file_exists($cacheDirectory)) {
  1018. mkdir($cacheDirectory, 0777, true);
  1019. }
  1020. $cachefile = $cacheDirectory.$name.'.jpg';
  1021. copy($url, $cachefile);
  1022. }
  1023. function downloader($array)
  1024. {
  1025. switch ($array['data']['source']) {
  1026. case 'sabnzbd':
  1027. switch ($array['data']['action']) {
  1028. case 'resume':
  1029. case 'pause':
  1030. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1031. break;
  1032. default:
  1033. # code...
  1034. break;
  1035. }
  1036. break;
  1037. case 'nzbget':
  1038. break;
  1039. default:
  1040. # code...
  1041. break;
  1042. }
  1043. }
  1044. function sabnzbdAction($action=null, $target=null)
  1045. {
  1046. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1047. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1048. switch ($action) {
  1049. case 'pause':
  1050. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value='.$target.'&' : 'mode=pause';
  1051. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  1052. break;
  1053. case 'resume':
  1054. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value='.$target.'&' : 'mode=resume';
  1055. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  1056. break;
  1057. default:
  1058. # code...
  1059. break;
  1060. }
  1061. try {
  1062. $options = (localURL($url)) ? array('verify' => false ) : array();
  1063. $response = Requests::get($url, array(), $options);
  1064. if ($response->success) {
  1065. $api['content'] = json_decode($response->body, true);
  1066. }
  1067. } catch (Requests_Exception $e) {
  1068. writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  1069. };
  1070. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1071. return $api;
  1072. }
  1073. }
  1074. function getOrgUsers()
  1075. {
  1076. $result = allUsers();
  1077. if (is_array($result) || is_object($result)) {
  1078. foreach ($result['users'] as $k => $v) {
  1079. $return[$v['username']] = $v['email'];
  1080. }
  1081. return $return;
  1082. }
  1083. }
  1084. function convertPlexName($user, $type)
  1085. {
  1086. $array = libraryList('plex');
  1087. switch ($type) {
  1088. case "username":
  1089. case "u":
  1090. $plexUser = array_search($user, $array['users']);
  1091. break;
  1092. case "id":
  1093. if (array_key_exists(strtolower($user), $array['users'])) {
  1094. $plexUser = $array['users'][strtolower($user)];
  1095. }
  1096. break;
  1097. default:
  1098. $plexUser = false;
  1099. }
  1100. return (!empty($plexUser) ? $plexUser : null);
  1101. }
  1102. function libraryList($type=null)
  1103. {
  1104. switch ($type) {
  1105. case 'plex':
  1106. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1107. $url = 'https://plex.tv/api/servers/'.$GLOBALS['plexID'].'/shared_servers';
  1108. try {
  1109. $headers = array(
  1110. "Accept" => "application/json",
  1111. "X-Plex-Token" => $GLOBALS['plexToken']
  1112. );
  1113. $response = Requests::get($url, $headers, array());
  1114. libxml_use_internal_errors(true);
  1115. if ($response->success) {
  1116. $libraryList = array();
  1117. $plex = simplexml_load_string($response->body);
  1118. foreach ($plex->SharedServer->Section as $child) {
  1119. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1120. }
  1121. foreach ($plex->SharedServer as $child) {
  1122. if (!empty($child['username'])) {
  1123. $username = (string)strtolower($child['username']);
  1124. $email = (string)strtolower($child['email']);
  1125. $libraryList['users'][$username] = (string)$child['id'];
  1126. $libraryList['emails'][$email] = (string)$child['id'];
  1127. $libraryList['both'][$username] = $email;
  1128. }
  1129. }
  1130. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1131. return $libraryList;
  1132. }
  1133. } catch (Requests_Exception $e) {
  1134. writeLog('error', 'Plex Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  1135. };
  1136. }
  1137. break;
  1138. default:
  1139. # code...
  1140. break;
  1141. }
  1142. return false;
  1143. }
  1144. function plexJoinAPI($array)
  1145. {
  1146. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1147. }
  1148. function plexJoin($username, $email, $password)
  1149. {
  1150. try {
  1151. $url = 'https://plex.tv/users.json';
  1152. $headers = array(
  1153. 'Accept'=> 'application/json',
  1154. 'Content-Type' => 'application/x-www-form-urlencoded',
  1155. 'X-Plex-Product' => 'Organizr',
  1156. 'X-Plex-Version' => '2.0',
  1157. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1158. );
  1159. $data = array(
  1160. 'user[email]' => $email,
  1161. 'user[username]' => $username,
  1162. 'user[password]' => $password,
  1163. );
  1164. $response = Requests::post($url, $headers, $data, array());
  1165. $json = json_decode($response->body, true);
  1166. $errors = (!empty($json['errors']) ? true : false);
  1167. $success = (!empty($json['user']) ? true : false);
  1168. //Use This for later
  1169. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1170. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1171. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1172. $errorMessage = "";
  1173. if ($errors) {
  1174. if ($usernameError) {
  1175. $errorMessage .= "[Username Error: ". $usernameError ."]";
  1176. }
  1177. if ($emailError) {
  1178. $errorMessage .= "[Email Error: ". $emailError ."]";
  1179. }
  1180. if ($passwordError) {
  1181. $errorMessage .= "[Password Error: ". $passwordError ."]";
  1182. }
  1183. }
  1184. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1185. } catch (Requests_Exception $e) {
  1186. writeLog('error', 'Plex.TV Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  1187. };
  1188. return false;
  1189. }