organizr-functions.php 49 KB

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