organizr-functions.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  1. <?php
  2. function organizrSpecialSettings()
  3. {
  4. $refreshSearch = "Refresh";
  5. $tautulliSearch = "tautulli_token";
  6. $tautulli = array_filter($_COOKIE, function ($k) use ($tautulliSearch) {
  7. return stripos($k, $tautulliSearch) !== false;
  8. }, ARRAY_FILTER_USE_KEY);
  9. return array(
  10. 'homepage' => array(
  11. 'refresh' => array_filter($GLOBALS, function ($k) use ($refreshSearch) {
  12. return stripos($k, $refreshSearch) !== false;
  13. }, ARRAY_FILTER_USE_KEY),
  14. 'search' => array(
  15. 'enabled' => (qualifyRequest($GLOBALS['mediaSearchAuth']) && $GLOBALS['mediaSearch'] == true && $GLOBALS['plexToken']) ? true : false,
  16. 'type' => $GLOBALS['mediaSearchType'],
  17. ),
  18. 'ombi' => array(
  19. 'enabled' => (qualifyRequest($GLOBALS['homepageOmbiAuth']) && qualifyRequest($GLOBALS['homepageOmbiRequestAuth']) && $GLOBALS['homepageOmbiEnabled'] == true && $GLOBALS['ssoOmbi'] && isset($_COOKIE['Auth'])) ? true : false,
  20. 'authView' => (qualifyRequest($GLOBALS['homepageOmbiAuth'])) ? true : false,
  21. 'authRequest' => (qualifyRequest($GLOBALS['homepageOmbiRequestAuth'])) ? true : false,
  22. 'sso' => ($GLOBALS['ssoOmbi']) ? true : false,
  23. 'cookie' => (isset($_COOKIE['Auth'])) ? true : false,
  24. ),
  25. 'options' => array(
  26. 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
  27. )
  28. ),
  29. 'sso' => array(
  30. 'plex' => array(
  31. 'enabled' => ($GLOBALS['ssoPlex']) ? true : false,
  32. 'cookie' => isset($_COOKIE['mpt']) ? true : false,
  33. ),
  34. 'ombi' => array(
  35. 'enabled' => ($GLOBALS['ssoOmbi']) ? true : false,
  36. 'cookie' => isset($_COOKIE['Auth']) ? true : false,
  37. ),
  38. 'tautulli' => array(
  39. 'enabled' => ($GLOBALS['ssoTautulli']) ? true : false,
  40. 'cookie' => !empty($tautulli) ? true : false,
  41. ),
  42. )
  43. );
  44. }
  45. function wizardConfig($array)
  46. {
  47. foreach ($array['data'] as $items) {
  48. foreach ($items as $key => $value) {
  49. if ($key == 'name') {
  50. $newKey = $value;
  51. }
  52. if ($key == 'value') {
  53. $newValue = $value;
  54. }
  55. if (isset($newKey) && isset($newValue)) {
  56. $$newKey = $newValue;
  57. }
  58. }
  59. }
  60. $location = cleanDirectory($location);
  61. $dbName = $dbName . '.db';
  62. $configVersion = $GLOBALS['installedVersion'];
  63. $configArray = array(
  64. 'dbName' => $dbName,
  65. 'dbLocation' => $location,
  66. 'license' => $license,
  67. 'organizrHash' => $hashKey,
  68. 'organizrAPI' => $api,
  69. 'registrationPassword' => $registrationPassword,
  70. );
  71. // Create Config
  72. $GLOBALS['dbLocation'] = $location;
  73. $GLOBALS['dbName'] = $dbName;
  74. if (createConfig($configArray)) {
  75. // Call DB Create
  76. if (createDB($location, $dbName)) {
  77. // Add in first user
  78. if (createFirstAdmin($location, $dbName, $username, $password, $email)) {
  79. if (createToken($username, $email, gravatar($email), 'Admin', 0, $hashKey, 1)) {
  80. return true;
  81. } else {
  82. return 'token';
  83. }
  84. } else {
  85. return 'admin';
  86. }
  87. } else {
  88. return 'db';
  89. }
  90. } else {
  91. return 'config';
  92. }
  93. return false;
  94. }
  95. function register($array)
  96. {
  97. // Grab username and password from login form
  98. foreach ($array['data'] as $items) {
  99. foreach ($items as $key => $value) {
  100. if ($key == 'name') {
  101. $newKey = $value;
  102. }
  103. if ($key == 'value') {
  104. $newValue = $value;
  105. }
  106. if (isset($newKey) && isset($newValue)) {
  107. $$newKey = $newValue;
  108. }
  109. }
  110. }
  111. if ($registrationPassword == $GLOBALS['registrationPassword']) {
  112. $defaults = defaultUserGroup();
  113. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  114. if (createUser($username, $password, $defaults, $email)) {
  115. writeLog('success', 'Registration Function - A User has registered', $username);
  116. if (createToken($username, $email, gravatar($email), $defaults['group'], $defaults['group_id'], $GLOBALS['organizrHash'], 1)) {
  117. writeLoginLog($username, 'success');
  118. writeLog('success', 'Login Function - A User has logged in', $username);
  119. return true;
  120. }
  121. } else {
  122. writeLog('error', 'Registration Function - An error occured', $username);
  123. return 'username taken';
  124. }
  125. } else {
  126. writeLog('warning', 'Registration Function - Wrong Password', $username);
  127. return 'mismatch';
  128. }
  129. }
  130. function removeFile($array)
  131. {
  132. $filePath = $array['data']['path'];
  133. $fileName = $array['data']['name'];
  134. if (file_exists($filePath)) {
  135. if (unlink($filePath)) {
  136. writeLog('success', 'Log Management Function - Log: ' . $fileName . ' has been purged/deleted', 'SYSTEM');
  137. return true;
  138. } else {
  139. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' - Error Occured', 'SYSTEM');
  140. return false;
  141. }
  142. } else {
  143. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' does not exist', 'SYSTEM');
  144. return false;
  145. }
  146. }
  147. function recover($array)
  148. {
  149. $email = $array['data']['email'];
  150. $newPassword = randString(10);
  151. try {
  152. $connect = new Dibi\Connection([
  153. 'driver' => 'sqlite3',
  154. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  155. ]);
  156. $isUser = $connect->fetch('SELECT * FROM users WHERE email = ? COLLATE NOCASE', $email);
  157. if ($isUser) {
  158. $connect->query('
  159. UPDATE users SET', [
  160. 'password' => password_hash($newPassword, PASSWORD_BCRYPT)
  161. ], '
  162. WHERE email=? COLLATE NOCASE', $email);
  163. if ($GLOBALS['PHPMAILER-enabled']) {
  164. $emailTemplate = array(
  165. 'type' => 'reset',
  166. 'body' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'],
  167. 'subject' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'],
  168. 'user' => $isUser['username'],
  169. 'password' => $newPassword,
  170. 'inviteCode' => null,
  171. );
  172. $emailTemplate = phpmEmailTemplate($emailTemplate);
  173. $sendEmail = array(
  174. 'to' => $email,
  175. 'user' => $isUser['username'],
  176. 'subject' => $emailTemplate['subject'],
  177. 'body' => phpmBuildEmail($emailTemplate),
  178. );
  179. phpmSendEmail($sendEmail);
  180. }
  181. writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
  182. return true;
  183. } else {
  184. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  185. return 'an error occured';
  186. }
  187. } catch (Dibi\Exception $e) {
  188. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  189. return 'an error occured';
  190. }
  191. }
  192. function editUser($array)
  193. {
  194. if ($array['data']['username'] == '' && $array['data']['username'] == '') {
  195. return 'Username/email not set';
  196. }
  197. try {
  198. $connect = new Dibi\Connection([
  199. 'driver' => 'sqlite3',
  200. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  201. ]);
  202. if (!usernameTakenExcept($array['data']['username'], $array['data']['email'], $GLOBALS['organizrUser']['userID'])) {
  203. $connect->query('
  204. UPDATE users SET', [
  205. 'username' => $array['data']['username'],
  206. 'email' => $array['data']['email'],
  207. ], '
  208. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  209. if (!empty($array['data']['password'])) {
  210. $connect->query('
  211. UPDATE users SET', [
  212. 'password' => password_hash($array['data']['password'], PASSWORD_BCRYPT)
  213. ], '
  214. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  215. }
  216. writeLog('success', 'User Management Function - User: ' . $array['data']['username'] . '\'s info was changed', $GLOBALS['organizrUser']['username']);
  217. return true;
  218. } else {
  219. return 'Username/Email Already Taken';
  220. }
  221. } catch (Dibi\Exception $e) {
  222. writeLog('error', 'User Management Function - Error - User: ' . $array['data']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  223. return 'an error occured';
  224. }
  225. }
  226. function logout()
  227. {
  228. coookie('delete', 'organizrToken');
  229. coookie('delete', 'mpt');
  230. coookie('delete', 'Auth');
  231. $GLOBALS['organizrUser'] = false;
  232. return true;
  233. }
  234. function qualifyRequest($accessLevelNeeded)
  235. {
  236. if (getUserLevel() <= $accessLevelNeeded) {
  237. return true;
  238. } else {
  239. return false;
  240. }
  241. }
  242. function getUserLevel()
  243. {
  244. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  245. // Check token or API key
  246. // If API key, return 0 for admin
  247. if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
  248. //DO API CHECK
  249. return 0;
  250. } elseif (isset($GLOBALS['organizrUser'])) {
  251. return $GLOBALS['organizrUser']['groupID'];
  252. }
  253. // All else fails? return guest id
  254. return 999;
  255. }
  256. function organizrStatus()
  257. {
  258. $status = array();
  259. $dependenciesActive = array();
  260. $dependenciesInactive = array();
  261. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  262. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  263. foreach ($extensions as $check) {
  264. if (extension_loaded($check)) {
  265. array_push($dependenciesActive, $check);
  266. } else {
  267. array_push($dependenciesInactive, $check);
  268. }
  269. }
  270. foreach ($functions as $check) {
  271. if (function_exists($check)) {
  272. array_push($dependenciesActive, $check);
  273. } else {
  274. array_push($dependenciesInactive, $check);
  275. }
  276. }
  277. if (!file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
  278. $status['status'] = "wizard";//wizard - ok for test
  279. }
  280. if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, '7.0.0') >= 0)) {
  281. $status['status'] = "dependencies";
  282. }
  283. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  284. $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
  285. $status['minVersion'] = (version_compare(PHP_VERSION, '7.0.0') >= 0) ? 'yes' : 'no';
  286. $status['dependenciesActive'] = $dependenciesActive;
  287. $status['dependenciesInactive'] = $dependenciesInactive;
  288. $status['version'] = $GLOBALS['installedVersion'];
  289. $status['os'] = getOS();
  290. $status['php'] = phpversion();
  291. return $status;
  292. }
  293. function getSettingsMain()
  294. {
  295. return array(
  296. 'Github' => array(
  297. array(
  298. 'type' => 'select',
  299. 'name' => 'branch',
  300. 'label' => 'Branch',
  301. 'value' => $GLOBALS['branch'],
  302. 'options' => getBranches()
  303. ),
  304. array(
  305. 'type' => 'button',
  306. 'label' => 'Force Install Branch',
  307. 'class' => 'updateNow',
  308. 'icon' => 'fa fa-download',
  309. 'text' => 'Retrieve'
  310. )
  311. ),
  312. 'API' => array(
  313. array(
  314. 'type' => 'password-alt',
  315. 'name' => 'organizrAPI',
  316. 'label' => 'Organizr API',
  317. 'value' => $GLOBALS['organizrAPI']
  318. ),
  319. array(
  320. 'type' => 'button',
  321. 'label' => 'Generate New API Key',
  322. 'class' => 'newAPIKey',
  323. 'icon' => 'fa fa-refresh',
  324. 'text' => 'Generate'
  325. )
  326. ),
  327. 'Authentication' => array(
  328. array(
  329. 'type' => 'select',
  330. 'name' => 'authType',
  331. 'id' => 'authSelect',
  332. 'label' => 'Authentication Type',
  333. 'value' => $GLOBALS['authType'],
  334. 'options' => getAuthTypes()
  335. ),
  336. array(
  337. 'type' => 'select',
  338. 'name' => 'authBackend',
  339. 'id' => 'authBackendSelect',
  340. 'label' => 'Authentication Backend',
  341. 'class' => 'backendAuth switchAuth',
  342. 'value' => $GLOBALS['authBackend'],
  343. 'options' => getAuthBackends()
  344. ),
  345. array(
  346. 'type' => 'password-alt',
  347. 'name' => 'plexToken',
  348. 'class' => 'plexAuth switchAuth',
  349. 'label' => 'Plex Token',
  350. 'value' => $GLOBALS['plexToken'],
  351. 'placeholder' => 'Use Get Token Button'
  352. ),
  353. array(
  354. 'type' => 'button',
  355. 'label' => 'Get Plex Token',
  356. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  357. 'icon' => 'fa fa-ticket',
  358. 'text' => 'Retrieve',
  359. 'href' => '#auth-plex-token-form',
  360. 'attr' => 'data-effect="mfp-3d-unfold"'
  361. ),
  362. array(
  363. 'type' => 'password-alt',
  364. 'name' => 'plexID',
  365. 'class' => 'plexAuth switchAuth',
  366. 'label' => 'Plex Machine',
  367. 'value' => $GLOBALS['plexID'],
  368. 'placeholder' => 'Use Get Plex Machine Button'
  369. ),
  370. array(
  371. 'type' => 'button',
  372. 'label' => 'Get Plex Machine',
  373. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  374. 'icon' => 'fa fa-id-badge',
  375. 'text' => 'Retrieve',
  376. 'href' => '#auth-plex-machine-form',
  377. 'attr' => 'data-effect="mfp-3d-unfold"'
  378. ),
  379. array(
  380. 'type' => 'input',
  381. 'name' => 'authBackendHost',
  382. 'class' => 'ldapAuth ftpAuth switchAuth',
  383. 'label' => 'Host Address',
  384. 'value' => $GLOBALS['authBackendHost'],
  385. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  386. ),
  387. array(
  388. 'type' => 'input',
  389. 'name' => 'authBaseDN',
  390. 'class' => 'ldapAuth switchAuth',
  391. 'label' => 'Host Base DN',
  392. 'value' => $GLOBALS['authBaseDN'],
  393. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  394. ),
  395. array(
  396. 'type' => 'input',
  397. 'name' => 'embyURL',
  398. 'class' => 'embyAuth switchAuth',
  399. 'label' => 'Emby URL',
  400. 'value' => $GLOBALS['embyURL'],
  401. 'placeholder' => 'http(s)://hostname:port'
  402. ),
  403. array(
  404. 'type' => 'password-alt',
  405. 'name' => 'embyToken',
  406. 'class' => 'embyAuth switchAuth',
  407. 'label' => 'Emby Token',
  408. 'value' => $GLOBALS['embyToken'],
  409. 'placeholder' => ''
  410. )
  411. /*array(
  412. 'type' => 'button',
  413. 'label' => 'Send Test',
  414. 'class' => 'phpmSendTestEmail',
  415. 'icon' => 'fa fa-paper-plane',
  416. 'text' => 'Send'
  417. )*/
  418. ),
  419. 'Misc' => array(
  420. array(
  421. 'type' => 'password-alt',
  422. 'name' => 'registrationPassword',
  423. 'label' => 'Registration Password',
  424. 'value' => $GLOBALS['registrationPassword'],
  425. ),
  426. array(
  427. 'type' => 'switch',
  428. 'name' => 'hideRegistration',
  429. 'label' => 'Hide Registration',
  430. 'value' => $GLOBALS['hideRegistration']
  431. )
  432. ),
  433. 'Ping' => array(
  434. array(
  435. 'type' => 'select',
  436. 'name' => 'pingAuth',
  437. 'label' => 'Minimum Authentication',
  438. 'value' => $GLOBALS['pingAuth'],
  439. 'options' => groupSelect()
  440. ),
  441. array(
  442. 'type' => 'select',
  443. 'name' => 'adminPingRefresh',
  444. 'label' => 'Admin Refresh Seconds',
  445. 'value' => $GLOBALS['adminPingRefresh'],
  446. 'options' => optionTime()
  447. ),
  448. array(
  449. 'type' => 'select',
  450. 'name' => 'otherPingRefresh',
  451. 'label' => 'Everyone Refresh Seconds',
  452. 'value' => $GLOBALS['otherPingRefresh'],
  453. 'options' => optionTime()
  454. ),
  455. )
  456. );
  457. }
  458. function getSSO()
  459. {
  460. return array(
  461. 'Plex' => array(
  462. array(
  463. 'type' => 'password-alt',
  464. 'name' => 'plexToken',
  465. 'label' => 'Plex Token',
  466. 'value' => $GLOBALS['plexToken'],
  467. 'placeholder' => 'Use Get Token Button'
  468. ),
  469. array(
  470. 'type' => 'button',
  471. 'label' => 'Get Plex Token',
  472. 'class' => 'popup-with-form getPlexTokenSSO',
  473. 'icon' => 'fa fa-ticket',
  474. 'text' => 'Retrieve',
  475. 'href' => '#sso-plex-token-form',
  476. 'attr' => 'data-effect="mfp-3d-unfold"'
  477. ),
  478. array(
  479. 'type' => 'password-alt',
  480. 'name' => 'plexID',
  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 getPlexMachineSSO',
  489. 'icon' => 'fa fa-id-badge',
  490. 'text' => 'Retrieve',
  491. 'href' => '#sso-plex-machine-form',
  492. 'attr' => 'data-effect="mfp-3d-unfold"'
  493. ),
  494. array(
  495. 'type' => 'input',
  496. 'name' => 'plexAdmin',
  497. 'label' => 'Admin Username',
  498. 'value' => $GLOBALS['plexAdmin'],
  499. 'placeholder' => 'Admin username for Plex'
  500. ),
  501. array(
  502. 'type' => 'blank',
  503. 'label' => ''
  504. ),
  505. array(
  506. 'type' => 'html',
  507. 'label' => 'Plex Note',
  508. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  509. ),
  510. array(
  511. 'type' => 'switch',
  512. 'name' => 'ssoPlex',
  513. 'label' => 'Enable',
  514. 'value' => $GLOBALS['ssoPlex']
  515. )
  516. ),
  517. 'Ombi' => array(
  518. array(
  519. 'type' => 'input',
  520. 'name' => 'ombiURL',
  521. 'label' => 'Ombi URL',
  522. 'value' => $GLOBALS['ombiURL'],
  523. 'placeholder' => 'http(s)://hostname:port'
  524. ),
  525. array(
  526. 'type' => 'switch',
  527. 'name' => 'ssoOmbi',
  528. 'label' => 'Enable',
  529. 'value' => $GLOBALS['ssoOmbi']
  530. )
  531. ),
  532. 'Tautulli' => array(
  533. array(
  534. 'type' => 'input',
  535. 'name' => 'tautulliURL',
  536. 'label' => 'Tautulli URL',
  537. 'value' => $GLOBALS['tautulliURL'],
  538. 'placeholder' => 'http(s)://hostname:port'
  539. ),
  540. array(
  541. 'type' => 'switch',
  542. 'name' => 'ssoTautulli',
  543. 'label' => 'Enable',
  544. 'value' => $GLOBALS['ssoTautulli']
  545. )
  546. )
  547. );
  548. }
  549. function loadAppearance()
  550. {
  551. $appearance = array();
  552. $appearance['logo'] = $GLOBALS['logo'];
  553. $appearance['title'] = $GLOBALS['title'];
  554. $appearance['useLogo'] = $GLOBALS['useLogo'];
  555. $appearance['headerColor'] = $GLOBALS['headerColor'];
  556. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  557. $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
  558. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  559. $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
  560. $appearance['accentColor'] = $GLOBALS['accentColor'];
  561. $appearance['accentTextColor'] = $GLOBALS['accentTextColor'];
  562. $appearance['buttonColor'] = $GLOBALS['buttonColor'];
  563. $appearance['buttonTextColor'] = $GLOBALS['buttonTextColor'];
  564. $appearance['buttonTextHoverColor'] = $GLOBALS['buttonTextHoverColor'];
  565. $appearance['buttonHoverColor'] = $GLOBALS['buttonHoverColor'];
  566. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  567. $appearance['customCss'] = $GLOBALS['customCss'];
  568. return $appearance;
  569. }
  570. function getCustomizeAppearance()
  571. {
  572. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  573. return array(
  574. 'Top Bar' => array(
  575. array(
  576. 'type' => 'input',
  577. 'name' => 'logo',
  578. 'label' => 'Logo',
  579. 'value' => $GLOBALS['logo']
  580. ),
  581. array(
  582. 'type' => 'input',
  583. 'name' => 'title',
  584. 'label' => 'Title',
  585. 'value' => $GLOBALS['title']
  586. ),
  587. array(
  588. 'type' => 'switch',
  589. 'name' => 'useLogo',
  590. 'label' => 'Use Logo instead of Title',
  591. 'value' => $GLOBALS['useLogo']
  592. )
  593. ),
  594. 'Login Page' => array(
  595. array(
  596. 'type' => 'input',
  597. 'name' => 'loginWallpaper',
  598. 'label' => 'Login Wallpaper',
  599. 'value' => $GLOBALS['loginWallpaper']
  600. )
  601. ),
  602. 'Options' => array(
  603. array(
  604. 'type' => 'switch',
  605. 'name' => 'alternateHomepageHeaders',
  606. 'label' => 'Alternate Homepage Titles',
  607. 'value' => $GLOBALS['alternateHomepageHeaders']
  608. )
  609. ),
  610. 'Colors & Themes' => array(
  611. array(
  612. 'type' => 'html',
  613. 'override' => 12,
  614. 'label' => 'Custom CSS [Can replace colors from above]',
  615. 'html' => '
  616. <div class="row">
  617. <div class="col-lg-12">
  618. <div class="panel panel-info">
  619. <div class="panel-heading">
  620. <span lang="en">Notice</span>
  621. </div>
  622. <div class="panel-wrapper collapse in" aria-expanded="true">
  623. <div class="panel-body">
  624. <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
  625. </div>
  626. </div>
  627. </div>
  628. </div>
  629. </div>
  630. ',
  631. ),
  632. array(
  633. 'type' => 'blank',
  634. 'label' => ''
  635. ),
  636. array(
  637. 'type' => 'input',
  638. 'name' => 'headerColor',
  639. 'label' => 'Nav Bar Color',
  640. 'value' => $GLOBALS['headerColor'],
  641. 'class' => 'pick-a-color',
  642. 'attr' => 'data-original="' . $GLOBALS['headerColor'] . '"'
  643. ),
  644. array(
  645. 'type' => 'input',
  646. 'name' => 'headerTextColor',
  647. 'label' => 'Nav Bar Text Color',
  648. 'value' => $GLOBALS['headerTextColor'],
  649. 'class' => 'pick-a-color',
  650. 'attr' => 'data-original="' . $GLOBALS['headerTextColor'] . '"'
  651. ),
  652. array(
  653. 'type' => 'input',
  654. 'name' => 'sidebarColor',
  655. 'label' => 'Side Bar Color',
  656. 'value' => $GLOBALS['sidebarColor'],
  657. 'class' => 'pick-a-color',
  658. 'attr' => 'data-original="' . $GLOBALS['sidebarColor'] . '"'
  659. ),
  660. array(
  661. 'type' => 'input',
  662. 'name' => 'sidebarTextColor',
  663. 'label' => 'Side Bar Text Color',
  664. 'value' => $GLOBALS['sidebarTextColor'],
  665. 'class' => 'pick-a-color',
  666. 'attr' => 'data-original="' . $GLOBALS['sidebarTextColor'] . '"'
  667. ),
  668. array(
  669. 'type' => 'input',
  670. 'name' => 'accentColor',
  671. 'label' => 'Accent Color',
  672. 'value' => $GLOBALS['accentColor'],
  673. 'class' => 'pick-a-color',
  674. 'attr' => 'data-original="' . $GLOBALS['accentColor'] . '"'
  675. ),
  676. array(
  677. 'type' => 'input',
  678. 'name' => 'accentTextColor',
  679. 'label' => 'Accent Text Color',
  680. 'value' => $GLOBALS['accentTextColor'],
  681. 'class' => 'pick-a-color',
  682. 'attr' => 'data-original="' . $GLOBALS['accentTextColor'] . '"'
  683. ),
  684. array(
  685. 'type' => 'input',
  686. 'name' => 'buttonColor',
  687. 'label' => 'Button Color',
  688. 'value' => $GLOBALS['buttonColor'],
  689. 'class' => 'pick-a-color',
  690. 'attr' => 'data-original="' . $GLOBALS['buttonColor'] . '"'
  691. ),
  692. array(
  693. 'type' => 'input',
  694. 'name' => 'buttonTextColor',
  695. 'label' => 'Button Text Color',
  696. 'value' => $GLOBALS['buttonTextColor'],
  697. 'class' => 'pick-a-color',
  698. 'attr' => 'data-original="' . $GLOBALS['buttonTextColor'] . '"'
  699. ),/*
  700. array(
  701. 'type' => 'input',
  702. 'name' => 'buttonHoverColor',
  703. 'label' => 'Button Hover Color',
  704. 'value' => $GLOBALS['buttonHoverColor'],
  705. 'class' => 'pick-a-color',
  706. 'disabled' => true
  707. ),
  708. array(
  709. 'type' => 'input',
  710. 'name' => 'buttonTextHoverColor',
  711. 'label' => 'Button Hover Text Color',
  712. 'value' => $GLOBALS['buttonTextHoverColor'],
  713. 'class' => 'pick-a-color',
  714. 'disabled' => true
  715. ),*/
  716. array(
  717. 'type' => 'select',
  718. 'name' => 'theme',
  719. 'label' => 'Theme',
  720. 'class' => 'themeChanger',
  721. 'value' => $GLOBALS['theme'],
  722. 'options' => getThemes()
  723. ),
  724. array(
  725. 'type' => 'select',
  726. 'name' => 'style',
  727. 'label' => 'Style',
  728. 'class' => 'styleChanger',
  729. 'value' => $GLOBALS['style'],
  730. 'options' => array(
  731. array(
  732. 'name' => 'Light',
  733. 'value' => 'light'
  734. ),
  735. array(
  736. 'name' => 'Dark',
  737. 'value' => 'dark'
  738. ),
  739. array(
  740. 'name' => 'Horizontal',
  741. 'value' => 'horizontal'
  742. )
  743. )
  744. )
  745. ),
  746. 'FavIcon' => array(
  747. array(
  748. 'type' => 'textbox',
  749. 'name' => 'favIcon',
  750. 'class' => '',
  751. 'label' => 'Fav Icon Code',
  752. 'value' => $GLOBALS['favIcon'],
  753. 'placeholder' => 'Paste Contents from https://realfavicongenerator.net/',
  754. 'attr' => 'rows="10"',
  755. ),
  756. array(
  757. 'type' => 'html',
  758. 'label' => 'Instructions',
  759. 'html' => '
  760. <div class="panel panel-default">
  761. <div class="panel-heading">
  762. <a href="https://realfavicongenerator.net/" target="_blank"><span class="label label-info m-l-5">Visit FavIcon Site</span></a>
  763. </div>
  764. <div class="panel-wrapper collapse in">
  765. <div class="panel-body">
  766. <ul class="list-icons">
  767. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Select your Favicon picture"</li>
  768. <li lang="en"><i class="fa fa-caret-right text-info"></i> Choose your image to use</li>
  769. <li lang="en"><i class="fa fa-caret-right text-info"></i> Edit settings to your liking</li>
  770. <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>
  771. <li lang="en"><i class="fa fa-caret-right text-info"></i> Enter this path <code>plugins/images/faviconCustom</code></li>
  772. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Generate your Favicons and HTML code"</li>
  773. <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>
  774. <li lang="en"><i class="fa fa-caret-right text-info"></i> Copy code and paste inside left box</li>
  775. </ul>
  776. </div>
  777. </div>
  778. </div>
  779. '
  780. ),
  781. ),
  782. 'Custom CSS' => array(
  783. array(
  784. 'type' => 'html',
  785. 'override' => 12,
  786. 'label' => 'Custom CSS [Can replace colors from above]',
  787. '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>'
  788. ),
  789. array(
  790. 'type' => 'textbox',
  791. 'name' => 'customCss',
  792. 'class' => 'hidden cssTextarea',
  793. 'label' => '',
  794. 'value' => $GLOBALS['customCss'],
  795. 'placeholder' => 'No <style> tags needed',
  796. 'attr' => 'rows="10"',
  797. ),
  798. )
  799. );
  800. }
  801. }
  802. function editAppearance($array)
  803. {
  804. switch ($array['data']['value']) {
  805. case 'true':
  806. $array['data']['value'] = (bool)true;
  807. break;
  808. case 'false':
  809. $array['data']['value'] = (bool)false;
  810. break;
  811. default:
  812. $array['data']['value'] = $array['data']['value'];
  813. }
  814. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  815. switch ($array['data']['action']) {
  816. case 'editCustomizeAppearance':
  817. $newItem = array(
  818. $array['data']['name'] => $array['data']['value']
  819. );
  820. return (updateConfig($newItem)) ? true : false;
  821. break;
  822. default:
  823. # code...
  824. break;
  825. }
  826. }
  827. function updateConfigMultiple($array)
  828. {
  829. return (updateConfig($array['data']['payload'])) ? true : false;
  830. }
  831. function updateConfigMultipleForm($array)
  832. {
  833. $newItem = array();
  834. foreach ($array['data']['payload'] as $k => $v) {
  835. switch ($v['value']) {
  836. case 'true':
  837. $v['value'] = (bool)true;
  838. break;
  839. case 'false':
  840. $v['value'] = (bool)false;
  841. break;
  842. default:
  843. $v['value'] = $v['value'];
  844. }
  845. // Hash
  846. if ($v['type'] == 'password') {
  847. if (strpos($v['value'], '==') !== false) {
  848. $v['value'] = $v['value'];
  849. } else {
  850. $v['value'] = encrypt($v['value']);
  851. }
  852. }
  853. $newItem[$v['name']] = $v['value'];
  854. }
  855. //return $newItem;
  856. return (updateConfig($newItem)) ? true : false;
  857. }
  858. function updateConfigItem($array)
  859. {
  860. switch ($array['data']['value']) {
  861. case 'true':
  862. $array['data']['value'] = (bool)true;
  863. break;
  864. case 'false':
  865. $array['data']['value'] = (bool)false;
  866. break;
  867. default:
  868. $array['data']['value'] = $array['data']['value'];
  869. }
  870. // Hash
  871. if ($array['data']['type'] == 'password') {
  872. $array['data']['value'] = encrypt($array['data']['value']);
  873. }
  874. $newItem = array(
  875. $array['data']['name'] => $array['data']['value']
  876. );
  877. return (updateConfig($newItem)) ? true : false;
  878. }
  879. function getPlugins()
  880. {
  881. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  882. $pluginList = [];
  883. foreach ($GLOBALS['plugins'] as $plugin) {
  884. foreach ($plugin as $key => $value) {
  885. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  886. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
  887. $pluginList[$key] = $plugin[$key];
  888. }
  889. }
  890. }
  891. return $pluginList;
  892. }
  893. return false;
  894. }
  895. function editPlugins($array)
  896. {
  897. switch ($array['data']['action']) {
  898. case 'enable':
  899. $newItem = array(
  900. $array['data']['configName'] => true
  901. );
  902. writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  903. return (updateConfig($newItem)) ? true : false;
  904. break;
  905. case 'disable':
  906. $newItem = array(
  907. $array['data']['configName'] => false
  908. );
  909. writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  910. return (updateConfig($newItem)) ? true : false;
  911. break;
  912. default:
  913. # code...
  914. break;
  915. }
  916. }
  917. function auth()
  918. {
  919. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  920. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  921. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  922. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  923. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  924. $currentIP = userIP();
  925. if (isset($GLOBALS['organizrUser'])) {
  926. $currentUser = $GLOBALS['organizrUser']['username'];
  927. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  928. } else {
  929. $currentUser = 'Guest';
  930. $currentGroup = getUserLevel();
  931. }
  932. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  933. if ($whitelist) {
  934. if (in_array($currentIP, arrayIP($whitelist))) {
  935. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  936. }
  937. }
  938. if ($blacklist) {
  939. if (in_array($currentIP, arrayIP($blacklist))) {
  940. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  941. }
  942. }
  943. if ($group !== null) {
  944. if (qualifyRequest($group)) {
  945. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  946. } else {
  947. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  948. }
  949. } else {
  950. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  951. }
  952. }
  953. function logoOrText()
  954. {
  955. if ($GLOBALS['useLogo'] == false) {
  956. return '<h1>' . $GLOBALS['title'] . '</h1>';
  957. } else {
  958. return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
  959. }
  960. }
  961. function showLogin()
  962. {
  963. if ($GLOBALS['hideRegistration'] == false) {
  964. 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>';
  965. }
  966. }
  967. function getImages()
  968. {
  969. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  970. $path = 'plugins/images/tabs/';
  971. $images = scandir($dirname);
  972. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  973. $allIcons = array();
  974. foreach ($images as $image) {
  975. if (!in_array($image, $ignore)) {
  976. $allIcons[] = $path . $image;
  977. }
  978. }
  979. return $allIcons;
  980. }
  981. function editImages()
  982. {
  983. $array = array();
  984. $postCheck = array_filter($_POST);
  985. $filesCheck = array_filter($_FILES);
  986. if (!empty($postCheck)) {
  987. if ($_POST['data']['action'] == 'deleteImage') {
  988. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
  989. writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
  990. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
  991. }
  992. }
  993. }
  994. if (!empty($filesCheck)) {
  995. ini_set('upload_max_filesize', '10M');
  996. ini_set('post_max_size', '10M');
  997. $tempFile = $_FILES['file']['tmp_name'];
  998. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  999. $targetFile = $targetPath . $_FILES['file']['name'];
  1000. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  1001. }
  1002. return false;
  1003. }
  1004. function getThemes()
  1005. {
  1006. $themes = array();
  1007. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  1008. $themes[] = array(
  1009. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1010. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  1011. );
  1012. }
  1013. return $themes;
  1014. }
  1015. function getBranches()
  1016. {
  1017. return array(
  1018. array(
  1019. 'name' => 'Develop',
  1020. 'value' => 'v2-develop'
  1021. ),
  1022. array(
  1023. 'name' => 'Master',
  1024. 'value' => 'v2-master'
  1025. )
  1026. );
  1027. }
  1028. function getAuthTypes()
  1029. {
  1030. return array(
  1031. array(
  1032. 'name' => 'Organizr DB',
  1033. 'value' => 'internal'
  1034. ),
  1035. array(
  1036. 'name' => 'Organizr DB + Backend',
  1037. 'value' => 'both'
  1038. ),
  1039. array(
  1040. 'name' => 'Backend Only',
  1041. 'value' => 'external'
  1042. )
  1043. );
  1044. }
  1045. function getAuthBackends()
  1046. {
  1047. $backendOptions = array();
  1048. $backendOptions[] = array(
  1049. 'name' => 'Choose Backend',
  1050. 'value' => false,
  1051. 'disabled' => true
  1052. );
  1053. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  1054. return strpos($v, 'plugin_auth_') === 0;
  1055. }) as $value) {
  1056. $name = str_replace('plugin_auth_', '', $value);
  1057. if (strpos($name, 'disabled') === false) {
  1058. $backendOptions[] = array(
  1059. 'name' => ucwords(str_replace('_', ' ', $name)),
  1060. 'value' => $name
  1061. );
  1062. } else {
  1063. $backendOptions[] = array(
  1064. 'name' => $value(),
  1065. 'value' => 'none',
  1066. 'disabled' => true,
  1067. );
  1068. }
  1069. }
  1070. ksort($backendOptions);
  1071. return $backendOptions;
  1072. }
  1073. function wizardPath($array)
  1074. {
  1075. $path = $array['data']['path'];
  1076. if (file_exists($path)) {
  1077. if (is_writable($path)) {
  1078. return true;
  1079. }
  1080. } else {
  1081. if (is_writable(dirname($path, 1))) {
  1082. if (mkdir($path, 0760, true)) {
  1083. return true;
  1084. }
  1085. }
  1086. }
  1087. return 'permissions';
  1088. }
  1089. function groupSelect()
  1090. {
  1091. $groups = allGroups();
  1092. $select = array();
  1093. foreach ($groups as $key => $value) {
  1094. $select[] = array(
  1095. 'name' => $value['group'],
  1096. 'value' => $value['group_id']
  1097. );
  1098. }
  1099. return $select;
  1100. }
  1101. function getImage()
  1102. {
  1103. $refresh = false;
  1104. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1105. if (!file_exists($cacheDirectory)) {
  1106. mkdir($cacheDirectory, 0777, true);
  1107. }
  1108. @$image_url = $_GET['img'];
  1109. @$key = $_GET['key'];
  1110. @$image_height = $_GET['height'];
  1111. @$image_width = $_GET['width'];
  1112. @$source = $_GET['source'];
  1113. @$itemType = $_GET['type'];
  1114. if (strpos($key, '$') !== false) {
  1115. $key = explode('$', $key)[0];
  1116. $refresh = true;
  1117. }
  1118. switch ($source) {
  1119. case 'plex':
  1120. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  1121. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  1122. break;
  1123. case 'emby':
  1124. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  1125. $imgParams = array();
  1126. if (isset($_GET['height'])) {
  1127. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  1128. }
  1129. if (isset($_GET['width'])) {
  1130. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  1131. }
  1132. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  1133. break;
  1134. default:
  1135. # code...
  1136. break;
  1137. }
  1138. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  1139. $cachefile = $cacheDirectory . $key . '.jpg';
  1140. $cachetime = 604800;
  1141. // Serve from the cache if it is younger than $cachetime
  1142. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1143. header("Content-type: image/jpeg");
  1144. //@readfile($cachefile);
  1145. echo @curl('get', $cachefile)['content'];
  1146. exit;
  1147. }
  1148. ob_start(); // Start the output buffer
  1149. header('Content-type: image/jpeg');
  1150. //@readfile($image_src);
  1151. echo @curl('get', $image_src)['content'];
  1152. // Cache the output to a file
  1153. $fp = fopen($cachefile, 'wb');
  1154. fwrite($fp, ob_get_contents());
  1155. fclose($fp);
  1156. ob_end_flush(); // Send the output to the browser
  1157. die();
  1158. } else {
  1159. die("Invalid Request");
  1160. }
  1161. }
  1162. function cacheImage($url, $name)
  1163. {
  1164. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1165. if (!file_exists($cacheDirectory)) {
  1166. mkdir($cacheDirectory, 0777, true);
  1167. }
  1168. $cachefile = $cacheDirectory . $name . '.jpg';
  1169. copy($url, $cachefile);
  1170. }
  1171. function downloader($array)
  1172. {
  1173. switch ($array['data']['source']) {
  1174. case 'sabnzbd':
  1175. switch ($array['data']['action']) {
  1176. case 'resume':
  1177. case 'pause':
  1178. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1179. break;
  1180. default:
  1181. # code...
  1182. break;
  1183. }
  1184. break;
  1185. case 'nzbget':
  1186. break;
  1187. default:
  1188. # code...
  1189. break;
  1190. }
  1191. }
  1192. function sabnzbdAction($action = null, $target = null)
  1193. {
  1194. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1195. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1196. switch ($action) {
  1197. case 'pause':
  1198. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
  1199. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1200. break;
  1201. case 'resume':
  1202. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
  1203. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1204. break;
  1205. default:
  1206. # code...
  1207. break;
  1208. }
  1209. try {
  1210. $options = (localURL($url)) ? array('verify' => false) : array();
  1211. $response = Requests::get($url, array(), $options);
  1212. if ($response->success) {
  1213. $api['content'] = json_decode($response->body, true);
  1214. }
  1215. } catch (Requests_Exception $e) {
  1216. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1217. };
  1218. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1219. return $api;
  1220. }
  1221. }
  1222. // Deluge API isn't working ATM - will get with dev.
  1223. function delugeAction($action = null, $target = null)
  1224. {
  1225. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  1226. $url = qualifyURL($GLOBALS['delugeURL']);
  1227. try {
  1228. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1229. switch ($action) {
  1230. case 'pause':
  1231. $torrents = $deluge->pauseTorrent($target);
  1232. break;
  1233. case 'pauseAll':
  1234. $torrents = $deluge->pauseAllTorrents();
  1235. break;
  1236. case 'resume':
  1237. $torrents = $deluge->resumeTorrent($target);
  1238. break;
  1239. case 'resumeAll':
  1240. $torrents = $deluge->resumeAllTorrents();
  1241. break;
  1242. default:
  1243. # code...
  1244. break;
  1245. }
  1246. $api['content'] = $torrents;
  1247. } catch (Excecption $e) {
  1248. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1249. }
  1250. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1251. return $api;
  1252. }
  1253. return false;
  1254. }
  1255. function getOrgUsers()
  1256. {
  1257. $result = allUsers();
  1258. if (is_array($result) || is_object($result)) {
  1259. foreach ($result['users'] as $k => $v) {
  1260. $return[$v['username']] = $v['email'];
  1261. }
  1262. return $return;
  1263. }
  1264. }
  1265. function convertPlexName($user, $type)
  1266. {
  1267. $array = libraryList('plex');
  1268. switch ($type) {
  1269. case "username":
  1270. case "u":
  1271. $plexUser = array_search($user, $array['users']);
  1272. break;
  1273. case "id":
  1274. if (array_key_exists(strtolower($user), $array['users'])) {
  1275. $plexUser = $array['users'][strtolower($user)];
  1276. }
  1277. break;
  1278. default:
  1279. $plexUser = false;
  1280. }
  1281. return (!empty($plexUser) ? $plexUser : null);
  1282. }
  1283. function libraryList($type = null)
  1284. {
  1285. switch ($type) {
  1286. case 'plex':
  1287. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1288. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
  1289. try {
  1290. $headers = array(
  1291. "Accept" => "application/json",
  1292. "X-Plex-Token" => $GLOBALS['plexToken']
  1293. );
  1294. $response = Requests::get($url, $headers, array());
  1295. libxml_use_internal_errors(true);
  1296. if ($response->success) {
  1297. $libraryList = array();
  1298. $plex = simplexml_load_string($response->body);
  1299. foreach ($plex->SharedServer->Section as $child) {
  1300. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1301. }
  1302. foreach ($plex->SharedServer as $child) {
  1303. if (!empty($child['username'])) {
  1304. $username = (string)strtolower($child['username']);
  1305. $email = (string)strtolower($child['email']);
  1306. $libraryList['users'][$username] = (string)$child['id'];
  1307. $libraryList['emails'][$email] = (string)$child['id'];
  1308. $libraryList['both'][$username] = $email;
  1309. }
  1310. }
  1311. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1312. return $libraryList;
  1313. }
  1314. } catch (Requests_Exception $e) {
  1315. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1316. };
  1317. }
  1318. break;
  1319. default:
  1320. # code...
  1321. break;
  1322. }
  1323. return false;
  1324. }
  1325. function plexJoinAPI($array)
  1326. {
  1327. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1328. }
  1329. function plexJoin($username, $email, $password)
  1330. {
  1331. try {
  1332. $url = 'https://plex.tv/users.json';
  1333. $headers = array(
  1334. 'Accept' => 'application/json',
  1335. 'Content-Type' => 'application/x-www-form-urlencoded',
  1336. 'X-Plex-Product' => 'Organizr',
  1337. 'X-Plex-Version' => '2.0',
  1338. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1339. );
  1340. $data = array(
  1341. 'user[email]' => $email,
  1342. 'user[username]' => $username,
  1343. 'user[password]' => $password,
  1344. );
  1345. $response = Requests::post($url, $headers, $data, array());
  1346. $json = json_decode($response->body, true);
  1347. $errors = (!empty($json['errors']) ? true : false);
  1348. $success = (!empty($json['user']) ? true : false);
  1349. //Use This for later
  1350. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1351. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1352. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1353. $errorMessage = "";
  1354. if ($errors) {
  1355. if ($usernameError) {
  1356. $errorMessage .= "[Username Error: " . $usernameError . "]";
  1357. }
  1358. if ($emailError) {
  1359. $errorMessage .= "[Email Error: " . $emailError . "]";
  1360. }
  1361. if ($passwordError) {
  1362. $errorMessage .= "[Password Error: " . $passwordError . "]";
  1363. }
  1364. }
  1365. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1366. } catch (Requests_Exception $e) {
  1367. writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1368. };
  1369. return false;
  1370. }
  1371. function checkFrame($array, $url)
  1372. {
  1373. if (array_key_exists("x-frame-options", $array)) {
  1374. if ($array['x-frame-options'] == "deny") {
  1375. return false;
  1376. } elseif ($array['x-frame-options'] == "sameorgin") {
  1377. $digest = parse_url($url);
  1378. $host = (isset($digest['host']) ? $digest['host'] : '');
  1379. if (getServer() == $host) {
  1380. return true;
  1381. } else {
  1382. return false;
  1383. }
  1384. }
  1385. } else {
  1386. if (!$array) {
  1387. return false;
  1388. }
  1389. return true;
  1390. }
  1391. }
  1392. function frameTest($url)
  1393. {
  1394. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  1395. $url = qualifyURL($url);
  1396. if (checkFrame($array, $url)) {
  1397. return true;
  1398. } else {
  1399. return false;
  1400. }
  1401. }
  1402. function ping($pings)
  1403. {
  1404. if (qualifyRequest($GLOBALS['pingAuth'])) {
  1405. $type = gettype($pings);
  1406. $ping = new Ping("");
  1407. $ping->setTtl(128);
  1408. $ping->setTimeout(2);
  1409. switch ($type) {
  1410. case "array":
  1411. $results = [];
  1412. foreach ($pings as $k => $v) {
  1413. if (strpos($v, ':') !== false) {
  1414. $domain = explode(':', $v)[0];
  1415. $port = explode(':', $v)[1];
  1416. $ping->setHost($domain);
  1417. $ping->setPort($port);
  1418. $latency = $ping->ping('fsockopen');
  1419. } else {
  1420. $ping->setHost($v);
  1421. $latency = $ping->ping();
  1422. }
  1423. if ($latency || $latency === 0) {
  1424. $results[$v] = $latency;
  1425. } else {
  1426. $results[$v] = false;
  1427. }
  1428. }
  1429. break;
  1430. case "string":
  1431. if (strpos($pings, ':') !== false) {
  1432. $domain = explode(':', $pings)[0];
  1433. $port = explode(':', $pings)[1];
  1434. $ping->setHost($domain);
  1435. $ping->setPort($port);
  1436. $latency = $ping->ping('fsockopen');
  1437. } else {
  1438. $ping->setHost($pings);
  1439. $latency = $ping->ping();
  1440. }
  1441. if ($latency || $latency === 0) {
  1442. $results = $latency;
  1443. } else {
  1444. $results = false;
  1445. }
  1446. break;
  1447. }
  1448. return $results;
  1449. }
  1450. return false;
  1451. }