' . $title . '
' . $notice . '
' . $closeMessage . '0) { foreach ($files as $file) { if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'js') { $scripts .= $this->loadJavaResource($file, $rootPath); } elseif (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'css') { $scripts .= $this->loadStyleResource($file, $rootPath); } } } return $scripts; } public function loadJavaResource($file = '', $rootPath = '') { return ($file !== '') ? '' . "\n" : ''; } public function loadStyleResource($file = '', $rootPath = '') { return ($file !== '') ? '' . "\n" : ''; } public function loadDefaultJavascriptFiles() { $javaFiles = [ 'js/jquery-2.2.4.min.js', 'bootstrap/dist/js/bootstrap.min.js', 'plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.js', 'js/jquery.slimscroll.js', 'plugins/bower_components/styleswitcher/jQuery.style.switcher.js', 'plugins/bower_components/moment/moment.js', 'plugins/bower_components/moment/moment-timezone.js', 'plugins/bower_components/jquery-wizard-master/dist/jquery-wizard.min.js', 'plugins/bower_components/jquery-wizard-master/libs/formvalidation/formValidation.min.js', 'plugins/bower_components/jquery-wizard-master/libs/formvalidation/bootstrap.min.js', 'js/bowser.min.js', 'js/jasny-bootstrap.js' ]; $scripts = ''; foreach ($javaFiles as $file) { $scripts .= '' . "\n"; } return $scripts; } public function loadJavascriptFile($file) { return '\n"; } public function embyJoinAPI($array) { $username = ($array['username']) ?? null; $email = ($array['email']) ?? null; $password = ($array['password']) ?? null; if (!$username) { $this->setAPIResponse('error', 'Username not supplied', 422); return false; } if (!$email) { $this->setAPIResponse('error', 'Email not supplied', 422); return false; } if (!$password) { $this->setAPIResponse('error', 'Password not supplied', 422); return false; } return $this->embyJoin($username, $email, $password); } public function embyJoin($username, $email, $password) { try { #create user in emby. $headers = array( "Accept" => "application/json" ); $data = array(); $url = $this->config['embyURL'] . '/emby/Users/New?name=' . $username . '&api_key=' . $this->config['embyToken']; $response = Requests::Post($url, $headers, json_encode($data), array()); $response = $response->body; //return($response); $response = json_decode($response, true); //return($response); $userID = $response["Id"]; //return($userID); #authenticate as user to update password. //randomizer four digits of DeviceId // I dont think ther would be security problems with hardcoding deviceID but randomizing it would mitigate any issue. $deviceIdSeceret = rand(0, 9) . "" . rand(0, 9) . "" . rand(0, 9) . "" . rand(0, 9); //hardcoded device id with the first three digits random 0-9,0-9,0-9,0-9 $embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", DeviceId="' . $deviceIdSeceret . 'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"'; $headers = array( "Accept" => "application/json", "Content-Type" => "application/json", "X-Emby-Authorization" => $embyAuthHeader ); $data = array( "Pw" => "", "Username" => $username ); $url = $this->config['embyURL'] . '/emby/Users/AuthenticateByName'; $response = Requests::Post($url, $headers, json_encode($data), array()); $response = $response->body; $response = json_decode($response, true); $userToken = $response["AccessToken"]; #update password $embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", Token="' . $userToken . '", DeviceId="' . $deviceIdSeceret . 'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"'; $headers = array( "Accept" => "application/json", "Content-Type" => "application/json", "X-Emby-Authorization" => $embyAuthHeader ); $data = array( "CurrentPw" => "", "NewPw" => $password, "Id" => $userID ); $url = $this->config['embyURL'] . '/emby/Users/' . $userID . '/Password'; Requests::Post($url, $headers, json_encode($data), array()); #update config $headers = array( "Accept" => "application/json", "Content-Type" => "application/json" ); $url = $this->config['embyURL'] . '/emby/Users/' . $userID . '/Policy?api_key=' . $this->config['embyToken']; $response = Requests::Post($url, $headers, $this->getEmbyTemplateUserJson(), array()); #add emby.media try { #seperate because this is not required $headers = array( "Accept" => "application/json", "X-Emby-Authorization" => $embyAuthHeader ); $data = array( "ConnectUsername " => $email ); $url = $this->config['embyURL'] . '/emby/Users/' . $userID . '/Connect/Link'; Requests::Post($url, $headers, json_encode($data), array()); } catch (Requests_Exception $e) { $this->setLoggerChannel('Emby')->error($e); $this->setResponse(500, $e->getMessage()); return false; } $this->setAPIResponse('success', 'User has joined Emby', 200); return true; } catch (Requests_Exception $e) { $this->setLoggerChannel('Emby')->error($e); $this->setResponse(500, $e->getMessage()); return false; } } /*loads users from emby and returns a correctly formated policy for a new user. */ public function getEmbyTemplateUserJson() { $headers = array( "Accept" => "application/json" ); $data = array(); $url = $this->config['embyURL'] . '/emby/Users?api_key=' . $this->config['embyToken']; $response = Requests::Get($url, $headers, array()); $response = $response->body; $response = json_decode($response, true); //$correct stores the template users object $correct = null; foreach ($response as $element) { if ($element['Name'] == $this->config['INVITES-EmbyTemplate']) { $correct = $element; } } if ($correct == null) { //return empty JSON if user incorrectly configured template return "{}"; } //select policy section and remove possibly dangerous rows. $policy = $correct['Policy']; unset($policy['AuthenticationProviderId']); unset($policy['InvalidLoginAttemptCount']); unset($policy['DisablePremiumFeatures']); unset($policy['DisablePremiumFeatures']); return (json_encode($policy)); } public function checkHostPrefix($s) { if (empty($s)) { return $s; } return (substr($s, -1, 1) == '\\') ? $s : $s . '\\'; } public function approvedFileExtension($filename, $type = 'image') { $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if ($type == 'image') { switch ($ext) { case 'gif': case 'png': case 'jpeg': case 'jpg': return true; default: return false; } } elseif ($type == 'cert') { switch ($ext) { case 'pem': return true; default: return false; } } } public function approvedFileType($file, $type = 'image') { $finfo = new finfo(FILEINFO_MIME_TYPE); $ext = $finfo->file($file); if ($type == 'image') { switch ($ext) { case 'image/gif': case 'image/png': case 'image/jpeg': case 'image/pjpeg': return true; default: return false; } } return false; } public function getImages() { $allIconsPrep = array(); $allIcons = array(); $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id", "index.html"); $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR; $path = 'plugins/images/tabs/'; $images = scandir($dirname); foreach ($images as $image) { if (!in_array($image, $ignore)) { $allIconsPrep[$image] = array( 'path' => $path, 'name' => $image ); } } $dirname = $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR; $path = 'data/userTabs/'; $images = scandir($dirname); foreach ($images as $image) { if (!in_array($image, $ignore)) { $allIconsPrep[$image] = array( 'path' => $path, 'name' => $image ); } } ksort($allIconsPrep); foreach ($allIconsPrep as $item) { $allIcons[] = $item['path'] . $item['name']; } return $allIcons; } public function imageSelect($form) { $i = 1; $images = $this->getImages(); $return = ''; } public function getThemes() { $themes = array(); foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) { $themes[] = array( 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)), 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)) ); } return $themes; } public function getSounds() { $sounds = array(); foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) { $sounds[] = array( 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)), 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/default/' . basename($filename) . '.mp3') ); } foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) { $sounds[] = array( 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)), 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/custom/' . basename($filename) . '.mp3') ); } return $sounds; } public function getBranches() { return array( array( 'name' => 'Develop', 'value' => 'v2-develop' ), array( 'name' => 'Master', 'value' => 'v2-master' ) ); } public function getSettingsTabs() { return array( array( 'name' => 'Tab Editor', 'value' => '0' ), array( 'name' => 'Customize', 'value' => '1' ), array( 'name' => 'User Management', 'value' => '2' ), array( 'name' => 'Image Manager', 'value' => '3' ), array( 'name' => 'Plugins', 'value' => '4' ), array( 'name' => 'System Settings', 'value' => '5' ) ); } public function getAuthTypes() { return array( array( 'name' => 'Organizr DB', 'value' => 'internal' ), array( 'name' => 'Organizr DB + Backend', 'value' => 'both' ), array( 'name' => 'Backend Only', 'value' => 'external' ) ); } public function getLDAPOptions() { return array( array( 'name' => 'Active Directory', 'value' => '1' ), array( 'name' => 'OpenLDAP', 'value' => '2' ), array( 'name' => 'Free IPA', 'value' => '3' ), ); } public function getAuthBackends() { $backendOptions = array(); $backendOptions[] = array( 'name' => 'Choose Backend', 'value' => false, 'disabled' => true ); foreach (array_filter(get_class_methods('Organizr'), function ($v) { return strpos($v, 'plugin_auth_') === 0; }) as $value) { $name = str_replace('plugin_auth_', '', $value); if ($name == 'ldap') { if (!function_exists('ldap_connect')) { continue; } } if ($name == 'ldap_disabled') { if (function_exists('ldap_connect')) { continue; } } if (strpos($name, 'disabled') === false) { $backendOptions[] = array( 'name' => ucwords(str_replace('_', ' ', $name)), 'value' => $name ); } else { $backendOptions[] = array( 'name' => $this->$value(), 'value' => 'none', 'disabled' => true, ); } } ksort($backendOptions); return $backendOptions; } public function importUserButtons() { $emptyButtons = '
Don\'t have an account?Sign Up
'; } } public function checkoAuth() { return $this->config['plexoAuth'] && $this->config['authBackend'] == 'plex' && $this->config['authType'] !== 'internal'; } public function checkoAuthOnly() { return $this->config['plexoAuth'] && $this->config['authBackend'] == 'plex' && $this->config['authType'] == 'external'; } public function showoAuth() { $buttons = ''; if ($this->config['plexoAuth'] && $this->config['authBackend'] == 'plex' && $this->config['authType'] !== 'internal') { $buttons .= ' Login '; } return ($buttons) ? ' ' : ''; } public function logoOrText() { $showLogo = $this->config['minimalLoginScreen'] ? '' : 'visible-xs'; if ($this->config['useLogoLogin'] == false) { $html = '(This window will close automatically)
' : ''; return '' . $notice . '
' . $closeMessage . '