organizr-functions.php 57 KB

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