organizr-functions.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  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. 'label' => 'Type',
  799. 'value' => $GLOBALS['notificationBackbone'],
  800. 'options' => optionNotificationTypes()
  801. ),
  802. array(
  803. 'type' => 'select',
  804. 'name' => 'notificationPosition',
  805. 'label' => 'Position',
  806. 'value' => $GLOBALS['notificationPosition'],
  807. 'options' => optionNotificationPositions()
  808. ),
  809. ),
  810. 'FavIcon' => array(
  811. array(
  812. 'type' => 'textbox',
  813. 'name' => 'favIcon',
  814. 'class' => '',
  815. 'label' => 'Fav Icon Code',
  816. 'value' => $GLOBALS['favIcon'],
  817. 'placeholder' => 'Paste Contents from https://realfavicongenerator.net/',
  818. 'attr' => 'rows="10"',
  819. ),
  820. array(
  821. 'type' => 'html',
  822. 'label' => 'Instructions',
  823. 'html' => '
  824. <div class="panel panel-default">
  825. <div class="panel-heading">
  826. <a href="https://realfavicongenerator.net/" target="_blank"><span class="label label-info m-l-5">Visit FavIcon Site</span></a>
  827. </div>
  828. <div class="panel-wrapper collapse in">
  829. <div class="panel-body">
  830. <ul class="list-icons">
  831. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Select your Favicon picture"</li>
  832. <li lang="en"><i class="fa fa-caret-right text-info"></i> Choose your image to use</li>
  833. <li lang="en"><i class="fa fa-caret-right text-info"></i> Edit settings to your liking</li>
  834. <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>
  835. <li lang="en"><i class="fa fa-caret-right text-info"></i> Enter this path <code>plugins/images/faviconCustom</code></li>
  836. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Generate your Favicons and HTML code"</li>
  837. <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>
  838. <li lang="en"><i class="fa fa-caret-right text-info"></i> Copy code and paste inside left box</li>
  839. </ul>
  840. </div>
  841. </div>
  842. </div>
  843. '
  844. ),
  845. ),
  846. 'Custom CSS' => array(
  847. array(
  848. 'type' => 'html',
  849. 'override' => 12,
  850. 'label' => 'Custom CSS [Can replace colors from above]',
  851. '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>'
  852. ),
  853. array(
  854. 'type' => 'textbox',
  855. 'name' => 'customCss',
  856. 'class' => 'hidden cssTextarea',
  857. 'label' => '',
  858. 'value' => $GLOBALS['customCss'],
  859. 'placeholder' => 'No <style> tags needed',
  860. 'attr' => 'rows="10"',
  861. ),
  862. )
  863. );
  864. }
  865. }
  866. function editAppearance($array)
  867. {
  868. switch ($array['data']['value']) {
  869. case 'true':
  870. $array['data']['value'] = (bool)true;
  871. break;
  872. case 'false':
  873. $array['data']['value'] = (bool)false;
  874. break;
  875. default:
  876. $array['data']['value'] = $array['data']['value'];
  877. }
  878. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  879. switch ($array['data']['action']) {
  880. case 'editCustomizeAppearance':
  881. $newItem = array(
  882. $array['data']['name'] => $array['data']['value']
  883. );
  884. return (updateConfig($newItem)) ? true : false;
  885. break;
  886. default:
  887. # code...
  888. break;
  889. }
  890. }
  891. function updateConfigMultiple($array)
  892. {
  893. return (updateConfig($array['data']['payload'])) ? true : false;
  894. }
  895. function updateConfigMultipleForm($array)
  896. {
  897. $newItem = array();
  898. foreach ($array['data']['payload'] as $k => $v) {
  899. switch ($v['value']) {
  900. case 'true':
  901. $v['value'] = (bool)true;
  902. break;
  903. case 'false':
  904. $v['value'] = (bool)false;
  905. break;
  906. default:
  907. $v['value'] = $v['value'];
  908. }
  909. // Hash
  910. if ($v['type'] == 'password') {
  911. if (strpos($v['value'], '==') !== false) {
  912. $v['value'] = $v['value'];
  913. } else {
  914. $v['value'] = encrypt($v['value']);
  915. }
  916. }
  917. $newItem[$v['name']] = $v['value'];
  918. }
  919. //return $newItem;
  920. return (updateConfig($newItem)) ? true : false;
  921. }
  922. function updateConfigItem($array)
  923. {
  924. switch ($array['data']['value']) {
  925. case 'true':
  926. $array['data']['value'] = (bool)true;
  927. break;
  928. case 'false':
  929. $array['data']['value'] = (bool)false;
  930. break;
  931. default:
  932. $array['data']['value'] = $array['data']['value'];
  933. }
  934. // Hash
  935. if ($array['data']['type'] == 'password') {
  936. $array['data']['value'] = encrypt($array['data']['value']);
  937. }
  938. $newItem = array(
  939. $array['data']['name'] => $array['data']['value']
  940. );
  941. return (updateConfig($newItem)) ? true : false;
  942. }
  943. function getPlugins()
  944. {
  945. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  946. $pluginList = [];
  947. foreach ($GLOBALS['plugins'] as $plugin) {
  948. foreach ($plugin as $key => $value) {
  949. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  950. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
  951. $pluginList[$key] = $plugin[$key];
  952. }
  953. }
  954. }
  955. return $pluginList;
  956. }
  957. return false;
  958. }
  959. function editPlugins($array)
  960. {
  961. switch ($array['data']['action']) {
  962. case 'enable':
  963. $newItem = array(
  964. $array['data']['configName'] => true
  965. );
  966. writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  967. return (updateConfig($newItem)) ? true : false;
  968. break;
  969. case 'disable':
  970. $newItem = array(
  971. $array['data']['configName'] => false
  972. );
  973. writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  974. return (updateConfig($newItem)) ? true : false;
  975. break;
  976. default:
  977. # code...
  978. break;
  979. }
  980. }
  981. function auth()
  982. {
  983. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  984. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  985. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  986. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  987. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  988. $currentIP = userIP();
  989. if (isset($GLOBALS['organizrUser'])) {
  990. $currentUser = $GLOBALS['organizrUser']['username'];
  991. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  992. } else {
  993. $currentUser = 'Guest';
  994. $currentGroup = getUserLevel();
  995. }
  996. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  997. if ($whitelist) {
  998. if (in_array($currentIP, arrayIP($whitelist))) {
  999. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  1000. }
  1001. }
  1002. if ($blacklist) {
  1003. if (in_array($currentIP, arrayIP($blacklist))) {
  1004. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  1005. }
  1006. }
  1007. if ($group !== null) {
  1008. if (qualifyRequest($group)) {
  1009. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  1010. } else {
  1011. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  1012. }
  1013. } else {
  1014. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  1015. }
  1016. }
  1017. function logoOrText()
  1018. {
  1019. if ($GLOBALS['useLogo'] == false) {
  1020. return '<h1>' . $GLOBALS['title'] . '</h1>';
  1021. } else {
  1022. return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
  1023. }
  1024. }
  1025. function showLogin()
  1026. {
  1027. if ($GLOBALS['hideRegistration'] == false) {
  1028. 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>';
  1029. }
  1030. }
  1031. function getImages()
  1032. {
  1033. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  1034. $path = 'plugins/images/tabs/';
  1035. $images = scandir($dirname);
  1036. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  1037. $allIcons = array();
  1038. foreach ($images as $image) {
  1039. if (!in_array($image, $ignore)) {
  1040. $allIcons[] = $path . $image;
  1041. }
  1042. }
  1043. return $allIcons;
  1044. }
  1045. function editImages()
  1046. {
  1047. $array = array();
  1048. $postCheck = array_filter($_POST);
  1049. $filesCheck = array_filter($_FILES);
  1050. if (!empty($postCheck)) {
  1051. if ($_POST['data']['action'] == 'deleteImage') {
  1052. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
  1053. writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
  1054. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
  1055. }
  1056. }
  1057. }
  1058. if (!empty($filesCheck)) {
  1059. ini_set('upload_max_filesize', '10M');
  1060. ini_set('post_max_size', '10M');
  1061. $tempFile = $_FILES['file']['tmp_name'];
  1062. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  1063. $targetFile = $targetPath . $_FILES['file']['name'];
  1064. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  1065. }
  1066. return false;
  1067. }
  1068. function getThemes()
  1069. {
  1070. $themes = array();
  1071. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  1072. $themes[] = array(
  1073. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1074. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  1075. );
  1076. }
  1077. return $themes;
  1078. }
  1079. function getSounds()
  1080. {
  1081. $sounds = array();
  1082. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  1083. $sounds[] = array(
  1084. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1085. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/default/' . basename($filename) . '.mp3')
  1086. );
  1087. }
  1088. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  1089. $sounds[] = array(
  1090. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1091. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/custom/' . basename($filename) . '.mp3')
  1092. );
  1093. }
  1094. return $sounds;
  1095. }
  1096. function getBranches()
  1097. {
  1098. return array(
  1099. array(
  1100. 'name' => 'Develop',
  1101. 'value' => 'v2-develop'
  1102. ),
  1103. array(
  1104. 'name' => 'Master',
  1105. 'value' => 'v2-master'
  1106. )
  1107. );
  1108. }
  1109. function getAuthTypes()
  1110. {
  1111. return array(
  1112. array(
  1113. 'name' => 'Organizr DB',
  1114. 'value' => 'internal'
  1115. ),
  1116. array(
  1117. 'name' => 'Organizr DB + Backend',
  1118. 'value' => 'both'
  1119. ),
  1120. array(
  1121. 'name' => 'Backend Only',
  1122. 'value' => 'external'
  1123. )
  1124. );
  1125. }
  1126. function getAuthBackends()
  1127. {
  1128. $backendOptions = array();
  1129. $backendOptions[] = array(
  1130. 'name' => 'Choose Backend',
  1131. 'value' => false,
  1132. 'disabled' => true
  1133. );
  1134. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  1135. return strpos($v, 'plugin_auth_') === 0;
  1136. }) as $value) {
  1137. $name = str_replace('plugin_auth_', '', $value);
  1138. if (strpos($name, 'disabled') === false) {
  1139. $backendOptions[] = array(
  1140. 'name' => ucwords(str_replace('_', ' ', $name)),
  1141. 'value' => $name
  1142. );
  1143. } else {
  1144. $backendOptions[] = array(
  1145. 'name' => $value(),
  1146. 'value' => 'none',
  1147. 'disabled' => true,
  1148. );
  1149. }
  1150. }
  1151. ksort($backendOptions);
  1152. return $backendOptions;
  1153. }
  1154. function wizardPath($array)
  1155. {
  1156. $path = $array['data']['path'];
  1157. if (file_exists($path)) {
  1158. if (is_writable($path)) {
  1159. return true;
  1160. }
  1161. } else {
  1162. if (is_writable(dirname($path, 1))) {
  1163. if (mkdir($path, 0760, true)) {
  1164. return true;
  1165. }
  1166. }
  1167. }
  1168. return 'permissions';
  1169. }
  1170. function groupSelect()
  1171. {
  1172. $groups = allGroups();
  1173. $select = array();
  1174. foreach ($groups as $key => $value) {
  1175. $select[] = array(
  1176. 'name' => $value['group'],
  1177. 'value' => $value['group_id']
  1178. );
  1179. }
  1180. return $select;
  1181. }
  1182. function getImage()
  1183. {
  1184. $refresh = false;
  1185. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1186. if (!file_exists($cacheDirectory)) {
  1187. mkdir($cacheDirectory, 0777, true);
  1188. }
  1189. @$image_url = $_GET['img'];
  1190. @$key = $_GET['key'];
  1191. @$image_height = $_GET['height'];
  1192. @$image_width = $_GET['width'];
  1193. @$source = $_GET['source'];
  1194. @$itemType = $_GET['type'];
  1195. if (strpos($key, '$') !== false) {
  1196. $key = explode('$', $key)[0];
  1197. $refresh = true;
  1198. }
  1199. switch ($source) {
  1200. case 'plex':
  1201. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  1202. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  1203. break;
  1204. case 'emby':
  1205. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  1206. $imgParams = array();
  1207. if (isset($_GET['height'])) {
  1208. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  1209. }
  1210. if (isset($_GET['width'])) {
  1211. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  1212. }
  1213. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  1214. break;
  1215. default:
  1216. # code...
  1217. break;
  1218. }
  1219. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  1220. $cachefile = $cacheDirectory . $key . '.jpg';
  1221. $cachetime = 604800;
  1222. // Serve from the cache if it is younger than $cachetime
  1223. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1224. header("Content-type: image/jpeg");
  1225. //@readfile($cachefile);
  1226. echo @curl('get', $cachefile)['content'];
  1227. exit;
  1228. }
  1229. ob_start(); // Start the output buffer
  1230. header('Content-type: image/jpeg');
  1231. //@readfile($image_src);
  1232. echo @curl('get', $image_src)['content'];
  1233. // Cache the output to a file
  1234. $fp = fopen($cachefile, 'wb');
  1235. fwrite($fp, ob_get_contents());
  1236. fclose($fp);
  1237. ob_end_flush(); // Send the output to the browser
  1238. die();
  1239. } else {
  1240. die("Invalid Request");
  1241. }
  1242. }
  1243. function cacheImage($url, $name)
  1244. {
  1245. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1246. if (!file_exists($cacheDirectory)) {
  1247. mkdir($cacheDirectory, 0777, true);
  1248. }
  1249. $cachefile = $cacheDirectory . $name . '.jpg';
  1250. copy($url, $cachefile);
  1251. }
  1252. function downloader($array)
  1253. {
  1254. switch ($array['data']['source']) {
  1255. case 'sabnzbd':
  1256. switch ($array['data']['action']) {
  1257. case 'resume':
  1258. case 'pause':
  1259. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1260. break;
  1261. default:
  1262. # code...
  1263. break;
  1264. }
  1265. break;
  1266. case 'nzbget':
  1267. break;
  1268. default:
  1269. # code...
  1270. break;
  1271. }
  1272. }
  1273. function sabnzbdAction($action = null, $target = null)
  1274. {
  1275. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1276. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1277. switch ($action) {
  1278. case 'pause':
  1279. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
  1280. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1281. break;
  1282. case 'resume':
  1283. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
  1284. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1285. break;
  1286. default:
  1287. # code...
  1288. break;
  1289. }
  1290. try {
  1291. $options = (localURL($url)) ? array('verify' => false) : array();
  1292. $response = Requests::get($url, array(), $options);
  1293. if ($response->success) {
  1294. $api['content'] = json_decode($response->body, true);
  1295. }
  1296. } catch (Requests_Exception $e) {
  1297. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1298. };
  1299. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1300. return $api;
  1301. }
  1302. }
  1303. // Deluge API isn't working ATM - will get with dev.
  1304. function delugeAction($action = null, $target = null)
  1305. {
  1306. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  1307. $url = qualifyURL($GLOBALS['delugeURL']);
  1308. try {
  1309. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1310. switch ($action) {
  1311. case 'pause':
  1312. $torrents = $deluge->pauseTorrent($target);
  1313. break;
  1314. case 'pauseAll':
  1315. $torrents = $deluge->pauseAllTorrents();
  1316. break;
  1317. case 'resume':
  1318. $torrents = $deluge->resumeTorrent($target);
  1319. break;
  1320. case 'resumeAll':
  1321. $torrents = $deluge->resumeAllTorrents();
  1322. break;
  1323. default:
  1324. # code...
  1325. break;
  1326. }
  1327. $api['content'] = $torrents;
  1328. } catch (Excecption $e) {
  1329. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1330. }
  1331. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1332. return $api;
  1333. }
  1334. return false;
  1335. }
  1336. function getOrgUsers()
  1337. {
  1338. $result = allUsers();
  1339. if (is_array($result) || is_object($result)) {
  1340. foreach ($result['users'] as $k => $v) {
  1341. $return[$v['username']] = $v['email'];
  1342. }
  1343. return $return;
  1344. }
  1345. }
  1346. function convertPlexName($user, $type)
  1347. {
  1348. $array = libraryList('plex');
  1349. switch ($type) {
  1350. case "username":
  1351. case "u":
  1352. $plexUser = array_search($user, $array['users']);
  1353. break;
  1354. case "id":
  1355. if (array_key_exists(strtolower($user), $array['users'])) {
  1356. $plexUser = $array['users'][strtolower($user)];
  1357. }
  1358. break;
  1359. default:
  1360. $plexUser = false;
  1361. }
  1362. return (!empty($plexUser) ? $plexUser : null);
  1363. }
  1364. function libraryList($type = null)
  1365. {
  1366. switch ($type) {
  1367. case 'plex':
  1368. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1369. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
  1370. try {
  1371. $headers = array(
  1372. "Accept" => "application/json",
  1373. "X-Plex-Token" => $GLOBALS['plexToken']
  1374. );
  1375. $response = Requests::get($url, $headers, array());
  1376. libxml_use_internal_errors(true);
  1377. if ($response->success) {
  1378. $libraryList = array();
  1379. $plex = simplexml_load_string($response->body);
  1380. foreach ($plex->SharedServer->Section as $child) {
  1381. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1382. }
  1383. foreach ($plex->SharedServer as $child) {
  1384. if (!empty($child['username'])) {
  1385. $username = (string)strtolower($child['username']);
  1386. $email = (string)strtolower($child['email']);
  1387. $libraryList['users'][$username] = (string)$child['id'];
  1388. $libraryList['emails'][$email] = (string)$child['id'];
  1389. $libraryList['both'][$username] = $email;
  1390. }
  1391. }
  1392. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1393. return $libraryList;
  1394. }
  1395. } catch (Requests_Exception $e) {
  1396. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1397. };
  1398. }
  1399. break;
  1400. default:
  1401. # code...
  1402. break;
  1403. }
  1404. return false;
  1405. }
  1406. function plexJoinAPI($array)
  1407. {
  1408. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1409. }
  1410. function plexJoin($username, $email, $password)
  1411. {
  1412. try {
  1413. $url = 'https://plex.tv/users.json';
  1414. $headers = array(
  1415. 'Accept' => 'application/json',
  1416. 'Content-Type' => 'application/x-www-form-urlencoded',
  1417. 'X-Plex-Product' => 'Organizr',
  1418. 'X-Plex-Version' => '2.0',
  1419. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1420. );
  1421. $data = array(
  1422. 'user[email]' => $email,
  1423. 'user[username]' => $username,
  1424. 'user[password]' => $password,
  1425. );
  1426. $response = Requests::post($url, $headers, $data, array());
  1427. $json = json_decode($response->body, true);
  1428. $errors = (!empty($json['errors']) ? true : false);
  1429. $success = (!empty($json['user']) ? true : false);
  1430. //Use This for later
  1431. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1432. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1433. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1434. $errorMessage = "";
  1435. if ($errors) {
  1436. if ($usernameError) {
  1437. $errorMessage .= "[Username Error: " . $usernameError . "]";
  1438. }
  1439. if ($emailError) {
  1440. $errorMessage .= "[Email Error: " . $emailError . "]";
  1441. }
  1442. if ($passwordError) {
  1443. $errorMessage .= "[Password Error: " . $passwordError . "]";
  1444. }
  1445. }
  1446. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1447. } catch (Requests_Exception $e) {
  1448. writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1449. };
  1450. return false;
  1451. }
  1452. function checkFrame($array, $url)
  1453. {
  1454. if (array_key_exists("x-frame-options", $array)) {
  1455. if ($array['x-frame-options'] == "deny") {
  1456. return false;
  1457. } elseif ($array['x-frame-options'] == "sameorgin") {
  1458. $digest = parse_url($url);
  1459. $host = (isset($digest['host']) ? $digest['host'] : '');
  1460. if (getServer() == $host) {
  1461. return true;
  1462. } else {
  1463. return false;
  1464. }
  1465. }
  1466. } else {
  1467. if (!$array) {
  1468. return false;
  1469. }
  1470. return true;
  1471. }
  1472. }
  1473. function frameTest($url)
  1474. {
  1475. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  1476. $url = qualifyURL($url);
  1477. if (checkFrame($array, $url)) {
  1478. return true;
  1479. } else {
  1480. return false;
  1481. }
  1482. }
  1483. function ping($pings)
  1484. {
  1485. if (qualifyRequest($GLOBALS['pingAuth'])) {
  1486. $type = gettype($pings);
  1487. $ping = new Ping("");
  1488. $ping->setTtl(128);
  1489. $ping->setTimeout(2);
  1490. switch ($type) {
  1491. case "array":
  1492. $results = [];
  1493. foreach ($pings as $k => $v) {
  1494. if (strpos($v, ':') !== false) {
  1495. $domain = explode(':', $v)[0];
  1496. $port = explode(':', $v)[1];
  1497. $ping->setHost($domain);
  1498. $ping->setPort($port);
  1499. $latency = $ping->ping('fsockopen');
  1500. } else {
  1501. $ping->setHost($v);
  1502. $latency = $ping->ping();
  1503. }
  1504. if ($latency || $latency === 0) {
  1505. $results[$v] = $latency;
  1506. } else {
  1507. $results[$v] = false;
  1508. }
  1509. }
  1510. break;
  1511. case "string":
  1512. if (strpos($pings, ':') !== false) {
  1513. $domain = explode(':', $pings)[0];
  1514. $port = explode(':', $pings)[1];
  1515. $ping->setHost($domain);
  1516. $ping->setPort($port);
  1517. $latency = $ping->ping('fsockopen');
  1518. } else {
  1519. $ping->setHost($pings);
  1520. $latency = $ping->ping();
  1521. }
  1522. if ($latency || $latency === 0) {
  1523. $results = $latency;
  1524. } else {
  1525. $results = false;
  1526. }
  1527. break;
  1528. }
  1529. return $results;
  1530. }
  1531. return false;
  1532. }