organizr-functions.php 54 KB

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