organizr-functions.php 56 KB

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