organizr-functions.php 53 KB

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