organizr-functions.php 58 KB

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