organizr-functions.php 58 KB

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