organizr-functions.php 57 KB

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