organizr-functions.php 53 KB

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