organizr-functions.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. <?php
  2. function organizrSpecialSettings()
  3. {
  4. $refreshSearch = "Refresh";
  5. return array(
  6. 'homepage' => array(
  7. 'refresh' => array_filter($GLOBALS, function ($k) use ($refreshSearch) {
  8. return stripos($k, $refreshSearch) !== false;
  9. }, ARRAY_FILTER_USE_KEY),
  10. 'search' => array(
  11. 'enabled' => (qualifyRequest($GLOBALS['mediaSearchAuth']) && $GLOBALS['mediaSearch'] == true && $GLOBALS['plexToken']) ? true : false,
  12. 'type' => $GLOBALS['mediaSearchType'],
  13. ),
  14. 'ombi' => array(
  15. 'enabled' => (qualifyRequest($GLOBALS['homepageOmbiAuth']) && qualifyRequest($GLOBALS['homepageOmbiRequestAuth']) && $GLOBALS['homepageOmbiEnabled'] == true && $GLOBALS['ssoOmbi'] && isset($_COOKIE['Auth'])) ? true : false,
  16. 'authView' => (qualifyRequest($GLOBALS['homepageOmbiAuth'])) ? true : false,
  17. 'authRequest' => (qualifyRequest($GLOBALS['homepageOmbiRequestAuth'])) ? true : false,
  18. 'sso' => ($GLOBALS['ssoOmbi']) ? true : false,
  19. 'cookie' => (isset($_COOKIE['Auth'])) ? true : false,
  20. ),
  21. 'options' => array(
  22. 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
  23. )
  24. )
  25. );
  26. }
  27. function wizardConfig($array)
  28. {
  29. foreach ($array['data'] as $items) {
  30. foreach ($items as $key => $value) {
  31. if ($key == 'name') {
  32. $newKey = $value;
  33. }
  34. if ($key == 'value') {
  35. $newValue = $value;
  36. }
  37. if (isset($newKey) && isset($newValue)) {
  38. $$newKey = $newValue;
  39. }
  40. }
  41. }
  42. $location = cleanDirectory($location);
  43. $dbName = $dbName . '.db';
  44. $configVersion = $GLOBALS['installedVersion'];
  45. $configArray = array(
  46. 'dbName' => $dbName,
  47. 'dbLocation' => $location,
  48. 'license' => $license,
  49. 'organizrHash' => $hashKey,
  50. 'organizrAPI' => $api,
  51. 'registrationPassword' => $registrationPassword,
  52. );
  53. // Create Config
  54. $GLOBALS['dbLocation'] = $location;
  55. $GLOBALS['dbName'] = $dbName;
  56. if (createConfig($configArray)) {
  57. // Call DB Create
  58. if (createDB($location, $dbName)) {
  59. // Add in first user
  60. if (createFirstAdmin($location, $dbName, $username, $password, $email)) {
  61. if (createToken($username, $email, gravatar($email), 'Admin', 0, $hashKey, 1)) {
  62. return true;
  63. } else {
  64. return 'token';
  65. }
  66. } else {
  67. return 'admin';
  68. }
  69. } else {
  70. return 'db';
  71. }
  72. } else {
  73. return 'config';
  74. }
  75. return false;
  76. }
  77. function register($array)
  78. {
  79. // Grab username and password from login form
  80. foreach ($array['data'] as $items) {
  81. foreach ($items as $key => $value) {
  82. if ($key == 'name') {
  83. $newKey = $value;
  84. }
  85. if ($key == 'value') {
  86. $newValue = $value;
  87. }
  88. if (isset($newKey) && isset($newValue)) {
  89. $$newKey = $newValue;
  90. }
  91. }
  92. }
  93. if ($registrationPassword == $GLOBALS['registrationPassword']) {
  94. $defaults = defaultUserGroup();
  95. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  96. if (createUser($username, $password, $defaults, $email)) {
  97. writeLog('success', 'Registration Function - A User has registered', $username);
  98. if (createToken($username, $email, gravatar($email), $defaults['group'], $defaults['group_id'], $GLOBALS['organizrHash'], 1)) {
  99. writeLoginLog($username, 'success');
  100. writeLog('success', 'Login Function - A User has logged in', $username);
  101. return true;
  102. }
  103. } else {
  104. writeLog('error', 'Registration Function - An error occured', $username);
  105. return 'username taken';
  106. }
  107. } else {
  108. writeLog('warning', 'Registration Function - Wrong Password', $username);
  109. return 'mismatch';
  110. }
  111. }
  112. function removeFile($array)
  113. {
  114. $filePath = $array['data']['path'];
  115. $fileName = $array['data']['name'];
  116. if (file_exists($filePath)) {
  117. if (unlink($filePath)) {
  118. writeLog('success', 'Log Management Function - Log: ' . $fileName . ' has been purged/deleted', 'SYSTEM');
  119. return true;
  120. } else {
  121. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' - Error Occured', 'SYSTEM');
  122. return false;
  123. }
  124. } else {
  125. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' does not exist', 'SYSTEM');
  126. return false;
  127. }
  128. }
  129. function recover($array)
  130. {
  131. $email = $array['data']['email'];
  132. $newPassword = randString(10);
  133. try {
  134. $connect = new Dibi\Connection([
  135. 'driver' => 'sqlite3',
  136. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  137. ]);
  138. $isUser = $connect->fetch('SELECT * FROM users WHERE email = ? COLLATE NOCASE', $email);
  139. if ($isUser) {
  140. $connect->query('
  141. UPDATE users SET', [
  142. 'password' => password_hash($newPassword, PASSWORD_BCRYPT)
  143. ], '
  144. WHERE email=? COLLATE NOCASE', $email);
  145. if ($GLOBALS['PHPMAILER-enabled']) {
  146. $emailTemplate = array(
  147. 'type' => 'reset',
  148. 'body' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'],
  149. 'subject' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'],
  150. 'user' => $isUser['username'],
  151. 'password' => $newPassword,
  152. 'inviteCode' => null,
  153. );
  154. $emailTemplate = phpmEmailTemplate($emailTemplate);
  155. $sendEmail = array(
  156. 'to' => $email,
  157. 'user' => $isUser['username'],
  158. 'subject' => $emailTemplate['subject'],
  159. 'body' => phpmBuildEmail($emailTemplate),
  160. );
  161. phpmSendEmail($sendEmail);
  162. }
  163. writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
  164. return true;
  165. } else {
  166. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  167. return 'an error occured';
  168. }
  169. } catch (Dibi\Exception $e) {
  170. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  171. return 'an error occured';
  172. }
  173. }
  174. function editUser($array)
  175. {
  176. if ($array['data']['username'] == '' && $array['data']['username'] == '') {
  177. return 'Username/email not set';
  178. }
  179. try {
  180. $connect = new Dibi\Connection([
  181. 'driver' => 'sqlite3',
  182. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  183. ]);
  184. if (!usernameTakenExcept($array['data']['username'], $array['data']['email'], $GLOBALS['organizrUser']['userID'])) {
  185. $connect->query('
  186. UPDATE users SET', [
  187. 'username' => $array['data']['username'],
  188. 'email' => $array['data']['email'],
  189. ], '
  190. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  191. if (!empty($array['data']['password'])) {
  192. $connect->query('
  193. UPDATE users SET', [
  194. 'password' => password_hash($array['data']['password'], PASSWORD_BCRYPT)
  195. ], '
  196. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  197. }
  198. writeLog('success', 'User Management Function - User: ' . $array['data']['username'] . '\'s info was changed', $GLOBALS['organizrUser']['username']);
  199. return true;
  200. } else {
  201. return 'Username/Email Already Taken';
  202. }
  203. } catch (Dibi\Exception $e) {
  204. writeLog('error', 'User Management Function - Error - User: ' . $array['data']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  205. return 'an error occured';
  206. }
  207. }
  208. function logout()
  209. {
  210. coookie('delete', 'organizrToken');
  211. coookie('delete', 'mpt');
  212. coookie('delete', 'Auth');
  213. $GLOBALS['organizrUser'] = false;
  214. return true;
  215. }
  216. function qualifyRequest($accessLevelNeeded)
  217. {
  218. if (getUserLevel() <= $accessLevelNeeded) {
  219. return true;
  220. } else {
  221. return false;
  222. }
  223. }
  224. function getUserLevel()
  225. {
  226. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  227. // Check token or API key
  228. // If API key, return 0 for admin
  229. if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
  230. //DO API CHECK
  231. return 0;
  232. } elseif (isset($GLOBALS['organizrUser'])) {
  233. return $GLOBALS['organizrUser']['groupID'];
  234. }
  235. // All else fails? return guest id
  236. return 999;
  237. }
  238. function organizrStatus()
  239. {
  240. $status = array();
  241. $dependenciesActive = array();
  242. $dependenciesInactive = array();
  243. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  244. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  245. foreach ($extensions as $check) {
  246. if (extension_loaded($check)) {
  247. array_push($dependenciesActive, $check);
  248. } else {
  249. array_push($dependenciesInactive, $check);
  250. }
  251. }
  252. foreach ($functions as $check) {
  253. if (function_exists($check)) {
  254. array_push($dependenciesActive, $check);
  255. } else {
  256. array_push($dependenciesInactive, $check);
  257. }
  258. }
  259. if (!file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
  260. $status['status'] = "wizard";//wizard - ok for test
  261. }
  262. if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, '7.0.0') >= 0)) {
  263. $status['status'] = "dependencies";
  264. }
  265. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  266. $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
  267. $status['minVersion'] = (version_compare(PHP_VERSION, '7.0.0') >= 0) ? 'yes' : 'no';
  268. $status['dependenciesActive'] = $dependenciesActive;
  269. $status['dependenciesInactive'] = $dependenciesInactive;
  270. $status['version'] = $GLOBALS['installedVersion'];
  271. $status['os'] = getOS();
  272. $status['php'] = phpversion();
  273. return $status;
  274. }
  275. function getSettingsMain()
  276. {
  277. return array(
  278. 'Github' => array(
  279. array(
  280. 'type' => 'select',
  281. 'name' => 'branch',
  282. 'label' => 'Branch',
  283. 'value' => $GLOBALS['branch'],
  284. 'options' => getBranches()
  285. ),
  286. array(
  287. 'type' => 'button',
  288. 'label' => 'Force Install Branch',
  289. 'class' => 'updateNow',
  290. 'icon' => 'fa fa-download',
  291. 'text' => 'Retrieve'
  292. )
  293. ),
  294. 'API' => array(
  295. array(
  296. 'type' => 'password-alt',
  297. 'name' => 'organizrAPI',
  298. 'label' => 'Organizr API',
  299. 'value' => $GLOBALS['organizrAPI']
  300. ),
  301. array(
  302. 'type' => 'button',
  303. 'label' => 'Generate New API Key',
  304. 'class' => 'newAPIKey',
  305. 'icon' => 'fa fa-refresh',
  306. 'text' => 'Generate'
  307. )
  308. ),
  309. 'Authentication' => array(
  310. array(
  311. 'type' => 'select',
  312. 'name' => 'authType',
  313. 'id' => 'authSelect',
  314. 'label' => 'Authentication Type',
  315. 'value' => $GLOBALS['authType'],
  316. 'options' => getAuthTypes()
  317. ),
  318. array(
  319. 'type' => 'select',
  320. 'name' => 'authBackend',
  321. 'id' => 'authBackendSelect',
  322. 'label' => 'Authentication Backend',
  323. 'class' => 'backendAuth switchAuth',
  324. 'value' => $GLOBALS['authBackend'],
  325. 'options' => getAuthBackends()
  326. ),
  327. array(
  328. 'type' => 'password-alt',
  329. 'name' => 'plexToken',
  330. 'class' => 'plexAuth switchAuth',
  331. 'label' => 'Plex Token',
  332. 'value' => $GLOBALS['plexToken'],
  333. 'placeholder' => 'Use Get Token Button'
  334. ),
  335. array(
  336. 'type' => 'button',
  337. 'label' => 'Get Plex Token',
  338. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  339. 'icon' => 'fa fa-ticket',
  340. 'text' => 'Retrieve',
  341. 'href' => '#auth-plex-token-form',
  342. 'attr' => 'data-effect="mfp-3d-unfold"'
  343. ),
  344. array(
  345. 'type' => 'password-alt',
  346. 'name' => 'plexID',
  347. 'class' => 'plexAuth switchAuth',
  348. 'label' => 'Plex Machine',
  349. 'value' => $GLOBALS['plexID'],
  350. 'placeholder' => 'Use Get Plex Machine Button'
  351. ),
  352. array(
  353. 'type' => 'button',
  354. 'label' => 'Get Plex Machine',
  355. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  356. 'icon' => 'fa fa-id-badge',
  357. 'text' => 'Retrieve',
  358. 'href' => '#auth-plex-machine-form',
  359. 'attr' => 'data-effect="mfp-3d-unfold"'
  360. ),
  361. array(
  362. 'type' => 'input',
  363. 'name' => 'authBackendHost',
  364. 'class' => 'ldapAuth ftpAuth switchAuth',
  365. 'label' => 'Host Address',
  366. 'value' => $GLOBALS['authBackendHost'],
  367. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  368. ),
  369. array(
  370. 'type' => 'input',
  371. 'name' => 'authBaseDN',
  372. 'class' => 'ldapAuth switchAuth',
  373. 'label' => 'Host Base DN',
  374. 'value' => $GLOBALS['authBaseDN'],
  375. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  376. ),
  377. array(
  378. 'type' => 'input',
  379. 'name' => 'embyURL',
  380. 'class' => 'embyAuth switchAuth',
  381. 'label' => 'Emby URL',
  382. 'value' => $GLOBALS['embyURL'],
  383. 'placeholder' => 'http(s)://hostname:port'
  384. ),
  385. array(
  386. 'type' => 'password-alt',
  387. 'name' => 'embyToken',
  388. 'class' => 'embyAuth switchAuth',
  389. 'label' => 'Emby Token',
  390. 'value' => $GLOBALS['embyToken'],
  391. 'placeholder' => ''
  392. )
  393. /*array(
  394. 'type' => 'button',
  395. 'label' => 'Send Test',
  396. 'class' => 'phpmSendTestEmail',
  397. 'icon' => 'fa fa-paper-plane',
  398. 'text' => 'Send'
  399. )*/
  400. ),
  401. 'Misc' => array(
  402. array(
  403. 'type' => 'password-alt',
  404. 'name' => 'registrationPassword',
  405. 'label' => 'Registration Password',
  406. 'value' => $GLOBALS['registrationPassword'],
  407. ),
  408. array(
  409. 'type' => 'switch',
  410. 'name' => 'hideRegistration',
  411. 'label' => 'Hide Registration',
  412. 'value' => $GLOBALS['hideRegistration']
  413. )
  414. )
  415. );
  416. }
  417. function getSSO()
  418. {
  419. return array(
  420. 'Plex' => array(
  421. array(
  422. 'type' => 'password-alt',
  423. 'name' => 'plexToken',
  424. 'label' => 'Plex Token',
  425. 'value' => $GLOBALS['plexToken'],
  426. 'placeholder' => 'Use Get Token Button'
  427. ),
  428. array(
  429. 'type' => 'button',
  430. 'label' => 'Get Plex Token',
  431. 'class' => 'popup-with-form getPlexTokenSSO',
  432. 'icon' => 'fa fa-ticket',
  433. 'text' => 'Retrieve',
  434. 'href' => '#sso-plex-token-form',
  435. 'attr' => 'data-effect="mfp-3d-unfold"'
  436. ),
  437. array(
  438. 'type' => 'password-alt',
  439. 'name' => 'plexID',
  440. 'label' => 'Plex Machine',
  441. 'value' => $GLOBALS['plexID'],
  442. 'placeholder' => 'Use Get Plex Machine Button'
  443. ),
  444. array(
  445. 'type' => 'button',
  446. 'label' => 'Get Plex Machine',
  447. 'class' => 'popup-with-form getPlexMachineSSO',
  448. 'icon' => 'fa fa-id-badge',
  449. 'text' => 'Retrieve',
  450. 'href' => '#sso-plex-machine-form',
  451. 'attr' => 'data-effect="mfp-3d-unfold"'
  452. ),
  453. array(
  454. 'type' => 'input',
  455. 'name' => 'plexAdmin',
  456. 'label' => 'Admin Username',
  457. 'value' => $GLOBALS['plexAdmin'],
  458. 'placeholder' => 'Admin username for Plex'
  459. ),
  460. array(
  461. 'type' => 'blank',
  462. 'label' => ''
  463. ),
  464. array(
  465. 'type' => 'html',
  466. 'label' => 'Plex Note',
  467. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  468. ),
  469. array(
  470. 'type' => 'switch',
  471. 'name' => 'ssoPlex',
  472. 'label' => 'Enable',
  473. 'value' => $GLOBALS['ssoPlex']
  474. )
  475. ),
  476. 'Ombi' => array(
  477. array(
  478. 'type' => 'input',
  479. 'name' => 'ombiURL',
  480. 'label' => 'Ombi URL',
  481. 'value' => $GLOBALS['ombiURL'],
  482. 'placeholder' => 'http(s)://hostname:port'
  483. ),
  484. array(
  485. 'type' => 'switch',
  486. 'name' => 'ssoOmbi',
  487. 'label' => 'Enable',
  488. 'value' => $GLOBALS['ssoOmbi']
  489. )
  490. ),
  491. 'Tautulli' => array(
  492. array(
  493. 'type' => 'input',
  494. 'name' => 'tautulliURL',
  495. 'label' => 'Tautulli URL',
  496. 'value' => $GLOBALS['tautulliURL'],
  497. 'placeholder' => 'http(s)://hostname:port'
  498. ),
  499. array(
  500. 'type' => 'switch',
  501. 'name' => 'ssoTautulli',
  502. 'label' => 'Enable',
  503. 'value' => $GLOBALS['ssoTautulli']
  504. )
  505. )
  506. );
  507. }
  508. function loadAppearance()
  509. {
  510. $appearance = array();
  511. $appearance['logo'] = $GLOBALS['logo'];
  512. $appearance['title'] = $GLOBALS['title'];
  513. $appearance['useLogo'] = $GLOBALS['useLogo'];
  514. $appearance['headerColor'] = $GLOBALS['headerColor'];
  515. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  516. $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
  517. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  518. $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
  519. $appearance['accentColor'] = $GLOBALS['accentColor'];
  520. $appearance['accentTextColor'] = $GLOBALS['accentTextColor'];
  521. $appearance['buttonColor'] = $GLOBALS['buttonColor'];
  522. $appearance['buttonTextColor'] = $GLOBALS['buttonTextColor'];
  523. $appearance['buttonTextHoverColor'] = $GLOBALS['buttonTextHoverColor'];
  524. $appearance['buttonHoverColor'] = $GLOBALS['buttonHoverColor'];
  525. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  526. $appearance['customCss'] = $GLOBALS['customCss'];
  527. return $appearance;
  528. }
  529. function getCustomizeAppearance()
  530. {
  531. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  532. return array(
  533. 'Top Bar' => array(
  534. array(
  535. 'type' => 'input',
  536. 'name' => 'logo',
  537. 'label' => 'Logo',
  538. 'value' => $GLOBALS['logo']
  539. ),
  540. array(
  541. 'type' => 'input',
  542. 'name' => 'title',
  543. 'label' => 'Title',
  544. 'value' => $GLOBALS['title']
  545. ),
  546. array(
  547. 'type' => 'switch',
  548. 'name' => 'useLogo',
  549. 'label' => 'Use Logo instead of Title',
  550. 'value' => $GLOBALS['useLogo']
  551. )
  552. ),
  553. 'Login Page' => array(
  554. array(
  555. 'type' => 'input',
  556. 'name' => 'loginWallpaper',
  557. 'label' => 'Login Wallpaper',
  558. 'value' => $GLOBALS['loginWallpaper']
  559. )
  560. ),
  561. 'Options' => array(
  562. array(
  563. 'type' => 'switch',
  564. 'name' => 'alternateHomepageHeaders',
  565. 'label' => 'Alternate Homepage Titles',
  566. 'value' => $GLOBALS['alternateHomepageHeaders']
  567. )
  568. ),
  569. 'custom' => '
  570. <div class="row">
  571. <div class="col-lg-12">
  572. <div class="panel panel-info">
  573. <div class="panel-heading">
  574. <span lang="en">Notice</span>
  575. </div>
  576. <div class="panel-wrapper collapse in" aria-expanded="true">
  577. <div class="panel-body">
  578. <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
  579. </div>
  580. </div>
  581. </div>
  582. </div>
  583. </div>
  584. ',
  585. 'Colors & Themes' => array(
  586. array(
  587. 'type' => 'input',
  588. 'name' => 'headerColor',
  589. 'label' => 'Nav Bar Color',
  590. 'value' => $GLOBALS['headerColor'],
  591. 'class' => 'pick-a-color',
  592. 'attr' => 'data-original="' . $GLOBALS['headerColor'] . '"'
  593. ),
  594. array(
  595. 'type' => 'input',
  596. 'name' => 'headerTextColor',
  597. 'label' => 'Nav Bar Text Color',
  598. 'value' => $GLOBALS['headerTextColor'],
  599. 'class' => 'pick-a-color',
  600. 'attr' => 'data-original="' . $GLOBALS['headerTextColor'] . '"'
  601. ),
  602. array(
  603. 'type' => 'input',
  604. 'name' => 'sidebarColor',
  605. 'label' => 'Side Bar Color',
  606. 'value' => $GLOBALS['sidebarColor'],
  607. 'class' => 'pick-a-color',
  608. 'attr' => 'data-original="' . $GLOBALS['sidebarColor'] . '"'
  609. ),
  610. array(
  611. 'type' => 'input',
  612. 'name' => 'sidebarTextColor',
  613. 'label' => 'Side Bar Text Color',
  614. 'value' => $GLOBALS['sidebarTextColor'],
  615. 'class' => 'pick-a-color',
  616. 'attr' => 'data-original="' . $GLOBALS['sidebarTextColor'] . '"'
  617. ),
  618. array(
  619. 'type' => 'input',
  620. 'name' => 'accentColor',
  621. 'label' => 'Accent Color',
  622. 'value' => $GLOBALS['accentColor'],
  623. 'class' => 'pick-a-color',
  624. 'attr' => 'data-original="' . $GLOBALS['accentColor'] . '"'
  625. ),
  626. array(
  627. 'type' => 'input',
  628. 'name' => 'accentTextColor',
  629. 'label' => 'Accent Text Color',
  630. 'value' => $GLOBALS['accentTextColor'],
  631. 'class' => 'pick-a-color',
  632. 'attr' => 'data-original="' . $GLOBALS['accentTextColor'] . '"'
  633. ),
  634. array(
  635. 'type' => 'input',
  636. 'name' => 'buttonColor',
  637. 'label' => 'Button Color',
  638. 'value' => $GLOBALS['buttonColor'],
  639. 'class' => 'pick-a-color',
  640. 'attr' => 'data-original="' . $GLOBALS['buttonColor'] . '"'
  641. ),
  642. array(
  643. 'type' => 'input',
  644. 'name' => 'buttonTextColor',
  645. 'label' => 'Button Text Color',
  646. 'value' => $GLOBALS['buttonTextColor'],
  647. 'class' => 'pick-a-color',
  648. 'attr' => 'data-original="' . $GLOBALS['buttonTextColor'] . '"'
  649. ),/*
  650. array(
  651. 'type' => 'input',
  652. 'name' => 'buttonHoverColor',
  653. 'label' => 'Button Hover Color',
  654. 'value' => $GLOBALS['buttonHoverColor'],
  655. 'class' => 'pick-a-color',
  656. 'disabled' => true
  657. ),
  658. array(
  659. 'type' => 'input',
  660. 'name' => 'buttonTextHoverColor',
  661. 'label' => 'Button Hover Text Color',
  662. 'value' => $GLOBALS['buttonTextHoverColor'],
  663. 'class' => 'pick-a-color',
  664. 'disabled' => true
  665. ),*/
  666. array(
  667. 'type' => 'select',
  668. 'name' => 'theme',
  669. 'label' => 'Theme',
  670. 'class' => 'themeChanger',
  671. 'value' => $GLOBALS['theme'],
  672. 'options' => getThemes()
  673. ),
  674. array(
  675. 'type' => 'select',
  676. 'name' => 'style',
  677. 'label' => 'Style',
  678. 'class' => 'styleChanger',
  679. 'value' => $GLOBALS['style'],
  680. 'options' => array(
  681. array(
  682. 'name' => 'Light',
  683. 'value' => 'light'
  684. ),
  685. array(
  686. 'name' => 'Dark',
  687. 'value' => 'dark'
  688. ),
  689. array(
  690. 'name' => 'Horizontal',
  691. 'value' => 'horizontal'
  692. )
  693. )
  694. ),
  695. array(
  696. 'type' => 'textbox',
  697. 'name' => 'customCss',
  698. 'class' => 'hidden cssTextarea',
  699. 'label' => '',
  700. 'value' => $GLOBALS['customCss'],
  701. 'placeholder' => 'No <style> tags needed',
  702. 'attr' => 'rows="10"',
  703. ),
  704. array(
  705. 'type' => 'html',
  706. 'override' => 12,
  707. 'label' => 'Custom CSS [Can replace colors from above]',
  708. '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>'
  709. ),
  710. )
  711. );
  712. }
  713. }
  714. function editAppearance($array)
  715. {
  716. switch ($array['data']['value']) {
  717. case 'true':
  718. $array['data']['value'] = (bool)true;
  719. break;
  720. case 'false':
  721. $array['data']['value'] = (bool)false;
  722. break;
  723. default:
  724. $array['data']['value'] = $array['data']['value'];
  725. }
  726. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  727. switch ($array['data']['action']) {
  728. case 'editCustomizeAppearance':
  729. $newItem = array(
  730. $array['data']['name'] => $array['data']['value']
  731. );
  732. return (updateConfig($newItem)) ? true : false;
  733. break;
  734. default:
  735. # code...
  736. break;
  737. }
  738. }
  739. function updateConfigMultiple($array)
  740. {
  741. return (updateConfig($array['data']['payload'])) ? true : false;
  742. }
  743. function updateConfigMultipleForm($array)
  744. {
  745. $newItem = array();
  746. foreach ($array['data']['payload'] as $k => $v) {
  747. switch ($v['value']) {
  748. case 'true':
  749. $v['value'] = (bool)true;
  750. break;
  751. case 'false':
  752. $v['value'] = (bool)false;
  753. break;
  754. default:
  755. $v['value'] = $v['value'];
  756. }
  757. // Hash
  758. if ($v['type'] == 'password') {
  759. if (strpos($v['value'], '==') !== false) {
  760. $v['value'] = $v['value'];
  761. } else {
  762. $v['value'] = encrypt($v['value']);
  763. }
  764. }
  765. $newItem[$v['name']] = $v['value'];
  766. }
  767. //return $newItem;
  768. return (updateConfig($newItem)) ? true : false;
  769. }
  770. function updateConfigItem($array)
  771. {
  772. switch ($array['data']['value']) {
  773. case 'true':
  774. $array['data']['value'] = (bool)true;
  775. break;
  776. case 'false':
  777. $array['data']['value'] = (bool)false;
  778. break;
  779. default:
  780. $array['data']['value'] = $array['data']['value'];
  781. }
  782. // Hash
  783. if ($array['data']['type'] == 'password') {
  784. $array['data']['value'] = encrypt($array['data']['value']);
  785. }
  786. $newItem = array(
  787. $array['data']['name'] => $array['data']['value']
  788. );
  789. return (updateConfig($newItem)) ? true : false;
  790. }
  791. function getPlugins()
  792. {
  793. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  794. $pluginList = [];
  795. foreach ($GLOBALS['plugins'] as $plugin) {
  796. foreach ($plugin as $key => $value) {
  797. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  798. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
  799. $pluginList[$key] = $plugin[$key];
  800. }
  801. }
  802. }
  803. return $pluginList;
  804. }
  805. return false;
  806. }
  807. function editPlugins($array)
  808. {
  809. switch ($array['data']['action']) {
  810. case 'enable':
  811. $newItem = array(
  812. $array['data']['configName'] => true
  813. );
  814. writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  815. return (updateConfig($newItem)) ? true : false;
  816. break;
  817. case 'disable':
  818. $newItem = array(
  819. $array['data']['configName'] => false
  820. );
  821. writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  822. return (updateConfig($newItem)) ? true : false;
  823. break;
  824. default:
  825. # code...
  826. break;
  827. }
  828. }
  829. function auth()
  830. {
  831. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  832. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  833. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  834. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  835. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  836. $currentIP = userIP();
  837. if (isset($GLOBALS['organizrUser'])) {
  838. $currentUser = $GLOBALS['organizrUser']['username'];
  839. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  840. } else {
  841. $currentUser = 'Guest';
  842. $currentGroup = getUserLevel();
  843. }
  844. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  845. if ($whitelist) {
  846. if (in_array($currentIP, arrayIP($whitelist))) {
  847. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  848. }
  849. }
  850. if ($blacklist) {
  851. if (in_array($currentIP, arrayIP($blacklist))) {
  852. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  853. }
  854. }
  855. if ($group !== null) {
  856. if (qualifyRequest($group)) {
  857. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  858. } else {
  859. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  860. }
  861. } else {
  862. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  863. }
  864. }
  865. function logoOrText()
  866. {
  867. if ($GLOBALS['useLogo'] == false) {
  868. return '<h1>' . $GLOBALS['title'] . '</h1>';
  869. } else {
  870. return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
  871. }
  872. }
  873. function showLogin()
  874. {
  875. if ($GLOBALS['hideRegistration'] == false) {
  876. 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>';
  877. }
  878. }
  879. function getImages()
  880. {
  881. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  882. $path = 'plugins/images/tabs/';
  883. $images = scandir($dirname);
  884. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  885. $allIcons = array();
  886. foreach ($images as $image) {
  887. if (!in_array($image, $ignore)) {
  888. $allIcons[] = $path . $image;
  889. }
  890. }
  891. return $allIcons;
  892. }
  893. function editImages()
  894. {
  895. $array = array();
  896. $postCheck = array_filter($_POST);
  897. $filesCheck = array_filter($_FILES);
  898. if (!empty($postCheck)) {
  899. if ($_POST['data']['action'] == 'deleteImage') {
  900. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
  901. writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
  902. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
  903. }
  904. }
  905. }
  906. if (!empty($filesCheck)) {
  907. ini_set('upload_max_filesize', '10M');
  908. ini_set('post_max_size', '10M');
  909. $tempFile = $_FILES['file']['tmp_name'];
  910. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  911. $targetFile = $targetPath . $_FILES['file']['name'];
  912. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  913. }
  914. return false;
  915. }
  916. function getThemes()
  917. {
  918. $themes = array();
  919. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  920. $themes[] = array(
  921. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  922. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  923. );
  924. }
  925. return $themes;
  926. }
  927. function getBranches()
  928. {
  929. return array(
  930. array(
  931. 'name' => 'Develop',
  932. 'value' => 'v2-develop'
  933. ),
  934. array(
  935. 'name' => 'Master',
  936. 'value' => 'v2-master'
  937. )
  938. );
  939. }
  940. function getAuthTypes()
  941. {
  942. return array(
  943. array(
  944. 'name' => 'Organizr DB',
  945. 'value' => 'internal'
  946. ),
  947. array(
  948. 'name' => 'Organizr DB + Backend',
  949. 'value' => 'both'
  950. ),
  951. array(
  952. 'name' => 'Backend Only',
  953. 'value' => 'external'
  954. )
  955. );
  956. }
  957. function getAuthBackends()
  958. {
  959. $backendOptions = array();
  960. $backendOptions[] = array(
  961. 'name' => 'Choose Backend',
  962. 'value' => false,
  963. 'disabled' => true
  964. );
  965. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  966. return strpos($v, 'plugin_auth_') === 0;
  967. }) as $value) {
  968. $name = str_replace('plugin_auth_', '', $value);
  969. if (strpos($name, 'disabled') === false) {
  970. $backendOptions[] = array(
  971. 'name' => ucwords(str_replace('_', ' ', $name)),
  972. 'value' => $name
  973. );
  974. } else {
  975. $backendOptions[] = array(
  976. 'name' => $value(),
  977. 'value' => 'none',
  978. 'disabled' => true,
  979. );
  980. }
  981. }
  982. ksort($backendOptions);
  983. return $backendOptions;
  984. }
  985. function wizardPath($array)
  986. {
  987. $path = $array['data']['path'];
  988. if (file_exists($path)) {
  989. if (is_writable($path)) {
  990. return true;
  991. }
  992. } else {
  993. if (is_writable(dirname($path, 1))) {
  994. if (mkdir($path, 0760, true)) {
  995. return true;
  996. }
  997. }
  998. }
  999. return 'permissions';
  1000. }
  1001. function groupSelect()
  1002. {
  1003. $groups = allGroups();
  1004. $select = array();
  1005. foreach ($groups as $key => $value) {
  1006. $select[] = array(
  1007. 'name' => $value['group'],
  1008. 'value' => $value['group_id']
  1009. );
  1010. }
  1011. return $select;
  1012. }
  1013. function getImage()
  1014. {
  1015. $refresh = false;
  1016. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1017. if (!file_exists($cacheDirectory)) {
  1018. mkdir($cacheDirectory, 0777, true);
  1019. }
  1020. @$image_url = $_GET['img'];
  1021. @$key = $_GET['key'];
  1022. @$image_height = $_GET['height'];
  1023. @$image_width = $_GET['width'];
  1024. @$source = $_GET['source'];
  1025. @$itemType = $_GET['type'];
  1026. if (strpos($key, '$') !== false) {
  1027. $key = explode('$', $key)[0];
  1028. $refresh = true;
  1029. }
  1030. switch ($source) {
  1031. case 'plex':
  1032. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  1033. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  1034. break;
  1035. case 'emby':
  1036. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  1037. $imgParams = array();
  1038. if (isset($_GET['height'])) {
  1039. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  1040. }
  1041. if (isset($_GET['width'])) {
  1042. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  1043. }
  1044. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  1045. break;
  1046. default:
  1047. # code...
  1048. break;
  1049. }
  1050. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  1051. $cachefile = $cacheDirectory . $key . '.jpg';
  1052. $cachetime = 604800;
  1053. // Serve from the cache if it is younger than $cachetime
  1054. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1055. header("Content-type: image/jpeg");
  1056. //@readfile($cachefile);
  1057. echo @curl('get', $cachefile)['content'];
  1058. exit;
  1059. }
  1060. ob_start(); // Start the output buffer
  1061. header('Content-type: image/jpeg');
  1062. //@readfile($image_src);
  1063. echo @curl('get', $image_src)['content'];
  1064. // Cache the output to a file
  1065. $fp = fopen($cachefile, 'wb');
  1066. fwrite($fp, ob_get_contents());
  1067. fclose($fp);
  1068. ob_end_flush(); // Send the output to the browser
  1069. die();
  1070. } else {
  1071. die("Invalid Request");
  1072. }
  1073. }
  1074. function cacheImage($url, $name)
  1075. {
  1076. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1077. if (!file_exists($cacheDirectory)) {
  1078. mkdir($cacheDirectory, 0777, true);
  1079. }
  1080. $cachefile = $cacheDirectory . $name . '.jpg';
  1081. copy($url, $cachefile);
  1082. }
  1083. function downloader($array)
  1084. {
  1085. switch ($array['data']['source']) {
  1086. case 'sabnzbd':
  1087. switch ($array['data']['action']) {
  1088. case 'resume':
  1089. case 'pause':
  1090. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1091. break;
  1092. default:
  1093. # code...
  1094. break;
  1095. }
  1096. break;
  1097. case 'nzbget':
  1098. break;
  1099. default:
  1100. # code...
  1101. break;
  1102. }
  1103. }
  1104. function sabnzbdAction($action = null, $target = null)
  1105. {
  1106. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1107. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1108. switch ($action) {
  1109. case 'pause':
  1110. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
  1111. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1112. break;
  1113. case 'resume':
  1114. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
  1115. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1116. break;
  1117. default:
  1118. # code...
  1119. break;
  1120. }
  1121. try {
  1122. $options = (localURL($url)) ? array('verify' => false) : array();
  1123. $response = Requests::get($url, array(), $options);
  1124. if ($response->success) {
  1125. $api['content'] = json_decode($response->body, true);
  1126. }
  1127. } catch (Requests_Exception $e) {
  1128. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1129. };
  1130. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1131. return $api;
  1132. }
  1133. }
  1134. // Deluge API isn't working ATM - will get with dev.
  1135. function delugeAction($action = null, $target = null)
  1136. {
  1137. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  1138. $url = qualifyURL($GLOBALS['delugeURL']);
  1139. try {
  1140. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1141. switch ($action) {
  1142. case 'pause':
  1143. $torrents = $deluge->pauseTorrent($target);
  1144. break;
  1145. case 'pauseAll':
  1146. $torrents = $deluge->pauseAllTorrents();
  1147. break;
  1148. case 'resume':
  1149. $torrents = $deluge->resumeTorrent($target);
  1150. break;
  1151. case 'resumeAll':
  1152. $torrents = $deluge->resumeAllTorrents();
  1153. break;
  1154. default:
  1155. # code...
  1156. break;
  1157. }
  1158. $api['content'] = $torrents;
  1159. } catch (Excecption $e) {
  1160. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1161. }
  1162. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1163. return $api;
  1164. }
  1165. return false;
  1166. }
  1167. function getOrgUsers()
  1168. {
  1169. $result = allUsers();
  1170. if (is_array($result) || is_object($result)) {
  1171. foreach ($result['users'] as $k => $v) {
  1172. $return[$v['username']] = $v['email'];
  1173. }
  1174. return $return;
  1175. }
  1176. }
  1177. function convertPlexName($user, $type)
  1178. {
  1179. $array = libraryList('plex');
  1180. switch ($type) {
  1181. case "username":
  1182. case "u":
  1183. $plexUser = array_search($user, $array['users']);
  1184. break;
  1185. case "id":
  1186. if (array_key_exists(strtolower($user), $array['users'])) {
  1187. $plexUser = $array['users'][strtolower($user)];
  1188. }
  1189. break;
  1190. default:
  1191. $plexUser = false;
  1192. }
  1193. return (!empty($plexUser) ? $plexUser : null);
  1194. }
  1195. function libraryList($type = null)
  1196. {
  1197. switch ($type) {
  1198. case 'plex':
  1199. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1200. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
  1201. try {
  1202. $headers = array(
  1203. "Accept" => "application/json",
  1204. "X-Plex-Token" => $GLOBALS['plexToken']
  1205. );
  1206. $response = Requests::get($url, $headers, array());
  1207. libxml_use_internal_errors(true);
  1208. if ($response->success) {
  1209. $libraryList = array();
  1210. $plex = simplexml_load_string($response->body);
  1211. foreach ($plex->SharedServer->Section as $child) {
  1212. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1213. }
  1214. foreach ($plex->SharedServer as $child) {
  1215. if (!empty($child['username'])) {
  1216. $username = (string)strtolower($child['username']);
  1217. $email = (string)strtolower($child['email']);
  1218. $libraryList['users'][$username] = (string)$child['id'];
  1219. $libraryList['emails'][$email] = (string)$child['id'];
  1220. $libraryList['both'][$username] = $email;
  1221. }
  1222. }
  1223. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1224. return $libraryList;
  1225. }
  1226. } catch (Requests_Exception $e) {
  1227. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1228. };
  1229. }
  1230. break;
  1231. default:
  1232. # code...
  1233. break;
  1234. }
  1235. return false;
  1236. }
  1237. function plexJoinAPI($array)
  1238. {
  1239. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1240. }
  1241. function plexJoin($username, $email, $password)
  1242. {
  1243. try {
  1244. $url = 'https://plex.tv/users.json';
  1245. $headers = array(
  1246. 'Accept' => 'application/json',
  1247. 'Content-Type' => 'application/x-www-form-urlencoded',
  1248. 'X-Plex-Product' => 'Organizr',
  1249. 'X-Plex-Version' => '2.0',
  1250. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1251. );
  1252. $data = array(
  1253. 'user[email]' => $email,
  1254. 'user[username]' => $username,
  1255. 'user[password]' => $password,
  1256. );
  1257. $response = Requests::post($url, $headers, $data, array());
  1258. $json = json_decode($response->body, true);
  1259. $errors = (!empty($json['errors']) ? true : false);
  1260. $success = (!empty($json['user']) ? true : false);
  1261. //Use This for later
  1262. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1263. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1264. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1265. $errorMessage = "";
  1266. if ($errors) {
  1267. if ($usernameError) {
  1268. $errorMessage .= "[Username Error: " . $usernameError . "]";
  1269. }
  1270. if ($emailError) {
  1271. $errorMessage .= "[Email Error: " . $emailError . "]";
  1272. }
  1273. if ($passwordError) {
  1274. $errorMessage .= "[Password Error: " . $passwordError . "]";
  1275. }
  1276. }
  1277. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1278. } catch (Requests_Exception $e) {
  1279. writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1280. };
  1281. return false;
  1282. }
  1283. function checkFrame($array, $url)
  1284. {
  1285. if (array_key_exists("x-frame-options", $array)) {
  1286. if ($array['x-frame-options'] == "deny") {
  1287. return false;
  1288. } elseif ($array['x-frame-options'] == "sameorgin") {
  1289. $digest = parse_url($url);
  1290. $host = (isset($digest['host']) ? $digest['host'] : '');
  1291. if (getServer() == $host) {
  1292. return true;
  1293. } else {
  1294. return false;
  1295. }
  1296. }
  1297. } else {
  1298. if (!$array) {
  1299. return false;
  1300. }
  1301. return true;
  1302. }
  1303. }
  1304. function frameTest($url)
  1305. {
  1306. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  1307. $url = qualifyURL($url);
  1308. if (checkFrame($array, $url)) {
  1309. return true;
  1310. } else {
  1311. return false;
  1312. }
  1313. }