organizr-functions.php 55 KB

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