organizr-functions.php 59 KB

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