organizr-functions.php 56 KB

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