organizr-functions.php 58 KB

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