organizr-functions.php 46 KB

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