organizr-functions.php 50 KB

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