organizr-functions.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <?php
  2. trait OrganizrFunctions
  3. {
  4. public function loadDefaultJavascriptFiles()
  5. {
  6. $javaFiles = [
  7. 'js/jquery-2.2.4.min.js',
  8. 'bootstrap/dist/js/bootstrap.min.js',
  9. 'plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.js',
  10. 'js/jquery.slimscroll.js',
  11. 'plugins/bower_components/styleswitcher/jQuery.style.switcher.js',
  12. 'plugins/bower_components/moment/moment.js',
  13. 'plugins/bower_components/moment/moment-timezone.js',
  14. 'plugins/bower_components/jquery-wizard-master/dist/jquery-wizard.min.js',
  15. 'plugins/bower_components/jquery-wizard-master/libs/formvalidation/formValidation.min.js',
  16. 'plugins/bower_components/jquery-wizard-master/libs/formvalidation/bootstrap.min.js',
  17. 'js/bowser.min.js',
  18. 'js/jasny-bootstrap.js'
  19. ];
  20. $scripts = '';
  21. foreach ($javaFiles as $file) {
  22. $scripts .= '<script src="' . $file . '?v=' . $this->fileHash . '"></script>' . "\n";
  23. }
  24. return $scripts;
  25. }
  26. public function loadJavascriptFile($file)
  27. {
  28. return '<script>loadJavascript("' . $file . '?v=' . $this->fileHash . '");' . "</script>\n";
  29. }
  30. public function embyJoinAPI($array)
  31. {
  32. $username = ($array['username']) ?? null;
  33. $email = ($array['email']) ?? null;
  34. $password = ($array['password']) ?? null;
  35. if (!$username) {
  36. $this->setAPIResponse('error', 'Username not supplied', 422);
  37. return false;
  38. }
  39. if (!$email) {
  40. $this->setAPIResponse('error', 'Email not supplied', 422);
  41. return false;
  42. }
  43. if (!$password) {
  44. $this->setAPIResponse('error', 'Password not supplied', 422);
  45. return false;
  46. }
  47. return $this->embyJoin($username, $email, $password);
  48. }
  49. public function embyJoin($username, $email, $password)
  50. {
  51. try {
  52. #create user in emby.
  53. $headers = array(
  54. "Accept" => "application/json"
  55. );
  56. $data = array();
  57. $url = $this->config['embyURL'] . '/emby/Users/New?name=' . $username . '&api_key=' . $this->config['embyToken'];
  58. $response = Requests::Post($url, $headers, json_encode($data), array());
  59. $response = $response->body;
  60. //return($response);
  61. $response = json_decode($response, true);
  62. //return($response);
  63. $userID = $response["Id"];
  64. //return($userID);
  65. #authenticate as user to update password.
  66. //randomizer four digits of DeviceId
  67. // I dont think ther would be security problems with hardcoding deviceID but randomizing it would mitigate any issue.
  68. $deviceIdSeceret = rand(0, 9) . "" . rand(0, 9) . "" . rand(0, 9) . "" . rand(0, 9);
  69. //hardcoded device id with the first three digits random 0-9,0-9,0-9,0-9
  70. $embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", DeviceId="' . $deviceIdSeceret . 'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"';
  71. $headers = array(
  72. "Accept" => "application/json",
  73. "Content-Type" => "application/json",
  74. "X-Emby-Authorization" => $embyAuthHeader
  75. );
  76. $data = array(
  77. "Pw" => "",
  78. "Username" => $username
  79. );
  80. $url = $this->config['embyURL'] . '/emby/Users/AuthenticateByName';
  81. $response = Requests::Post($url, $headers, json_encode($data), array());
  82. $response = $response->body;
  83. $response = json_decode($response, true);
  84. $userToken = $response["AccessToken"];
  85. #update password
  86. $embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", Token="' . $userToken . '", DeviceId="' . $deviceIdSeceret . 'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"';
  87. $headers = array(
  88. "Accept" => "application/json",
  89. "Content-Type" => "application/json",
  90. "X-Emby-Authorization" => $embyAuthHeader
  91. );
  92. $data = array(
  93. "CurrentPw" => "",
  94. "NewPw" => $password,
  95. "Id" => $userID
  96. );
  97. $url = $this->config['embyURL'] . '/emby/Users/' . $userID . '/Password';
  98. Requests::Post($url, $headers, json_encode($data), array());
  99. #update config
  100. $headers = array(
  101. "Accept" => "application/json",
  102. "Content-Type" => "application/json"
  103. );
  104. $url = $this->config['embyURL'] . '/emby/Users/' . $userID . '/Policy?api_key=' . $this->config['embyToken'];
  105. $response = Requests::Post($url, $headers, $this->getEmbyTemplateUserJson(), array());
  106. #add emby.media
  107. try {
  108. #seperate because this is not required
  109. $headers = array(
  110. "Accept" => "application/json",
  111. "X-Emby-Authorization" => $embyAuthHeader
  112. );
  113. $data = array(
  114. "ConnectUsername " => $email
  115. );
  116. $url = $this->config['embyURL'] . '/emby/Users/' . $userID . '/Connect/Link';
  117. Requests::Post($url, $headers, json_encode($data), array());
  118. } catch (Requests_Exception $e) {
  119. $this->writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  120. $this->setAPIResponse('error', $e->getMessage(), 500);
  121. return false;
  122. }
  123. $this->setAPIResponse('success', 'User has joined Emby', 200);
  124. return true;
  125. } catch (Requests_Exception $e) {
  126. $this->writeLog('error', 'Emby create Function - Error: ' . $e->getMessage(), 'SYSTEM');
  127. $this->setAPIResponse('error', $e->getMessage(), 500);
  128. return false;
  129. }
  130. }
  131. /*loads users from emby and returns a correctly formated policy for a new user.
  132. */
  133. public function getEmbyTemplateUserJson()
  134. {
  135. $headers = array(
  136. "Accept" => "application/json"
  137. );
  138. $data = array();
  139. $url = $this->config['embyURL'] . '/emby/Users?api_key=' . $this->config['embyToken'];
  140. $response = Requests::Get($url, $headers, array());
  141. $response = $response->body;
  142. $response = json_decode($response, true);
  143. //error_Log("response ".json_encode($response));
  144. $this->writeLog('error', 'userList:' . json_encode($response), 'SYSTEM');
  145. //$correct stores the template users object
  146. $correct = null;
  147. foreach ($response as $element) {
  148. if ($element['Name'] == $this->config['INVITES-EmbyTemplate']) {
  149. $correct = $element;
  150. }
  151. }
  152. $this->writeLog('error', 'Correct user:' . json_encode($correct), 'SYSTEM');
  153. if ($correct == null) {
  154. //return empty JSON if user incorrectly configured template
  155. return "{}";
  156. }
  157. //select policy section and remove possibly dangerous rows.
  158. $policy = $correct['Policy'];
  159. //writeLog('error', 'policy update'.$policy, 'SYSTEM');
  160. unset($policy['AuthenticationProviderId']);
  161. unset($policy['InvalidLoginAttemptCount']);
  162. unset($policy['DisablePremiumFeatures']);
  163. unset($policy['DisablePremiumFeatures']);
  164. return (json_encode($policy));
  165. }
  166. public function checkHostPrefix($s)
  167. {
  168. if (empty($s)) {
  169. return $s;
  170. }
  171. return (substr($s, -1, 1) == '\\') ? $s : $s . '\\';
  172. }
  173. public function approvedFileExtension($filename)
  174. {
  175. $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
  176. switch ($ext) {
  177. case 'gif':
  178. case 'png':
  179. case 'jpeg':
  180. case 'jpg':
  181. case 'svg':
  182. return true;
  183. break;
  184. default:
  185. return false;
  186. }
  187. }
  188. public function getImages()
  189. {
  190. $allIconsPrep = array();
  191. $allIcons = array();
  192. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id", "index.html");
  193. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  194. $path = 'plugins/images/tabs/';
  195. $images = scandir($dirname);
  196. foreach ($images as $image) {
  197. if (!in_array($image, $ignore)) {
  198. $allIconsPrep[$image] = array(
  199. 'path' => $path,
  200. 'name' => $image
  201. );
  202. }
  203. }
  204. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR;
  205. $path = 'plugins/images/userTabs/';
  206. $images = scandir($dirname);
  207. foreach ($images as $image) {
  208. if (!in_array($image, $ignore)) {
  209. $allIconsPrep[$image] = array(
  210. 'path' => $path,
  211. 'name' => $image
  212. );
  213. }
  214. }
  215. ksort($allIconsPrep);
  216. foreach ($allIconsPrep as $item) {
  217. $allIcons[] = $item['path'] . $item['name'];
  218. }
  219. return $allIcons;
  220. }
  221. public function imageSelect($form)
  222. {
  223. $i = 1;
  224. $images = $this->getImages();
  225. $return = '<select class="form-control tabIconImageList" id="' . $form . '-chooseImage" name="chooseImage"><option lang="en">Select or type Icon</option>';
  226. foreach ($images as $image) {
  227. $i++;
  228. $return .= '<option value="' . $image . '">' . basename($image) . '</option>';
  229. }
  230. return $return . '</select>';
  231. }
  232. public function getThemes()
  233. {
  234. $themes = array();
  235. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  236. $themes[] = array(
  237. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  238. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  239. );
  240. }
  241. return $themes;
  242. }
  243. public function getSounds()
  244. {
  245. $sounds = array();
  246. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  247. $sounds[] = array(
  248. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  249. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/default/' . basename($filename) . '.mp3')
  250. );
  251. }
  252. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  253. $sounds[] = array(
  254. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  255. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/custom/' . basename($filename) . '.mp3')
  256. );
  257. }
  258. return $sounds;
  259. }
  260. public function getBranches()
  261. {
  262. return array(
  263. array(
  264. 'name' => 'Develop',
  265. 'value' => 'v2-develop'
  266. ),
  267. array(
  268. 'name' => 'Master',
  269. 'value' => 'v2-master'
  270. )
  271. );
  272. }
  273. public function getAuthTypes()
  274. {
  275. return array(
  276. array(
  277. 'name' => 'Organizr DB',
  278. 'value' => 'internal'
  279. ),
  280. array(
  281. 'name' => 'Organizr DB + Backend',
  282. 'value' => 'both'
  283. ),
  284. array(
  285. 'name' => 'Backend Only',
  286. 'value' => 'external'
  287. )
  288. );
  289. }
  290. public function getLDAPOptions()
  291. {
  292. return array(
  293. array(
  294. 'name' => 'Active Directory',
  295. 'value' => '1'
  296. ),
  297. array(
  298. 'name' => 'OpenLDAP',
  299. 'value' => '2'
  300. ),
  301. array(
  302. 'name' => 'First IPA',
  303. 'value' => '3'
  304. ),
  305. );
  306. }
  307. public function getAuthBackends()
  308. {
  309. $backendOptions = array();
  310. $backendOptions[] = array(
  311. 'name' => 'Choose Backend',
  312. 'value' => false,
  313. 'disabled' => true
  314. );
  315. foreach (array_filter(get_class_methods('Organizr'), function ($v) {
  316. return strpos($v, 'plugin_auth_') === 0;
  317. }) as $value) {
  318. $name = str_replace('plugin_auth_', '', $value);
  319. if (strpos($name, 'disabled') === false) {
  320. $backendOptions[] = array(
  321. 'name' => ucwords(str_replace('_', ' ', $name)),
  322. 'value' => $name
  323. );
  324. } else {
  325. $backendOptions[] = array(
  326. 'name' => $this->$value(),
  327. 'value' => 'none',
  328. 'disabled' => true,
  329. );
  330. }
  331. }
  332. ksort($backendOptions);
  333. return $backendOptions;
  334. }
  335. public function importUserButtons()
  336. {
  337. $emptyButtons = '
  338. <div class="col-md-12">
  339. <div class="white-box bg-org">
  340. <h3 class="box-title m-0" lang="en">Currently User import is available for Plex only.</h3> </div>
  341. </div>
  342. ';
  343. $buttons = '';
  344. if (!empty($this->config['plexToken'])) {
  345. $buttons .= '<button class="btn m-b-20 m-r-20 bg-plex text-muted waves-effect waves-light importUsersButton" onclick="importUsers(\'plex\')" type="button"><span class="btn-label"><i class="mdi mdi-plex"></i></span><span lang="en">Import Plex Users</span></button>';
  346. }
  347. if (!empty($this->config['jellyfinURL']) && !empty($this->config['jellyfinToken'])) {
  348. $buttons .= '<button class="btn m-b-20 m-r-20 bg-primary text-muted waves-effect waves-light importUsersButton" onclick="importUsers(\'jellyfin\')" type="button"><span class="btn-label"><i class="mdi mdi-fish"></i></span><span lang="en">Import Jellyfin Users</span></button>';
  349. }
  350. if (!empty($this->config['embyURL']) && !empty($this->config['embyToken'])) {
  351. $buttons .= '<button class="btn m-b-20 m-r-20 bg-emby text-muted waves-effect waves-light importUsersButton" onclick="importUsers(\'emby\')" type="button"><span class="btn-label"><i class="mdi mdi-emby"></i></span><span lang="en">Import Emby Users</span></button>';
  352. }
  353. return ($buttons !== '') ? $buttons : $emptyButtons;
  354. }
  355. public function getHomepageMediaImage()
  356. {
  357. $refresh = false;
  358. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  359. if (!file_exists($cacheDirectory)) {
  360. mkdir($cacheDirectory, 0777, true);
  361. }
  362. @$image_url = $_GET['img'];
  363. @$key = $_GET['key'];
  364. @$image_height = $_GET['height'];
  365. @$image_width = $_GET['width'];
  366. @$source = $_GET['source'];
  367. @$itemType = $_GET['type'];
  368. if (strpos($key, '$') !== false) {
  369. $key = explode('$', $key)[0];
  370. $refresh = true;
  371. }
  372. switch ($source) {
  373. case 'plex':
  374. $plexAddress = $this->qualifyURL($this->config['plexURL']);
  375. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $this->config['plexToken'];
  376. break;
  377. case 'emby':
  378. $embyAddress = $this->qualifyURL($this->config['embyURL']);
  379. $imgParams = array();
  380. if (isset($_GET['height'])) {
  381. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  382. }
  383. if (isset($_GET['width'])) {
  384. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  385. }
  386. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  387. break;
  388. case 'jellyfin':
  389. $jellyfinAddress = $this->qualifyURL($this->config['jellyfinURL']);
  390. $imgParams = array();
  391. if (isset($_GET['height'])) {
  392. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  393. }
  394. if (isset($_GET['width'])) {
  395. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  396. }
  397. $image_src = $jellyfinAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  398. break;
  399. default:
  400. # code...
  401. break;
  402. }
  403. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  404. $cachefile = $cacheDirectory . $key . '.jpg';
  405. $cachetime = 604800;
  406. // Serve from the cache if it is younger than $cachetime
  407. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  408. header("Content-type: image/jpeg");
  409. @readfile($cachefile);
  410. exit;
  411. }
  412. ob_start(); // Start the output buffer
  413. header('Content-type: image/jpeg');
  414. $options = array('verify' => false);
  415. $response = Requests::get($image_src, array(), $options);
  416. if ($response->success) {
  417. echo $response->body;
  418. }
  419. // Cache the output to a file
  420. $fp = fopen($cachefile, 'wb');
  421. fwrite($fp, ob_get_contents());
  422. fclose($fp);
  423. ob_end_flush(); // Send the output to the browser
  424. die();
  425. } else {
  426. die("Invalid Request");
  427. }
  428. }
  429. public function cacheImage($url, $name, $extension = 'jpg')
  430. {
  431. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  432. if (!file_exists($cacheDirectory)) {
  433. mkdir($cacheDirectory, 0777, true);
  434. }
  435. $cacheFile = $cacheDirectory . $name . '.' . $extension;
  436. $cacheTime = 604800;
  437. if ((file_exists($cacheFile) && (time() - $cacheTime) > filemtime($cacheFile)) || !file_exists($cacheFile)) {
  438. @copy($url, $cacheFile);
  439. }
  440. }
  441. public function checkFrame($array, $url)
  442. {
  443. if (array_key_exists("x-frame-options", $array)) {
  444. if ($array['x-frame-options'] == "deny") {
  445. return false;
  446. } elseif ($array['x-frame-options'] == "sameorgin") {
  447. $digest = parse_url($url);
  448. $host = (isset($digest['host']) ? $digest['host'] : '');
  449. if ($this->getServer() == $host) {
  450. return true;
  451. } else {
  452. return false;
  453. }
  454. }
  455. } else {
  456. if (!$array) {
  457. return false;
  458. }
  459. return true;
  460. }
  461. }
  462. public function frameTest($url)
  463. {
  464. if (!$url || $url == '') {
  465. $this->setAPIResponse('error', 'URL not supplied', 404);
  466. return false;
  467. }
  468. $array = array_change_key_case(get_headers($this->qualifyURL($url), 1));
  469. $url = $this->qualifyURL($url);
  470. if ($this->checkFrame($array, $url)) {
  471. $this->setAPIResponse('success', 'URL approved for iFrame', 200);
  472. return true;
  473. } else {
  474. $this->setAPIResponse('error', 'URL failed approval for iFrame', 409);
  475. return false;
  476. }
  477. }
  478. public function groupSelect()
  479. {
  480. $groups = $this->getAllGroups();
  481. $select = array();
  482. foreach ($groups as $key => $value) {
  483. $select[] = array(
  484. 'name' => $value['group'],
  485. 'value' => $value['group_id']
  486. );
  487. }
  488. return $select;
  489. }
  490. public function showLogin()
  491. {
  492. if ($this->config['hideRegistration'] == false) {
  493. 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>';
  494. }
  495. }
  496. public function checkoAuth()
  497. {
  498. return $this->config['plexoAuth'] && $this->config['authBackend'] == 'plex' && $this->config['authType'] !== 'internal';
  499. }
  500. public function checkoAuthOnly()
  501. {
  502. return $this->config['plexoAuth'] && $this->config['authBackend'] == 'plex' && $this->config['authType'] == 'external';
  503. }
  504. public function showoAuth()
  505. {
  506. $buttons = '';
  507. if ($this->config['plexoAuth'] && $this->config['authBackend'] == 'plex' && $this->config['authType'] !== 'internal') {
  508. $buttons .= '<a href="javascript:void(0)" onclick="oAuthStart(\'plex\')" class="btn btn-lg btn-block text-uppercase waves-effect waves-light bg-plex text-muted" data-toggle="tooltip" title="" data-original-title="Login with Plex"> <span>Login</span><i aria-hidden="true" class="mdi mdi-plex m-l-5"></i> </a>';
  509. }
  510. return ($buttons) ? '
  511. <div class="panel">
  512. <div class="panel-heading bg-org" id="plex-login-heading" role="tab">
  513. <a class="panel-title" data-toggle="collapse" href="#plex-login-collapse" data-parent="#login-panels" aria-expanded="false" aria-controls="organizr-login-collapse">
  514. <img class="lazyload loginTitle" data-src="plugins/images/tabs/plex.png"> &nbsp;
  515. <span class="text-uppercase fw300" lang="en">Login with Plex</span>
  516. </a>
  517. </div>
  518. <div class="panel-collapse collapse in" id="plex-login-collapse" aria-labelledby="plex-login-heading" role="tabpanel">
  519. <div class="panel-body">
  520. <div class="row">
  521. <div class="col-xs-12 col-sm-12 col-md-12 text-center">
  522. <div class="social m-b-0">' . $buttons . '</div>
  523. </div>
  524. </div>
  525. </div>
  526. </div>
  527. </div>
  528. ' : '';
  529. }
  530. public function logoOrText()
  531. {
  532. if ($this->config['useLogoLogin'] == false) {
  533. return '<h1>' . $this->config['title'] . '</h1>';
  534. } else {
  535. return '<img class="loginLogo" src="' . $this->config['loginLogo'] . '" alt="Home" />';
  536. }
  537. }
  538. public function settingsDocker()
  539. {
  540. $type = ($this->docker) ? 'Official Docker' : 'Native';
  541. return '<li><div class="bg-info"><i class="mdi mdi-flag mdi-24px text-white"></i></div><span class="text-muted hidden-xs m-t-10" lang="en">Install Type</span> ' . $type . '</li>';
  542. }
  543. public function settingsPathChecks()
  544. {
  545. $paths = $this->pathsWritable($this->paths);
  546. $items = '';
  547. $type = (array_search(false, $paths)) ? 'Not Writable' : 'Writable';
  548. $result = '<li class="mouse" onclick="toggleWritableFolders();"><div class="bg-info"><i class="mdi mdi-folder mdi-24px text-white"></i></div><span class="text-muted hidden-xs m-t-10" lang="en">Organizr Paths</span> ' . $type . '</li>';
  549. foreach ($paths as $k => $v) {
  550. $items .= '<li class="folders-writable hidden"><div class="bg-primary"><i class="mdi mdi-folder mdi-24px text-white"></i></div><a tabindex="0" type="button" class="btn btn-default btn-outline popover-info pull-right clipboard" lang="en" data-container="body" title="" data-toggle="popover" data-placement="left" data-content="' . $v['path'] . '" data-original-title="File Path" data-clipboard-text="' . $v['path'] . '">' . $k . '</a> ' . (($v['writable']) ? 'Writable' : 'Not Writable') . '</li>';
  551. }
  552. return $result . $items;
  553. }
  554. public function pathsWritable($paths)
  555. {
  556. $results = array();
  557. foreach ($paths as $k => $v) {
  558. $results[$k] = [
  559. 'writable' => is_writable($v),
  560. 'path' => $v
  561. ];
  562. }
  563. return $results;
  564. }
  565. public function clearTautulliTokens()
  566. {
  567. foreach (array_keys($_COOKIE) as $k => $v) {
  568. if (strpos($v, 'tautulli') !== false) {
  569. $this->coookie('delete', $v);
  570. }
  571. }
  572. }
  573. public function clearJellyfinTokens()
  574. {
  575. foreach (array_keys($_COOKIE) as $k => $v) {
  576. if (strpos($v, 'user-') !== false) {
  577. $this->coookie('delete', $v);
  578. }
  579. }
  580. $this->coookie('delete', 'jellyfin_credentials');
  581. }
  582. public function analyzeIP($ip)
  583. {
  584. if (strpos($ip, '/') !== false) {
  585. $explodeIP = explode('/', $ip);
  586. $prefix = $explodeIP[1];
  587. $start_ip = $explodeIP[0];
  588. $ip_count = 1 << (32 - $prefix);
  589. $start_ip_long = ip2long($start_ip);
  590. $last_ip_long = ip2long($start_ip) + $ip_count - 1;
  591. } elseif (substr_count($ip, '.') == 3) {
  592. $start_ip_long = ip2long($ip);
  593. $last_ip_long = ip2long($ip);
  594. }
  595. return (isset($start_ip_long) && isset($last_ip_long)) ? array('from' => $start_ip_long, 'to' => $last_ip_long) : false;
  596. }
  597. public function authProxyRangeCheck($from, $to)
  598. {
  599. $approved = false;
  600. $userIP = ip2long($_SERVER['REMOTE_ADDR']);
  601. $low = $from;
  602. $high = $to;
  603. if ($userIP <= $high && $low <= $userIP) {
  604. $approved = true;
  605. }
  606. return $approved;
  607. }
  608. public function userDefinedIdReplacementLink($link, $variables)
  609. {
  610. return strtr($link, $variables);
  611. }
  612. public function requestOptions($url, $override = false, $timeout = null, $extras = null)
  613. {
  614. $options = [];
  615. if ($extras) {
  616. if (gettype($extras) == 'array') {
  617. $options = array_merge($options, $extras);
  618. }
  619. }
  620. if (is_numeric($timeout)) {
  621. $timeout = $timeout / 1000;
  622. $options = array_merge($options, array('timeout' => $timeout));
  623. }
  624. if ($this->localURL($url, $override)) {
  625. $options = array_merge($options, array('verify' => false));
  626. }
  627. return $options;
  628. }
  629. }