organizr-functions.php 56 KB

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