organizr-functions.php 58 KB

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