Explorar o código

added bypass login for local access

CauseFX hai 1 ano
pai
achega
bc261ad31b

+ 29 - 3
api/classes/organizr.class.php

@@ -92,6 +92,7 @@ class Organizr
 	public $paths;
 	public $checkForUpdates;
 	public $groupOptions;
+	public $userOptions;
 	public $warnings;
 	public $errors;
 	public bool $loggerSetup = false;
@@ -2458,6 +2459,8 @@ class Organizr
 				$this->settingsOption('switch', 'enableLocalAddressForward', ['label' => 'Enable Local Address Forward', 'help' => 'Enables the local address forward if on local address and accessed from WAN Domain']),
 				$this->settingsOption('switch', 'disableRecoverPass', ['label' => 'Disable Recover Password', 'help' => 'Disables recover password area']),
 				$this->settingsOption('input', 'customForgotPassText', ['label' => 'Custom Recover Password Text', 'help' => 'Text or HTML for recovery password section']),
+				$this->settingsOption('switch', 'bypassLoginForLocal', ['label' => 'Bypass Login For Local Access', 'help' => 'Disables login and logs user in with default User Id']),
+				$this->settingsOption('orguser', 'localLoginUserId', ['label' => 'Local User Id', 'help' => 'User Id to login the user when bypassing login']),
 			],
 			'Auth Proxy' => [
 				$this->settingsOption('switch', 'authProxyEnabled', ['label' => 'Auth Proxy', 'help' => 'Enable option to set Auth Proxy Header Login']),
@@ -3673,6 +3676,19 @@ class Organizr
 
 	public function login($array)
 	{
+		// Bypass Check
+		$bypassLogin = $this->config['bypassLoginForLocal'] && $this->config['localLoginUserId'] && $this->isLocal() == true;
+		if(gettype($array) == 'array'){
+			if(key_exists('bypass', $array)){
+				$bypassLogin = false;
+			}
+			if(key_exists('username', $array)){
+				$bypassLogin = false;
+			}
+			if(key_exists('oAuth', $array)){
+				$bypassLogin = false;
+			}
+		}
 		// Grab username, Password & other optional items from api call
 		$username = $array['username'] ?? null;
 		$password = $array['password'] ?? null;
@@ -3722,7 +3738,7 @@ class Organizr
 			}
 		}
 		// Check if Login method was an oAuth login
-		if (!$oAuth) {
+		if (!$oAuth && !$bypassLogin) {
 			$result = $this->getUserByUsernameAndEmail($username, $username);
 			$result['password'] = $result['password'] ?? '';
 			// Switch AuthType - internal - external - both
@@ -3748,6 +3764,10 @@ class Organizr
 					}
 			}
 			$authSuccess = ($authProxy) ? $addEmailToAuthProxy : $authSuccess;
+		} elseif ($bypassLogin){
+			$id = $this->config['localLoginUserId'];
+			$result = $this->getUserById($id);
+			$authSuccess = true;
 		} else {
 			// Has oAuth Token!
 			switch ($oAuthType) {
@@ -3794,7 +3814,7 @@ class Organizr
 			}
 			if ($userExists) {
 				//does org password need to be updated
-				if (!$passwordMatches) {
+				if (!$passwordMatches && $password) {
 					$this->updateUserPassword($password, $result['id']);
 					$this->setLoggerChannel('Authentication', $username);
 					$this->logger->info('User Password updated from backend');
@@ -4409,7 +4429,8 @@ class Organizr
 				'agent' => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null,
 				'oAuthLogin' => isset($_COOKIE['oAuth']),
 				'local' => $this->isLocal(),
-				'ip' => $this->userIP()
+				'ip' => $this->userIP(),
+				'bypass' => $this->config['bypassLoginForLocal'] && $this->config['localLoginUserId'] && $this->isLocal() == true
 			],
 			'login' => [
 				'rememberMe' => $this->config['rememberMe'],
@@ -4800,6 +4821,11 @@ class Organizr
 		$this->groupOptions = $this->groupSelect();
 	}
 
+	public function setUserOptionsVariable()
+	{
+		$this->userOptions = $this->userSelect();
+	}
+
 	public function getSettingsHomepageItem($item)
 	{
 		$items = $this->getSettingsHomepage();

+ 3 - 1
api/config/default.php

@@ -709,5 +709,7 @@ return [
 	'homepageUptimeKumaShowLatency' => true,
 	'checkForUpdate' => true,
 	'socksDebug' => false,
-	'maxSocksDebugSize' => 100
+	'maxSocksDebugSize' => 100,
+	'bypassLoginForLocal' => false,
+	'localLoginUserId' => "1"
 ];

+ 8 - 0
api/functions/option-functions.php

@@ -23,6 +23,14 @@ trait OptionsFunction
 			'value' => $this->config[$name] ?? ''
 		];
 		switch ($type) {
+			case 'orguser':
+				$this->setUserOptionsVariable();
+				$settingMerge = [
+					'type' => 'select',
+					'label' => 'Organizr User',
+					'options' => $this->userOptions
+				];
+				break;
 			case 'enable':
 				$settingMerge = [
 					'type' => 'switch',

+ 13 - 0
api/functions/organizr-functions.php

@@ -638,6 +638,19 @@ trait OrganizrFunctions
 		return $select;
 	}
 
+	public function userSelect()
+	{
+		$users = $this->getAllUsers();
+		$select = [];
+		foreach ($users as $key => $value) {
+			$select[] = array(
+				'name' => $value['username'],
+				'value' => $value['id']
+			);
+		}
+		return $select;
+	}
+
 	public function showLogin()
 	{
 		if ($this->config['hideRegistration'] == false) {

+ 20 - 3
js/functions.js

@@ -11952,7 +11952,16 @@ function showPlexMachineForm(selector = null){
 		})
 	);
 }
-function oAuthLoginNeededCheck() {
+function bypassLocalLogin() {
+
+	if(activeInfo.settings.user.bypass !== true){
+		return false;
+	}
+	console.log('run test')
+	OAuthLoginNeeded = true;
+	oAuthLoginNeededCheck('Bypass');
+}
+function oAuthLoginNeededCheck(type = "OAuth") {
     if(OAuthLoginNeeded == false){
         return false;
     }else{
@@ -11960,8 +11969,15 @@ function oAuthLoginNeededCheck() {
             return false;
         }
     }
-    message('OAuth', ' Proceeding to login', activeInfo.settings.notifications.position, '#FFF', 'info', '10000');
-    organizrAPI2('POST', 'api/v2/login', '').success(function (data) {
+	let data = '';
+	if(type === 'Bypass'){
+		const bypass = $.urlParam('bypassDisable');
+		if(bypass){
+			data = 'bypass';
+		}
+	}
+    message(type, ' Proceeding to login', activeInfo.settings.notifications.position, '#FFF', 'info', '10000');
+    organizrAPI2('POST', 'api/v2/login', data).success(function (data) {
 	    local('set','message','Welcome|Login Successful|success');
 	    local('r','loggingIn');
 	    location.reload();
@@ -12505,6 +12521,7 @@ function launch(){
 	        }
 	        console.info("%c Organizr %c ".concat("DOM Fully loaded", " "), "color: white; background: #AD80FD; font-weight: 700;", "color: #AD80FD; background: white; font-weight: 700;");
 	        oAuthLoginNeededCheck();
+			bypassLocalLogin();
         } catch (e) {
             orgErrorCode(data);
             defineNotification();