organizr-functions.php 50 KB

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