organizr-functions.php 55 KB

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