organizr-functions.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. <?php
  2. function organizrSpecialSettings()
  3. {
  4. $refreshSearch = "Refresh";
  5. $tautulliSearch = "tautulli_token";
  6. $tautulli = array_filter($_COOKIE, function ($k) use ($tautulliSearch) {
  7. return stripos($k, $tautulliSearch) !== false;
  8. }, ARRAY_FILTER_USE_KEY);
  9. return array(
  10. 'homepage' => array(
  11. 'refresh' => array_filter($GLOBALS, function ($k) use ($refreshSearch) {
  12. return stripos($k, $refreshSearch) !== false;
  13. }, ARRAY_FILTER_USE_KEY),
  14. 'search' => array(
  15. 'enabled' => (qualifyRequest($GLOBALS['mediaSearchAuth']) && $GLOBALS['mediaSearch'] == true && $GLOBALS['plexToken']) ? true : false,
  16. 'type' => $GLOBALS['mediaSearchType'],
  17. ),
  18. 'ombi' => array(
  19. 'enabled' => (qualifyRequest($GLOBALS['homepageOmbiAuth']) && qualifyRequest($GLOBALS['homepageOmbiRequestAuth']) && $GLOBALS['homepageOmbiEnabled'] == true && $GLOBALS['ssoOmbi'] && isset($_COOKIE['Auth'])) ? true : false,
  20. 'authView' => (qualifyRequest($GLOBALS['homepageOmbiAuth'])) ? true : false,
  21. 'authRequest' => (qualifyRequest($GLOBALS['homepageOmbiRequestAuth'])) ? true : false,
  22. 'sso' => ($GLOBALS['ssoOmbi']) ? true : false,
  23. 'cookie' => (isset($_COOKIE['Auth'])) ? true : false,
  24. ),
  25. 'options' => array(
  26. 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
  27. )
  28. ),
  29. 'sso' => array(
  30. 'plex' => array(
  31. 'enabled' => ($GLOBALS['ssoPlex']) ? true : false,
  32. 'cookie' => isset($_COOKIE['mpt']) ? true : false,
  33. ),
  34. 'ombi' => array(
  35. 'enabled' => ($GLOBALS['ssoOmbi']) ? true : false,
  36. 'cookie' => isset($_COOKIE['Auth']) ? true : false,
  37. ),
  38. 'tautulli' => array(
  39. 'enabled' => ($GLOBALS['ssoTautulli']) ? true : false,
  40. 'cookie' => !empty($tautulli) ? true : false,
  41. ),
  42. ),
  43. 'ping' => array(
  44. 'onlineSound' => $GLOBALS['pingOnlineSound'],
  45. 'offlineSound' => $GLOBALS['pingOfflineSound'],
  46. 'auth' => $GLOBALS['pingAuth'],
  47. 'authMessage' => $GLOBALS['pingAuthMessage'],
  48. 'authMs' => $GLOBALS['pingAuthMs'],
  49. 'ms' => $GLOBALS['pingMs'],
  50. 'adminRefresh' => $GLOBALS['adminPingRefresh'],
  51. 'everyoneRefresh' => $GLOBALS['otherPingRefresh'],
  52. ),
  53. 'notifications' => array(
  54. 'backbone' => $GLOBALS['notificationBackbone'],
  55. 'position' => $GLOBALS['notificationPosition']
  56. ),
  57. 'lockout' => array(
  58. 'enabled' => $GLOBALS['lockoutSystem'],
  59. 'timer' => $GLOBALS['lockoutTimeout'],
  60. 'minGroup' => $GLOBALS['lockoutMinAuth'],
  61. 'maxGroup' => $GLOBALS['lockoutMaxAuth']
  62. ),
  63. 'user' => array(
  64. 'agent' => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null
  65. ),
  66. 'misc' => array(
  67. 'installedPlugins' => $GLOBALS['installedPlugins'],
  68. 'installedThemes' => $GLOBALS['installedThemes'],
  69. 'return' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false,
  70. 'authDebug' => $GLOBALS['authDebug'],
  71. 'minimalLoginScreen' => $GLOBALS['minimalLoginScreen'],
  72. 'unsortedTabs' => $GLOBALS['unsortedTabs'],
  73. 'authBackend' => $GLOBALS['authBackend'],
  74. 'newMessageSound' => $GLOBALS['CHAT-newMessageSound-include'],
  75. )
  76. );
  77. }
  78. function wizardConfig($array)
  79. {
  80. foreach ($array['data'] as $items) {
  81. foreach ($items as $key => $value) {
  82. if ($key == 'name') {
  83. $newKey = $value;
  84. }
  85. if ($key == 'value') {
  86. $newValue = $value;
  87. }
  88. if (isset($newKey) && isset($newValue)) {
  89. $$newKey = $newValue;
  90. }
  91. }
  92. }
  93. $location = cleanDirectory($location);
  94. $dbName = $dbName . '.db';
  95. $configVersion = $GLOBALS['installedVersion'];
  96. $configArray = array(
  97. 'dbName' => $dbName,
  98. 'dbLocation' => $location,
  99. 'license' => $license,
  100. 'organizrHash' => $hashKey,
  101. 'organizrAPI' => $api,
  102. 'registrationPassword' => $registrationPassword,
  103. );
  104. // Create Config
  105. $GLOBALS['dbLocation'] = $location;
  106. $GLOBALS['dbName'] = $dbName;
  107. if (createConfig($configArray)) {
  108. // Call DB Create
  109. if (createDB($location, $dbName)) {
  110. // Add in first user
  111. if (createFirstAdmin($location, $dbName, $username, $password, $email)) {
  112. if (createToken($username, $email, gravatar($email), 'Admin', 0, $hashKey, 1)) {
  113. return true;
  114. } else {
  115. return 'token';
  116. }
  117. } else {
  118. return 'admin';
  119. }
  120. } else {
  121. return 'db';
  122. }
  123. } else {
  124. return 'config';
  125. }
  126. return false;
  127. }
  128. function register($array)
  129. {
  130. // Grab username and password from login form
  131. foreach ($array['data'] as $items) {
  132. foreach ($items as $key => $value) {
  133. if ($key == 'name') {
  134. $newKey = $value;
  135. }
  136. if ($key == 'value') {
  137. $newValue = $value;
  138. }
  139. if (isset($newKey) && isset($newValue)) {
  140. $$newKey = $newValue;
  141. }
  142. }
  143. }
  144. if ($registrationPassword == $GLOBALS['registrationPassword']) {
  145. $defaults = defaultUserGroup();
  146. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  147. if (createUser($username, $password, $defaults, $email)) {
  148. writeLog('success', 'Registration Function - A User has registered', $username);
  149. if (createToken($username, $email, gravatar($email), $defaults['group'], $defaults['group_id'], $GLOBALS['organizrHash'], 1)) {
  150. writeLoginLog($username, 'success');
  151. writeLog('success', 'Login Function - A User has logged in', $username);
  152. return true;
  153. }
  154. } else {
  155. writeLog('error', 'Registration Function - An error occured', $username);
  156. return 'username taken';
  157. }
  158. } else {
  159. writeLog('warning', 'Registration Function - Wrong Password', $username);
  160. return 'mismatch';
  161. }
  162. }
  163. function removeFile($array)
  164. {
  165. $filePath = $array['data']['path'];
  166. $fileName = $array['data']['name'];
  167. if (file_exists($filePath)) {
  168. if (unlink($filePath)) {
  169. writeLog('success', 'Log Management Function - Log: ' . $fileName . ' has been purged/deleted', 'SYSTEM');
  170. return true;
  171. } else {
  172. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' - Error Occured', 'SYSTEM');
  173. return false;
  174. }
  175. } else {
  176. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' does not exist', 'SYSTEM');
  177. return false;
  178. }
  179. }
  180. function recover($array)
  181. {
  182. $email = $array['data']['email'];
  183. $newPassword = randString(10);
  184. try {
  185. $connect = new Dibi\Connection([
  186. 'driver' => 'sqlite3',
  187. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  188. ]);
  189. $isUser = $connect->fetch('SELECT * FROM users WHERE email = ? COLLATE NOCASE', $email);
  190. if ($isUser) {
  191. $connect->query('
  192. UPDATE users SET', [
  193. 'password' => password_hash($newPassword, PASSWORD_BCRYPT)
  194. ], '
  195. WHERE email=? COLLATE NOCASE', $email);
  196. if ($GLOBALS['PHPMAILER-enabled']) {
  197. $emailTemplate = array(
  198. 'type' => 'reset',
  199. 'body' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'],
  200. 'subject' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'],
  201. 'user' => $isUser['username'],
  202. 'password' => $newPassword,
  203. 'inviteCode' => null,
  204. );
  205. $emailTemplate = phpmEmailTemplate($emailTemplate);
  206. $sendEmail = array(
  207. 'to' => $email,
  208. 'user' => $isUser['username'],
  209. 'subject' => $emailTemplate['subject'],
  210. 'body' => phpmBuildEmail($emailTemplate),
  211. );
  212. phpmSendEmail($sendEmail);
  213. }
  214. writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
  215. return true;
  216. } else {
  217. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  218. return 'an error occured';
  219. }
  220. } catch (Dibi\Exception $e) {
  221. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  222. return 'an error occured';
  223. }
  224. }
  225. function unlock($array)
  226. {
  227. if ($array['data']['password'] == '') {
  228. return 'Password Not Set';
  229. }
  230. try {
  231. $connect = new Dibi\Connection([
  232. 'driver' => 'sqlite3',
  233. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  234. ]);
  235. $result = $connect->fetch('SELECT * FROM users WHERE id = ?', $GLOBALS['organizrUser']['userID']);
  236. if (!password_verify($array['data']['password'], $result['password'])) {
  237. return 'Password Incorrect';
  238. }
  239. $connect->query('
  240. UPDATE users SET', [
  241. 'locked' => ''
  242. ], '
  243. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  244. writeLog('success', 'User Lockout Function - User: ' . $GLOBALS['organizrUser']['username'] . '\'s account unlocked', $GLOBALS['organizrUser']['username']);
  245. return true;
  246. } catch (Dibi\Exception $e) {
  247. writeLog('error', 'User Management Function - Error - User: ' . $GLOBALS['organizrUser']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  248. return 'an error occured';
  249. }
  250. }
  251. function lock()
  252. {
  253. if ($GLOBALS['organizrUser']['userID'] == '999') {
  254. return 'Not Allowed on Guest';
  255. }
  256. try {
  257. $connect = new Dibi\Connection([
  258. 'driver' => 'sqlite3',
  259. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  260. ]);
  261. $connect->query('
  262. UPDATE users SET', [
  263. 'locked' => '1'
  264. ], '
  265. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  266. writeLog('success', 'User Lockout Function - User: ' . $GLOBALS['organizrUser']['username'] . '\'s account unlocked', $GLOBALS['organizrUser']['username']);
  267. return true;
  268. } catch (Dibi\Exception $e) {
  269. writeLog('error', 'User Management Function - Error - User: ' . $GLOBALS['organizrUser']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  270. return 'an error occured';
  271. }
  272. }
  273. function editUser($array)
  274. {
  275. if ($array['data']['username'] == '' && $array['data']['username'] == '') {
  276. return 'Username/email not set';
  277. }
  278. try {
  279. $connect = new Dibi\Connection([
  280. 'driver' => 'sqlite3',
  281. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  282. ]);
  283. if (!usernameTakenExcept($array['data']['username'], $array['data']['email'], $GLOBALS['organizrUser']['userID'])) {
  284. $connect->query('
  285. UPDATE users SET', [
  286. 'username' => $array['data']['username'],
  287. 'email' => $array['data']['email'],
  288. ], '
  289. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  290. if (!empty($array['data']['password'])) {
  291. $connect->query('
  292. UPDATE users SET', [
  293. 'password' => password_hash($array['data']['password'], PASSWORD_BCRYPT)
  294. ], '
  295. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  296. }
  297. writeLog('success', 'User Management Function - User: ' . $array['data']['username'] . '\'s info was changed', $GLOBALS['organizrUser']['username']);
  298. return true;
  299. } else {
  300. return 'Username/Email Already Taken';
  301. }
  302. } catch (Dibi\Exception $e) {
  303. writeLog('error', 'User Management Function - Error - User: ' . $array['data']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  304. return 'an error occured';
  305. }
  306. }
  307. function logout()
  308. {
  309. coookie('delete', $GLOBALS['cookieName']);
  310. coookie('delete', 'mpt');
  311. coookie('delete', 'Auth');
  312. $GLOBALS['organizrUser'] = false;
  313. return true;
  314. }
  315. function qualifyRequest($accessLevelNeeded)
  316. {
  317. if (getUserLevel() <= $accessLevelNeeded) {
  318. return true;
  319. } else {
  320. return false;
  321. }
  322. }
  323. function getUserLevel()
  324. {
  325. // Grab token
  326. //$requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  327. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : (isset($_GET['apikey']) ? $_GET['apikey'] : false);
  328. // Check token or API key
  329. // If API key, return 0 for admin
  330. if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
  331. //DO API CHECK
  332. return 0;
  333. } elseif (isset($GLOBALS['organizrUser'])) {
  334. return $GLOBALS['organizrUser']['groupID'];
  335. }
  336. // All else fails? return guest id
  337. return 999;
  338. }
  339. function organizrStatus()
  340. {
  341. $status = array();
  342. $dependenciesActive = array();
  343. $dependenciesInactive = array();
  344. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  345. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  346. foreach ($extensions as $check) {
  347. if (extension_loaded($check)) {
  348. array_push($dependenciesActive, $check);
  349. } else {
  350. array_push($dependenciesInactive, $check);
  351. }
  352. }
  353. foreach ($functions as $check) {
  354. if (function_exists($check)) {
  355. array_push($dependenciesActive, $check);
  356. } else {
  357. array_push($dependenciesInactive, $check);
  358. }
  359. }
  360. if (!file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
  361. $status['status'] = "wizard";//wizard - ok for test
  362. }
  363. if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0)) {
  364. $status['status'] = "dependencies";
  365. }
  366. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  367. $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
  368. $status['minVersion'] = (version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0) ? 'yes' : 'no';
  369. $status['dependenciesActive'] = $dependenciesActive;
  370. $status['dependenciesInactive'] = $dependenciesInactive;
  371. $status['version'] = $GLOBALS['installedVersion'];
  372. $status['os'] = getOS();
  373. $status['php'] = phpversion();
  374. return $status;
  375. }
  376. function getSettingsMain()
  377. {
  378. return array(
  379. 'Github' => array(
  380. array(
  381. 'type' => 'select',
  382. 'name' => 'branch',
  383. 'label' => 'Branch',
  384. 'value' => $GLOBALS['branch'],
  385. 'options' => getBranches()
  386. ),
  387. array(
  388. 'type' => 'button',
  389. 'label' => 'Force Install Branch',
  390. 'class' => 'updateNow',
  391. 'icon' => 'fa fa-download',
  392. 'text' => 'Retrieve'
  393. )
  394. ),
  395. 'API' => array(
  396. array(
  397. 'type' => 'password-alt',
  398. 'name' => 'organizrAPI',
  399. 'label' => 'Organizr API',
  400. 'value' => $GLOBALS['organizrAPI']
  401. ),
  402. array(
  403. 'type' => 'button',
  404. 'label' => 'Generate New API Key',
  405. 'class' => 'newAPIKey',
  406. 'icon' => 'fa fa-refresh',
  407. 'text' => 'Generate'
  408. )
  409. ),
  410. 'Authentication' => array(
  411. array(
  412. 'type' => 'select',
  413. 'name' => 'authType',
  414. 'id' => 'authSelect',
  415. 'label' => 'Authentication Type',
  416. 'value' => $GLOBALS['authType'],
  417. 'options' => getAuthTypes()
  418. ),
  419. array(
  420. 'type' => 'select',
  421. 'name' => 'authBackend',
  422. 'id' => 'authBackendSelect',
  423. 'label' => 'Authentication Backend',
  424. 'class' => 'backendAuth switchAuth',
  425. 'value' => $GLOBALS['authBackend'],
  426. 'options' => getAuthBackends()
  427. ),
  428. array(
  429. 'type' => 'password-alt',
  430. 'name' => 'plexToken',
  431. 'class' => 'plexAuth switchAuth',
  432. 'label' => 'Plex Token',
  433. 'value' => $GLOBALS['plexToken'],
  434. 'placeholder' => 'Use Get Token Button'
  435. ),
  436. array(
  437. 'type' => 'button',
  438. 'label' => 'Get Plex Token',
  439. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  440. 'icon' => 'fa fa-ticket',
  441. 'text' => 'Retrieve',
  442. 'href' => '#auth-plex-token-form',
  443. 'attr' => 'data-effect="mfp-3d-unfold"'
  444. ),
  445. array(
  446. 'type' => 'password-alt',
  447. 'name' => 'plexID',
  448. 'class' => 'plexAuth switchAuth',
  449. 'label' => 'Plex Machine',
  450. 'value' => $GLOBALS['plexID'],
  451. 'placeholder' => 'Use Get Plex Machine Button'
  452. ),
  453. array(
  454. 'type' => 'button',
  455. 'label' => 'Get Plex Machine',
  456. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  457. 'icon' => 'fa fa-id-badge',
  458. 'text' => 'Retrieve',
  459. 'href' => '#auth-plex-machine-form',
  460. 'attr' => 'data-effect="mfp-3d-unfold"'
  461. ),
  462. array(
  463. 'type' => 'input',
  464. 'name' => 'authBackendHost',
  465. 'class' => 'ldapAuth ftpAuth switchAuth',
  466. 'label' => 'Host Address',
  467. 'value' => $GLOBALS['authBackendHost'],
  468. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  469. ),
  470. array(
  471. 'type' => 'input',
  472. 'name' => 'authBaseDN',
  473. 'class' => 'ldapAuth switchAuth',
  474. 'label' => 'Host Base DN',
  475. 'value' => $GLOBALS['authBaseDN'],
  476. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  477. ),
  478. array(
  479. 'type' => 'input',
  480. 'name' => 'embyURL',
  481. 'class' => 'embyAuth switchAuth',
  482. 'label' => 'Emby URL',
  483. 'value' => $GLOBALS['embyURL'],
  484. 'placeholder' => 'http(s)://hostname:port'
  485. ),
  486. array(
  487. 'type' => 'password-alt',
  488. 'name' => 'embyToken',
  489. 'class' => 'embyAuth switchAuth',
  490. 'label' => 'Emby Token',
  491. 'value' => $GLOBALS['embyToken'],
  492. 'placeholder' => ''
  493. ),
  494. /*array(
  495. 'type' => 'button',
  496. 'label' => 'Send Test',
  497. 'class' => 'phpmSendTestEmail',
  498. 'icon' => 'fa fa-paper-plane',
  499. 'text' => 'Send'
  500. )*/
  501. ),
  502. 'Security' => array(
  503. array(
  504. 'type' => 'number',
  505. 'name' => 'lockoutTimeout',
  506. 'label' => 'Inactivity Timer [Minutes]',
  507. 'value' => $GLOBALS['lockoutTimeout'],
  508. 'placeholder' => ''
  509. ),
  510. array(
  511. 'type' => 'switch',
  512. 'name' => 'lockoutSystem',
  513. 'label' => 'Inactivity Lock',
  514. 'value' => $GLOBALS['lockoutSystem']
  515. ),
  516. array(
  517. 'type' => 'select',
  518. 'name' => 'lockoutMinAuth',
  519. 'label' => 'Lockout Groups From',
  520. 'value' => $GLOBALS['lockoutMinAuth'],
  521. 'options' => groupSelect()
  522. ),
  523. array(
  524. 'type' => 'select',
  525. 'name' => 'lockoutMaxAuth',
  526. 'label' => 'Lockout Groups To',
  527. 'value' => $GLOBALS['lockoutMaxAuth'],
  528. 'options' => groupSelect()
  529. ),
  530. array(
  531. 'type' => 'password-alt',
  532. 'name' => 'registrationPassword',
  533. 'label' => 'Registration Password',
  534. 'value' => $GLOBALS['registrationPassword'],
  535. ),
  536. array(
  537. 'type' => 'switch',
  538. 'name' => 'hideRegistration',
  539. 'label' => 'Hide Registration',
  540. 'value' => $GLOBALS['hideRegistration'],
  541. ),
  542. array(
  543. 'type' => 'switch',
  544. 'name' => 'authDebug',
  545. 'label' => 'Nginx Auth Debug',
  546. 'help' => 'Important! Do not keep this enabled for too long as this opens up Authentication while testing.',
  547. 'value' => $GLOBALS['authDebug'],
  548. 'class' => 'authDebug'
  549. )
  550. ),
  551. 'Ping' => array(
  552. array(
  553. 'type' => 'select',
  554. 'name' => 'pingAuth',
  555. 'label' => 'Minimum Authentication',
  556. 'value' => $GLOBALS['pingAuth'],
  557. 'options' => groupSelect()
  558. ),
  559. array(
  560. 'type' => 'select',
  561. 'name' => 'pingAuthMessage',
  562. 'label' => 'Minimum Authentication for Message and Sound',
  563. 'value' => $GLOBALS['pingAuthMessage'],
  564. 'options' => groupSelect()
  565. ),
  566. array(
  567. 'type' => 'select',
  568. 'name' => 'pingOnlineSound',
  569. 'label' => 'Online Sound',
  570. 'value' => $GLOBALS['pingOnlineSound'],
  571. 'options' => getSounds()
  572. ),
  573. array(
  574. 'type' => 'select',
  575. 'name' => 'pingOfflineSound',
  576. 'label' => 'Offline Sound',
  577. 'value' => $GLOBALS['pingOfflineSound'],
  578. 'options' => getSounds()
  579. ),
  580. array(
  581. 'type' => 'switch',
  582. 'name' => 'pingMs',
  583. 'label' => 'Show Ping Time',
  584. 'value' => $GLOBALS['pingMs']
  585. ),
  586. array(
  587. 'type' => 'select',
  588. 'name' => 'pingAuthMs',
  589. 'label' => 'Minimum Authentication for Time Display',
  590. 'value' => $GLOBALS['pingAuthMs'],
  591. 'options' => groupSelect()
  592. ),
  593. array(
  594. 'type' => 'select',
  595. 'name' => 'adminPingRefresh',
  596. 'label' => 'Admin Refresh Seconds',
  597. 'value' => $GLOBALS['adminPingRefresh'],
  598. 'options' => optionTime()
  599. ),
  600. array(
  601. 'type' => 'select',
  602. 'name' => 'otherPingRefresh',
  603. 'label' => 'Everyone Refresh Seconds',
  604. 'value' => $GLOBALS['otherPingRefresh'],
  605. 'options' => optionTime()
  606. ),
  607. )
  608. );
  609. }
  610. function getSSO()
  611. {
  612. return array(
  613. 'FYI' => array(
  614. array(
  615. 'type' => 'html',
  616. 'label' => 'Important Information',
  617. 'override' => 12,
  618. 'html' => '
  619. <div class="row">
  620. <div class="col-lg-12">
  621. <div class="panel panel-info">
  622. <div class="panel-heading">
  623. <span lang="en">Notice</span>
  624. </div>
  625. <div class="panel-wrapper collapse in" aria-expanded="true">
  626. <div class="panel-body">
  627. <span lang="en">This is not the same as database authentication - i.e. Plex Authentication | Emby Authentication | FTP Authentication<br/>Click Main on the sub-menu above.</span>
  628. </div>
  629. </div>
  630. </div>
  631. </div>
  632. </div>
  633. '
  634. )
  635. ),
  636. 'Plex' => array(
  637. array(
  638. 'type' => 'password-alt',
  639. 'name' => 'plexToken',
  640. 'label' => 'Plex Token',
  641. 'value' => $GLOBALS['plexToken'],
  642. 'placeholder' => 'Use Get Token Button'
  643. ),
  644. array(
  645. 'type' => 'button',
  646. 'label' => 'Get Plex Token',
  647. 'class' => 'popup-with-form getPlexTokenSSO',
  648. 'icon' => 'fa fa-ticket',
  649. 'text' => 'Retrieve',
  650. 'href' => '#sso-plex-token-form',
  651. 'attr' => 'data-effect="mfp-3d-unfold"'
  652. ),
  653. array(
  654. 'type' => 'password-alt',
  655. 'name' => 'plexID',
  656. 'label' => 'Plex Machine',
  657. 'value' => $GLOBALS['plexID'],
  658. 'placeholder' => 'Use Get Plex Machine Button'
  659. ),
  660. array(
  661. 'type' => 'button',
  662. 'label' => 'Get Plex Machine',
  663. 'class' => 'popup-with-form getPlexMachineSSO',
  664. 'icon' => 'fa fa-id-badge',
  665. 'text' => 'Retrieve',
  666. 'href' => '#sso-plex-machine-form',
  667. 'attr' => 'data-effect="mfp-3d-unfold"'
  668. ),
  669. array(
  670. 'type' => 'input',
  671. 'name' => 'plexAdmin',
  672. 'label' => 'Admin Username',
  673. 'value' => $GLOBALS['plexAdmin'],
  674. 'placeholder' => 'Admin username for Plex'
  675. ),
  676. array(
  677. 'type' => 'blank',
  678. 'label' => ''
  679. ),
  680. array(
  681. 'type' => 'html',
  682. 'label' => 'Plex Note',
  683. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  684. ),
  685. array(
  686. 'type' => 'switch',
  687. 'name' => 'ssoPlex',
  688. 'label' => 'Enable',
  689. 'value' => $GLOBALS['ssoPlex']
  690. )
  691. ),
  692. 'Ombi' => array(
  693. array(
  694. 'type' => 'input',
  695. 'name' => 'ombiURL',
  696. 'label' => 'Ombi URL',
  697. 'value' => $GLOBALS['ombiURL'],
  698. 'placeholder' => 'http(s)://hostname:port'
  699. ),
  700. array(
  701. 'type' => 'switch',
  702. 'name' => 'ssoOmbi',
  703. 'label' => 'Enable',
  704. 'value' => $GLOBALS['ssoOmbi']
  705. )
  706. ),
  707. 'Tautulli' => array(
  708. array(
  709. 'type' => 'input',
  710. 'name' => 'tautulliURL',
  711. 'label' => 'Tautulli URL',
  712. 'value' => $GLOBALS['tautulliURL'],
  713. 'placeholder' => 'http(s)://hostname:port'
  714. ),
  715. array(
  716. 'type' => 'switch',
  717. 'name' => 'ssoTautulli',
  718. 'label' => 'Enable',
  719. 'value' => $GLOBALS['ssoTautulli']
  720. )
  721. )
  722. );
  723. }
  724. function loadAppearance()
  725. {
  726. $appearance = array();
  727. $appearance['logo'] = $GLOBALS['logo'];
  728. $appearance['title'] = $GLOBALS['title'];
  729. $appearance['useLogo'] = $GLOBALS['useLogo'];
  730. $appearance['headerColor'] = $GLOBALS['headerColor'];
  731. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  732. $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
  733. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  734. $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
  735. $appearance['accentColor'] = $GLOBALS['accentColor'];
  736. $appearance['accentTextColor'] = $GLOBALS['accentTextColor'];
  737. $appearance['buttonColor'] = $GLOBALS['buttonColor'];
  738. $appearance['buttonTextColor'] = $GLOBALS['buttonTextColor'];
  739. $appearance['buttonTextHoverColor'] = $GLOBALS['buttonTextHoverColor'];
  740. $appearance['buttonHoverColor'] = $GLOBALS['buttonHoverColor'];
  741. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  742. $appearance['customCss'] = $GLOBALS['customCss'];
  743. $appearance['customThemeCss'] = $GLOBALS['customThemeCss'];
  744. $appearance['customJava'] = $GLOBALS['customJava'];
  745. $appearance['customThemeJava'] = $GLOBALS['customThemeJava'];
  746. return $appearance;
  747. }
  748. function getCustomizeAppearance()
  749. {
  750. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  751. return array(
  752. 'Top Bar' => array(
  753. array(
  754. 'type' => 'input',
  755. 'name' => 'logo',
  756. 'label' => 'Logo',
  757. 'value' => $GLOBALS['logo']
  758. ),
  759. array(
  760. 'type' => 'input',
  761. 'name' => 'title',
  762. 'label' => 'Title',
  763. 'value' => $GLOBALS['title']
  764. ),
  765. array(
  766. 'type' => 'switch',
  767. 'name' => 'useLogo',
  768. 'label' => 'Use Logo instead of Title',
  769. 'value' => $GLOBALS['useLogo']
  770. )
  771. ),
  772. 'Login Page' => array(
  773. array(
  774. 'type' => 'input',
  775. 'name' => 'loginWallpaper',
  776. 'label' => 'Login Wallpaper',
  777. 'value' => $GLOBALS['loginWallpaper']
  778. ),
  779. array(
  780. 'type' => 'switch',
  781. 'name' => 'minimalLoginScreen',
  782. 'label' => 'Minimal Login Screen',
  783. 'value' => $GLOBALS['minimalLoginScreen']
  784. )
  785. ),
  786. 'Options' => array(
  787. array(
  788. 'type' => 'switch',
  789. 'name' => 'alternateHomepageHeaders',
  790. 'label' => 'Alternate Homepage Titles',
  791. 'value' => $GLOBALS['alternateHomepageHeaders']
  792. ),
  793. array(
  794. 'type' => 'select',
  795. 'name' => 'unsortedTabs',
  796. 'label' => 'Unsorted Tab Placement',
  797. 'value' => $GLOBALS['unsortedTabs'],
  798. 'options' => array(
  799. array(
  800. 'name' => 'Top',
  801. 'value' => 'top'
  802. ),
  803. array(
  804. 'name' => 'Bottom',
  805. 'value' => 'bottom'
  806. )
  807. )
  808. )
  809. ),
  810. 'Colors & Themes' => array(
  811. array(
  812. 'type' => 'html',
  813. 'override' => 12,
  814. 'label' => 'Custom CSS [Can replace colors from above]',
  815. 'html' => '
  816. <div class="row">
  817. <div class="col-lg-12">
  818. <div class="panel panel-info">
  819. <div class="panel-heading">
  820. <span lang="en">Notice</span>
  821. </div>
  822. <div class="panel-wrapper collapse in" aria-expanded="true">
  823. <div class="panel-body">
  824. <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
  825. </div>
  826. </div>
  827. </div>
  828. </div>
  829. </div>
  830. ',
  831. ),
  832. array(
  833. 'type' => 'blank',
  834. 'label' => ''
  835. ),
  836. array(
  837. 'type' => 'input',
  838. 'name' => 'headerColor',
  839. 'label' => 'Nav Bar Color',
  840. 'value' => $GLOBALS['headerColor'],
  841. 'class' => 'pick-a-color',
  842. 'attr' => 'data-original="' . $GLOBALS['headerColor'] . '"'
  843. ),
  844. array(
  845. 'type' => 'input',
  846. 'name' => 'headerTextColor',
  847. 'label' => 'Nav Bar Text Color',
  848. 'value' => $GLOBALS['headerTextColor'],
  849. 'class' => 'pick-a-color',
  850. 'attr' => 'data-original="' . $GLOBALS['headerTextColor'] . '"'
  851. ),
  852. array(
  853. 'type' => 'input',
  854. 'name' => 'sidebarColor',
  855. 'label' => 'Side Bar Color',
  856. 'value' => $GLOBALS['sidebarColor'],
  857. 'class' => 'pick-a-color',
  858. 'attr' => 'data-original="' . $GLOBALS['sidebarColor'] . '"'
  859. ),
  860. array(
  861. 'type' => 'input',
  862. 'name' => 'sidebarTextColor',
  863. 'label' => 'Side Bar Text Color',
  864. 'value' => $GLOBALS['sidebarTextColor'],
  865. 'class' => 'pick-a-color',
  866. 'attr' => 'data-original="' . $GLOBALS['sidebarTextColor'] . '"'
  867. ),
  868. array(
  869. 'type' => 'input',
  870. 'name' => 'accentColor',
  871. 'label' => 'Accent Color',
  872. 'value' => $GLOBALS['accentColor'],
  873. 'class' => 'pick-a-color',
  874. 'attr' => 'data-original="' . $GLOBALS['accentColor'] . '"'
  875. ),
  876. array(
  877. 'type' => 'input',
  878. 'name' => 'accentTextColor',
  879. 'label' => 'Accent Text Color',
  880. 'value' => $GLOBALS['accentTextColor'],
  881. 'class' => 'pick-a-color',
  882. 'attr' => 'data-original="' . $GLOBALS['accentTextColor'] . '"'
  883. ),
  884. array(
  885. 'type' => 'input',
  886. 'name' => 'buttonColor',
  887. 'label' => 'Button Color',
  888. 'value' => $GLOBALS['buttonColor'],
  889. 'class' => 'pick-a-color',
  890. 'attr' => 'data-original="' . $GLOBALS['buttonColor'] . '"'
  891. ),
  892. array(
  893. 'type' => 'input',
  894. 'name' => 'buttonTextColor',
  895. 'label' => 'Button Text Color',
  896. 'value' => $GLOBALS['buttonTextColor'],
  897. 'class' => 'pick-a-color',
  898. 'attr' => 'data-original="' . $GLOBALS['buttonTextColor'] . '"'
  899. ),/*
  900. array(
  901. 'type' => 'input',
  902. 'name' => 'buttonHoverColor',
  903. 'label' => 'Button Hover Color',
  904. 'value' => $GLOBALS['buttonHoverColor'],
  905. 'class' => 'pick-a-color',
  906. 'disabled' => true
  907. ),
  908. array(
  909. 'type' => 'input',
  910. 'name' => 'buttonTextHoverColor',
  911. 'label' => 'Button Hover Text Color',
  912. 'value' => $GLOBALS['buttonTextHoverColor'],
  913. 'class' => 'pick-a-color',
  914. 'disabled' => true
  915. ),*/
  916. array(
  917. 'type' => 'select',
  918. 'name' => 'theme',
  919. 'label' => 'Theme',
  920. 'class' => 'themeChanger',
  921. 'value' => $GLOBALS['theme'],
  922. 'options' => getThemes()
  923. ),
  924. array(
  925. 'type' => 'select',
  926. 'name' => 'style',
  927. 'label' => 'Style',
  928. 'class' => 'styleChanger',
  929. 'value' => $GLOBALS['style'],
  930. 'options' => array(
  931. array(
  932. 'name' => 'Light',
  933. 'value' => 'light'
  934. ),
  935. array(
  936. 'name' => 'Dark',
  937. 'value' => 'dark'
  938. ),
  939. array(
  940. 'name' => 'Horizontal',
  941. 'value' => 'horizontal'
  942. )
  943. )
  944. )
  945. ),
  946. 'Notifications' => array(
  947. array(
  948. 'type' => 'select',
  949. 'name' => 'notificationBackbone',
  950. 'class' => 'notifyChanger',
  951. 'label' => 'Type',
  952. 'value' => $GLOBALS['notificationBackbone'],
  953. 'options' => optionNotificationTypes()
  954. ),
  955. array(
  956. 'type' => 'select',
  957. 'name' => 'notificationPosition',
  958. 'class' => 'notifyPositionChanger',
  959. 'label' => 'Position',
  960. 'value' => $GLOBALS['notificationPosition'],
  961. 'options' => optionNotificationPositions()
  962. ),
  963. array(
  964. 'type' => 'html',
  965. 'label' => 'Test Message',
  966. 'html' => '
  967. <div class="btn-group m-r-10 dropup">
  968. <button aria-expanded="false" data-toggle="dropdown" class="btn btn-info btn-outline dropdown-toggle waves-effect waves-light" type="button">
  969. <i class="fa fa-comment m-r-5"></i>
  970. <span>Test </span>
  971. </button>
  972. <ul role="menu" class="dropdown-menu">
  973. <li><a onclick="message(\'Test Message\',\'This is a success Message\',activeInfo.settings.notifications.position,\'#FFF\',\'success\',\'5000\');">Success</a></li>
  974. <li><a onclick="message(\'Test Message\',\'This is a info Message\',activeInfo.settings.notifications.position,\'#FFF\',\'info\',\'5000\');">Info</a></li>
  975. <li><a onclick="message(\'Test Message\',\'This is a warning Message\',activeInfo.settings.notifications.position,\'#FFF\',\'warning\',\'5000\');">Warning</a></li>
  976. <li><a onclick="message(\'Test Message\',\'This is a error Message\',activeInfo.settings.notifications.position,\'#FFF\',\'error\',\'5000\');">Error</a></li>
  977. </ul>
  978. </div>
  979. '
  980. )
  981. ),
  982. 'FavIcon' => array(
  983. array(
  984. 'type' => 'textbox',
  985. 'name' => 'favIcon',
  986. 'class' => '',
  987. 'label' => 'Fav Icon Code',
  988. 'value' => $GLOBALS['favIcon'],
  989. 'placeholder' => 'Paste Contents from https://realfavicongenerator.net/',
  990. 'attr' => 'rows="10"',
  991. ),
  992. array(
  993. 'type' => 'html',
  994. 'label' => 'Instructions',
  995. 'html' => '
  996. <div class="panel panel-default">
  997. <div class="panel-heading">
  998. <a href="https://realfavicongenerator.net/" target="_blank"><span class="label label-info m-l-5">Visit FavIcon Site</span></a>
  999. </div>
  1000. <div class="panel-wrapper collapse in">
  1001. <div class="panel-body">
  1002. <ul class="list-icons">
  1003. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Select your Favicon picture"</li>
  1004. <li lang="en"><i class="fa fa-caret-right text-info"></i> Choose your image to use</li>
  1005. <li lang="en"><i class="fa fa-caret-right text-info"></i> Edit settings to your liking</li>
  1006. <li lang="en"><i class="fa fa-caret-right text-info"></i> At bottom of page on "Favicon Generator Options" under "Path" choose "I cannot or I do not want to place favicon files at the root of my web site."</li>
  1007. <li lang="en"><i class="fa fa-caret-right text-info"></i> Enter this path <code>plugins/images/faviconCustom</code></li>
  1008. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Generate your Favicons and HTML code"</li>
  1009. <li lang="en"><i class="fa fa-caret-right text-info"></i> Download and unzip file and place in <code>plugins/images/faviconCustom</code></li>
  1010. <li lang="en"><i class="fa fa-caret-right text-info"></i> Copy code and paste inside left box</li>
  1011. </ul>
  1012. </div>
  1013. </div>
  1014. </div>
  1015. '
  1016. ),
  1017. ),
  1018. 'Custom CSS' => array(
  1019. array(
  1020. 'type' => 'html',
  1021. 'override' => 12,
  1022. 'label' => 'Custom CSS [Can replace colors from above]',
  1023. '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>'
  1024. ),
  1025. array(
  1026. 'type' => 'textbox',
  1027. 'name' => 'customCss',
  1028. 'class' => 'hidden cssTextarea',
  1029. 'label' => '',
  1030. 'value' => $GLOBALS['customCss'],
  1031. 'placeholder' => 'No <style> tags needed',
  1032. 'attr' => 'rows="10"',
  1033. ),
  1034. ),
  1035. 'Theme CSS' => array(
  1036. array(
  1037. 'type' => 'html',
  1038. 'override' => 12,
  1039. 'label' => 'Theme CSS [Can replace colors from above]',
  1040. 'html' => '<button type="button" class="hidden saveCssTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeCSSEditor" style="height:300px">' . $GLOBALS['customThemeCss'] . '</div>'
  1041. ),
  1042. array(
  1043. 'type' => 'textbox',
  1044. 'name' => 'customThemeCss',
  1045. 'class' => 'hidden cssThemeTextarea',
  1046. 'label' => '',
  1047. 'value' => $GLOBALS['customThemeCss'],
  1048. 'placeholder' => 'No <style> tags needed',
  1049. 'attr' => 'rows="10"',
  1050. ),
  1051. ),
  1052. 'Custom Javascript' => array(
  1053. array(
  1054. 'type' => 'html',
  1055. 'override' => 12,
  1056. 'label' => 'Custom Javascript',
  1057. 'html' => '<button type="button" class="hidden saveJava btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customJavaEditor" style="height:300px">' . $GLOBALS['customJava'] . '</div>'
  1058. ),
  1059. array(
  1060. 'type' => 'textbox',
  1061. 'name' => 'customJava',
  1062. 'class' => 'hidden javaTextarea',
  1063. 'label' => '',
  1064. 'value' => $GLOBALS['customJava'],
  1065. 'placeholder' => 'No <script> tags needed',
  1066. 'attr' => 'rows="10"',
  1067. ),
  1068. ),
  1069. 'Theme Javascript' => array(
  1070. array(
  1071. 'type' => 'html',
  1072. 'override' => 12,
  1073. 'label' => 'Theme Javascript',
  1074. 'html' => '<button type="button" class="hidden saveJavaTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeJavaEditor" style="height:300px">' . $GLOBALS['customThemeJava'] . '</div>'
  1075. ),
  1076. array(
  1077. 'type' => 'textbox',
  1078. 'name' => 'customThemeJava',
  1079. 'class' => 'hidden javaThemeTextarea',
  1080. 'label' => '',
  1081. 'value' => $GLOBALS['customThemeJava'],
  1082. 'placeholder' => 'No <script> tags needed',
  1083. 'attr' => 'rows="10"',
  1084. ),
  1085. ),
  1086. );
  1087. }
  1088. }
  1089. function editAppearance($array)
  1090. {
  1091. switch ($array['data']['value']) {
  1092. case 'true':
  1093. $array['data']['value'] = (bool)true;
  1094. break;
  1095. case 'false':
  1096. $array['data']['value'] = (bool)false;
  1097. break;
  1098. default:
  1099. $array['data']['value'] = $array['data']['value'];
  1100. }
  1101. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  1102. switch ($array['data']['action']) {
  1103. case 'editCustomizeAppearance':
  1104. $newItem = array(
  1105. $array['data']['name'] => $array['data']['value']
  1106. );
  1107. return (updateConfig($newItem)) ? true : false;
  1108. break;
  1109. default:
  1110. # code...
  1111. break;
  1112. }
  1113. }
  1114. function updateConfigMultiple($array)
  1115. {
  1116. return (updateConfig($array['data']['payload'])) ? true : false;
  1117. }
  1118. function updateConfigMultipleForm($array)
  1119. {
  1120. $newItem = array();
  1121. foreach ($array['data']['payload'] as $k => $v) {
  1122. switch ($v['value']) {
  1123. case 'true':
  1124. $v['value'] = (bool)true;
  1125. break;
  1126. case 'false':
  1127. $v['value'] = (bool)false;
  1128. break;
  1129. default:
  1130. $v['value'] = $v['value'];
  1131. }
  1132. // Hash
  1133. if ($v['type'] == 'password') {
  1134. if (strpos($v['value'], '==') !== false) {
  1135. $v['value'] = $v['value'];
  1136. } else {
  1137. $v['value'] = encrypt($v['value']);
  1138. }
  1139. }
  1140. $newItem[$v['name']] = $v['value'];
  1141. }
  1142. //return $newItem;
  1143. return (updateConfig($newItem)) ? true : false;
  1144. }
  1145. function updateConfigItem($array)
  1146. {
  1147. switch ($array['data']['value']) {
  1148. case 'true':
  1149. $array['data']['value'] = (bool)true;
  1150. break;
  1151. case 'false':
  1152. $array['data']['value'] = (bool)false;
  1153. break;
  1154. default:
  1155. $array['data']['value'] = $array['data']['value'];
  1156. }
  1157. // Hash
  1158. if ($array['data']['type'] == 'password') {
  1159. $array['data']['value'] = encrypt($array['data']['value']);
  1160. }
  1161. $newItem = array(
  1162. $array['data']['name'] => $array['data']['value']
  1163. );
  1164. return (updateConfig($newItem)) ? true : false;
  1165. }
  1166. function getPlugins()
  1167. {
  1168. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  1169. $pluginList = [];
  1170. foreach ($GLOBALS['plugins'] as $plugin) {
  1171. foreach ($plugin as $key => $value) {
  1172. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  1173. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
  1174. $pluginList[$key] = $plugin[$key];
  1175. }
  1176. }
  1177. }
  1178. return $pluginList;
  1179. }
  1180. return false;
  1181. }
  1182. function editPlugins($array)
  1183. {
  1184. switch ($array['data']['action']) {
  1185. case 'enable':
  1186. $newItem = array(
  1187. $array['data']['configName'] => true
  1188. );
  1189. writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  1190. return (updateConfig($newItem)) ? true : false;
  1191. break;
  1192. case 'disable':
  1193. $newItem = array(
  1194. $array['data']['configName'] => false
  1195. );
  1196. writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  1197. return (updateConfig($newItem)) ? true : false;
  1198. break;
  1199. default:
  1200. # code...
  1201. break;
  1202. }
  1203. }
  1204. function auth()
  1205. {
  1206. $debug = $GLOBALS['authDebug']; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  1207. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  1208. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  1209. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  1210. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  1211. $currentIP = userIP();
  1212. $unlocked = ($GLOBALS['organizrUser']['locked'] == '1') ? false : true;
  1213. if (isset($GLOBALS['organizrUser'])) {
  1214. $currentUser = $GLOBALS['organizrUser']['username'];
  1215. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  1216. } else {
  1217. $currentUser = 'Guest';
  1218. $currentGroup = getUserLevel();
  1219. }
  1220. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  1221. if ($whitelist) {
  1222. if (in_array($currentIP, arrayIP($whitelist))) {
  1223. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  1224. }
  1225. }
  1226. if ($blacklist) {
  1227. if (in_array($currentIP, arrayIP($blacklist))) {
  1228. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  1229. }
  1230. }
  1231. if ($group !== null) {
  1232. if (qualifyRequest($group) && $unlocked) {
  1233. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  1234. } else {
  1235. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  1236. }
  1237. } else {
  1238. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  1239. }
  1240. }
  1241. function logoOrText()
  1242. {
  1243. if ($GLOBALS['useLogo'] == false) {
  1244. return '<h1>' . $GLOBALS['title'] . '</h1>';
  1245. } else {
  1246. return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
  1247. }
  1248. }
  1249. function showLogin()
  1250. {
  1251. if ($GLOBALS['hideRegistration'] == false) {
  1252. 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>';
  1253. }
  1254. }
  1255. function getImages()
  1256. {
  1257. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  1258. $path = 'plugins/images/tabs/';
  1259. $images = scandir($dirname);
  1260. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  1261. $allIcons = array();
  1262. foreach ($images as $image) {
  1263. if (!in_array($image, $ignore)) {
  1264. $allIcons[] = $path . $image;
  1265. }
  1266. }
  1267. return $allIcons;
  1268. }
  1269. function imageSelect($form)
  1270. {
  1271. $i = 1;
  1272. $images = getImages();
  1273. $return = '<select class="form-control tabIconImageList" id="' . $form . '-chooseImage" name="chooseImage"><option lang="en">Select or type Icon</option>';
  1274. foreach ($images as $image) {
  1275. $i++;
  1276. $return .= '<option value="' . $image . '">' . basename($image) . '</option>';
  1277. }
  1278. return $return . '</select>';
  1279. }
  1280. function editImages()
  1281. {
  1282. $array = array();
  1283. $postCheck = array_filter($_POST);
  1284. $filesCheck = array_filter($_FILES);
  1285. if (!empty($postCheck)) {
  1286. if ($_POST['data']['action'] == 'deleteImage') {
  1287. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
  1288. writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
  1289. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
  1290. }
  1291. }
  1292. }
  1293. if (!empty($filesCheck)) {
  1294. ini_set('upload_max_filesize', '10M');
  1295. ini_set('post_max_size', '10M');
  1296. $tempFile = $_FILES['file']['tmp_name'];
  1297. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  1298. $targetFile = $targetPath . $_FILES['file']['name'];
  1299. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  1300. }
  1301. return false;
  1302. }
  1303. function getThemes()
  1304. {
  1305. $themes = array();
  1306. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  1307. $themes[] = array(
  1308. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1309. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  1310. );
  1311. }
  1312. return $themes;
  1313. }
  1314. function getSounds()
  1315. {
  1316. $sounds = array();
  1317. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  1318. $sounds[] = array(
  1319. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1320. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/default/' . basename($filename) . '.mp3')
  1321. );
  1322. }
  1323. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  1324. $sounds[] = array(
  1325. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1326. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/custom/' . basename($filename) . '.mp3')
  1327. );
  1328. }
  1329. return $sounds;
  1330. }
  1331. function getBranches()
  1332. {
  1333. return array(
  1334. array(
  1335. 'name' => 'Develop',
  1336. 'value' => 'v2-develop'
  1337. ),
  1338. array(
  1339. 'name' => 'Master',
  1340. 'value' => 'v2-master'
  1341. )
  1342. );
  1343. }
  1344. function getAuthTypes()
  1345. {
  1346. return array(
  1347. array(
  1348. 'name' => 'Organizr DB',
  1349. 'value' => 'internal'
  1350. ),
  1351. array(
  1352. 'name' => 'Organizr DB + Backend',
  1353. 'value' => 'both'
  1354. ),
  1355. array(
  1356. 'name' => 'Backend Only',
  1357. 'value' => 'external'
  1358. )
  1359. );
  1360. }
  1361. function getAuthBackends()
  1362. {
  1363. $backendOptions = array();
  1364. $backendOptions[] = array(
  1365. 'name' => 'Choose Backend',
  1366. 'value' => false,
  1367. 'disabled' => true
  1368. );
  1369. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  1370. return strpos($v, 'plugin_auth_') === 0;
  1371. }) as $value) {
  1372. $name = str_replace('plugin_auth_', '', $value);
  1373. if (strpos($name, 'disabled') === false) {
  1374. $backendOptions[] = array(
  1375. 'name' => ucwords(str_replace('_', ' ', $name)),
  1376. 'value' => $name
  1377. );
  1378. } else {
  1379. $backendOptions[] = array(
  1380. 'name' => $value(),
  1381. 'value' => 'none',
  1382. 'disabled' => true,
  1383. );
  1384. }
  1385. }
  1386. ksort($backendOptions);
  1387. return $backendOptions;
  1388. }
  1389. function wizardPath($array)
  1390. {
  1391. $path = $array['data']['path'];
  1392. if (file_exists($path)) {
  1393. if (is_writable($path)) {
  1394. return true;
  1395. }
  1396. } else {
  1397. if (is_writable(dirname($path, 1))) {
  1398. if (mkdir($path, 0760, true)) {
  1399. return true;
  1400. }
  1401. }
  1402. }
  1403. return 'permissions';
  1404. }
  1405. function groupSelect()
  1406. {
  1407. $groups = allGroups();
  1408. $select = array();
  1409. foreach ($groups as $key => $value) {
  1410. $select[] = array(
  1411. 'name' => $value['group'],
  1412. 'value' => $value['group_id']
  1413. );
  1414. }
  1415. return $select;
  1416. }
  1417. function getImage()
  1418. {
  1419. $refresh = false;
  1420. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1421. if (!file_exists($cacheDirectory)) {
  1422. mkdir($cacheDirectory, 0777, true);
  1423. }
  1424. @$image_url = $_GET['img'];
  1425. @$key = $_GET['key'];
  1426. @$image_height = $_GET['height'];
  1427. @$image_width = $_GET['width'];
  1428. @$source = $_GET['source'];
  1429. @$itemType = $_GET['type'];
  1430. if (strpos($key, '$') !== false) {
  1431. $key = explode('$', $key)[0];
  1432. $refresh = true;
  1433. }
  1434. switch ($source) {
  1435. case 'plex':
  1436. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  1437. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  1438. break;
  1439. case 'emby':
  1440. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  1441. $imgParams = array();
  1442. if (isset($_GET['height'])) {
  1443. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  1444. }
  1445. if (isset($_GET['width'])) {
  1446. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  1447. }
  1448. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  1449. break;
  1450. default:
  1451. # code...
  1452. break;
  1453. }
  1454. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  1455. $cachefile = $cacheDirectory . $key . '.jpg';
  1456. $cachetime = 604800;
  1457. // Serve from the cache if it is younger than $cachetime
  1458. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1459. header("Content-type: image/jpeg");
  1460. //@readfile($cachefile);
  1461. echo @curl('get', $cachefile)['content'];
  1462. exit;
  1463. }
  1464. ob_start(); // Start the output buffer
  1465. header('Content-type: image/jpeg');
  1466. //@readfile($image_src);
  1467. echo @curl('get', $image_src)['content'];
  1468. // Cache the output to a file
  1469. $fp = fopen($cachefile, 'wb');
  1470. fwrite($fp, ob_get_contents());
  1471. fclose($fp);
  1472. ob_end_flush(); // Send the output to the browser
  1473. die();
  1474. } else {
  1475. die("Invalid Request");
  1476. }
  1477. }
  1478. function cacheImage($url, $name)
  1479. {
  1480. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1481. if (!file_exists($cacheDirectory)) {
  1482. mkdir($cacheDirectory, 0777, true);
  1483. }
  1484. $cachefile = $cacheDirectory . $name . '.jpg';
  1485. copy($url, $cachefile);
  1486. }
  1487. function downloader($array)
  1488. {
  1489. switch ($array['data']['source']) {
  1490. case 'sabnzbd':
  1491. switch ($array['data']['action']) {
  1492. case 'resume':
  1493. case 'pause':
  1494. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1495. break;
  1496. default:
  1497. # code...
  1498. break;
  1499. }
  1500. break;
  1501. case 'nzbget':
  1502. break;
  1503. default:
  1504. # code...
  1505. break;
  1506. }
  1507. }
  1508. function sabnzbdAction($action = null, $target = null)
  1509. {
  1510. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1511. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1512. switch ($action) {
  1513. case 'pause':
  1514. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
  1515. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1516. break;
  1517. case 'resume':
  1518. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
  1519. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1520. break;
  1521. default:
  1522. # code...
  1523. break;
  1524. }
  1525. try {
  1526. $options = (localURL($url)) ? array('verify' => false) : array();
  1527. $response = Requests::get($url, array(), $options);
  1528. if ($response->success) {
  1529. $api['content'] = json_decode($response->body, true);
  1530. }
  1531. } catch (Requests_Exception $e) {
  1532. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1533. };
  1534. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1535. return $api;
  1536. }
  1537. }
  1538. // Deluge API isn't working ATM - will get with dev.
  1539. function delugeAction($action = null, $target = null)
  1540. {
  1541. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  1542. $url = qualifyURL($GLOBALS['delugeURL']);
  1543. try {
  1544. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1545. switch ($action) {
  1546. case 'pause':
  1547. $torrents = $deluge->pauseTorrent($target);
  1548. break;
  1549. case 'pauseAll':
  1550. $torrents = $deluge->pauseAllTorrents();
  1551. break;
  1552. case 'resume':
  1553. $torrents = $deluge->resumeTorrent($target);
  1554. break;
  1555. case 'resumeAll':
  1556. $torrents = $deluge->resumeAllTorrents();
  1557. break;
  1558. default:
  1559. # code...
  1560. break;
  1561. }
  1562. $api['content'] = $torrents;
  1563. } catch (Excecption $e) {
  1564. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1565. }
  1566. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1567. return $api;
  1568. }
  1569. return false;
  1570. }
  1571. function getOrgUsers()
  1572. {
  1573. $result = allUsers();
  1574. if (is_array($result) || is_object($result)) {
  1575. foreach ($result['users'] as $k => $v) {
  1576. $return[$v['username']] = $v['email'];
  1577. }
  1578. return $return;
  1579. }
  1580. }
  1581. function convertPlexName($user, $type)
  1582. {
  1583. $array = userList('plex');
  1584. switch ($type) {
  1585. case "username":
  1586. case "u":
  1587. $plexUser = array_search($user, $array['users']);
  1588. break;
  1589. case "id":
  1590. if (array_key_exists(strtolower($user), $array['users'])) {
  1591. $plexUser = $array['users'][strtolower($user)];
  1592. }
  1593. break;
  1594. default:
  1595. $plexUser = false;
  1596. }
  1597. return (!empty($plexUser) ? $plexUser : null);
  1598. }
  1599. function userList($type = null)
  1600. {
  1601. switch ($type) {
  1602. case 'plex':
  1603. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1604. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
  1605. try {
  1606. $headers = array(
  1607. "Accept" => "application/json",
  1608. "X-Plex-Token" => $GLOBALS['plexToken']
  1609. );
  1610. $response = Requests::get($url, $headers, array());
  1611. libxml_use_internal_errors(true);
  1612. if ($response->success) {
  1613. $libraryList = array();
  1614. $plex = simplexml_load_string($response->body);
  1615. foreach ($plex->SharedServer as $child) {
  1616. if (!empty($child['username'])) {
  1617. $username = (string)strtolower($child['username']);
  1618. $email = (string)strtolower($child['email']);
  1619. $libraryList['users'][$username] = (string)$child['id'];
  1620. $libraryList['emails'][$email] = (string)$child['id'];
  1621. $libraryList['both'][$username] = $email;
  1622. }
  1623. }
  1624. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1625. return $libraryList;
  1626. }
  1627. } catch (Requests_Exception $e) {
  1628. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1629. };
  1630. }
  1631. break;
  1632. default:
  1633. # code...
  1634. break;
  1635. }
  1636. return false;
  1637. }
  1638. function libraryList($type = null)
  1639. {
  1640. switch ($type) {
  1641. case 'plex':
  1642. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1643. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'];
  1644. try {
  1645. $headers = array(
  1646. "Accept" => "application/json",
  1647. "X-Plex-Token" => $GLOBALS['plexToken']
  1648. );
  1649. $response = Requests::get($url, $headers, array());
  1650. libxml_use_internal_errors(true);
  1651. if ($response->success) {
  1652. $libraryList = array();
  1653. $plex = simplexml_load_string($response->body);
  1654. foreach ($plex->Server->Section as $child) {
  1655. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1656. }
  1657. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1658. return $libraryList;
  1659. }
  1660. } catch (Requests_Exception $e) {
  1661. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1662. };
  1663. }
  1664. break;
  1665. default:
  1666. # code...
  1667. break;
  1668. }
  1669. return false;
  1670. }
  1671. function plexJoinAPI($array)
  1672. {
  1673. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1674. }
  1675. function plexJoin($username, $email, $password)
  1676. {
  1677. try {
  1678. $url = 'https://plex.tv/users.json';
  1679. $headers = array(
  1680. 'Accept' => 'application/json',
  1681. 'Content-Type' => 'application/x-www-form-urlencoded',
  1682. 'X-Plex-Product' => 'Organizr',
  1683. 'X-Plex-Version' => '2.0',
  1684. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1685. );
  1686. $data = array(
  1687. 'user[email]' => $email,
  1688. 'user[username]' => $username,
  1689. 'user[password]' => $password,
  1690. );
  1691. $response = Requests::post($url, $headers, $data, array());
  1692. $json = json_decode($response->body, true);
  1693. $errors = (!empty($json['errors']) ? true : false);
  1694. $success = (!empty($json['user']) ? true : false);
  1695. //Use This for later
  1696. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1697. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1698. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1699. $errorMessage = "";
  1700. if ($errors) {
  1701. if ($usernameError) {
  1702. $errorMessage .= "[Username Error: " . $usernameError . "]";
  1703. }
  1704. if ($emailError) {
  1705. $errorMessage .= "[Email Error: " . $emailError . "]";
  1706. }
  1707. if ($passwordError) {
  1708. $errorMessage .= "[Password Error: " . $passwordError . "]";
  1709. }
  1710. }
  1711. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1712. } catch (Requests_Exception $e) {
  1713. writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1714. };
  1715. return false;
  1716. }
  1717. function checkFrame($array, $url)
  1718. {
  1719. if (array_key_exists("x-frame-options", $array)) {
  1720. if ($array['x-frame-options'] == "deny") {
  1721. return false;
  1722. } elseif ($array['x-frame-options'] == "sameorgin") {
  1723. $digest = parse_url($url);
  1724. $host = (isset($digest['host']) ? $digest['host'] : '');
  1725. if (getServer() == $host) {
  1726. return true;
  1727. } else {
  1728. return false;
  1729. }
  1730. }
  1731. } else {
  1732. if (!$array) {
  1733. return false;
  1734. }
  1735. return true;
  1736. }
  1737. }
  1738. function frameTest($url)
  1739. {
  1740. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  1741. $url = qualifyURL($url);
  1742. if (checkFrame($array, $url)) {
  1743. return true;
  1744. } else {
  1745. return false;
  1746. }
  1747. }
  1748. function ping($pings)
  1749. {
  1750. if (qualifyRequest($GLOBALS['pingAuth'])) {
  1751. $type = gettype($pings);
  1752. $ping = new Ping("");
  1753. $ping->setTtl(128);
  1754. $ping->setTimeout(2);
  1755. switch ($type) {
  1756. case "array":
  1757. $results = [];
  1758. foreach ($pings as $k => $v) {
  1759. if (strpos($v, ':') !== false) {
  1760. $domain = explode(':', $v)[0];
  1761. $port = explode(':', $v)[1];
  1762. $ping->setHost($domain);
  1763. $ping->setPort($port);
  1764. $latency = $ping->ping('fsockopen');
  1765. } else {
  1766. $ping->setHost($v);
  1767. $latency = $ping->ping();
  1768. }
  1769. if ($latency || $latency === 0) {
  1770. $results[$v] = $latency;
  1771. } else {
  1772. $results[$v] = false;
  1773. }
  1774. }
  1775. break;
  1776. case "string":
  1777. if (strpos($pings, ':') !== false) {
  1778. $domain = explode(':', $pings)[0];
  1779. $port = explode(':', $pings)[1];
  1780. $ping->setHost($domain);
  1781. $ping->setPort($port);
  1782. $latency = $ping->ping('fsockopen');
  1783. } else {
  1784. $ping->setHost($pings);
  1785. $latency = $ping->ping();
  1786. }
  1787. if ($latency || $latency === 0) {
  1788. $results = $latency;
  1789. } else {
  1790. $results = false;
  1791. }
  1792. break;
  1793. }
  1794. return $results;
  1795. }
  1796. return false;
  1797. }
  1798. function guestHash($start, $end)
  1799. {
  1800. $ip = $_SERVER['REMOTE_ADDR'];
  1801. $ip = md5($ip);
  1802. return substr($ip, $start, $end);
  1803. }