Browse Source

added ombi user fallback settings

CauseFX 5 years ago
parent
commit
213288726b
4 changed files with 44 additions and 5 deletions
  1. 13 0
      api/classes/organizr.class.php
  2. 2 0
      api/config/default.php
  3. 15 4
      api/functions/sso-functions.php
  4. 14 1
      api/homepage/ombi.php

+ 13 - 0
api/classes/organizr.class.php

@@ -2282,6 +2282,19 @@ class Organizr
 					'label' => 'Token',
 					'value' => $this->config['ombiToken']
 				),
+				array(
+					'type' => 'input',
+					'name' => 'ombiFallbackUser',
+					'label' => 'Ombi Fallback User',
+					'value' => $this->config['ombiFallbackUser'],
+					'help' => 'Organizr will request an Ombi User Token based off of this user credentials'
+				),
+				array(
+					'type' => 'password-alt',
+					'name' => 'ombiFallbackPassword',
+					'label' => 'Ombi Fallback Password',
+					'value' => $this->config['ombiFallbackPassword']
+				),
 				array(
 					'type' => 'switch',
 					'name' => 'ssoOmbi',

+ 2 - 0
api/config/default.php

@@ -51,6 +51,8 @@ return array(
 	'ombiURL' => '',
 	'ombiToken' => '',
 	'ombiAlias' => false,
+	'ombiFallbackUser' => '',
+	'ombiFallbackPassword' => '',
 	'ssoPlex' => false,
 	'ssoOmbi' => false,
 	'ssoTautulli' => false,

+ 15 - 4
api/functions/sso-functions.php

@@ -9,7 +9,8 @@ trait SSOFunctions
 			$this->coookie('set', 'mpt', $token, $this->config['rememberMeDays'], false);
 		}
 		if ($this->config['ssoOmbi']) {
-			$ombiToken = $this->getOmbiToken($username, $password, $token);
+			$fallback = ($this->config['ombiFallbackUser'] !== '' && $this->config['ombiFallbackPassword'] !== '');
+			$ombiToken = $this->getOmbiToken($username, $password, $token, $fallback);
 			if ($ombiToken) {
 				$this->coookie('set', 'Auth', $ombiToken, $this->config['rememberMeDays'], false);
 			}
@@ -25,7 +26,7 @@ trait SSOFunctions
 		return true;
 	}
 	
-	public function getOmbiToken($username, $password, $oAuthToken = null)
+	public function getOmbiToken($username, $password, $oAuthToken = null, $fallback = false)
 	{
 		$token = null;
 		try {
@@ -47,12 +48,22 @@ trait SSOFunctions
 				$token = json_decode($response->body, true)['access_token'];
 				$this->writeLog('success', 'Ombi Token Function - Grabbed token.', $username);
 			} else {
-				$this->writeLog('error', 'Ombi Token Function - Ombi did not return Token', $username);
+				if ($fallback) {
+					$this->writeLog('error', 'Ombi Token Function - Ombi did not return Token - Will retry using fallback credentials', $username);
+				} else {
+					$this->writeLog('error', 'Ombi Token Function - Ombi did not return Token', $username);
+				}
 			}
 		} catch (Requests_Exception $e) {
 			$this->writeLog('error', 'Ombi Token Function - Error: ' . $e->getMessage(), $username);
 		}
-		return ($token) ? $token : false;
+		if ($token) {
+			return $token;
+		} elseif ($fallback) {
+			return $this->getOmbiToken($this->config['ombiFallbackUser'], $this->decrypt($this->config['ombiFallbackPassword']), null, false);
+		} else {
+			return false;
+		}
 	}
 	
 	public function getTautulliToken($username, $password, $plexToken = null)

+ 14 - 1
api/homepage/ombi.php

@@ -40,7 +40,20 @@ trait OmbiHomepageItem
 						'name' => 'ombiToken',
 						'label' => 'Token',
 						'value' => $this->config['ombiToken']
-					)
+					),
+					array(
+						'type' => 'input',
+						'name' => 'ombiFallbackUser',
+						'label' => 'Ombi Fallback User',
+						'value' => $this->config['ombiFallbackUser'],
+						'help' => 'Organizr will request an Ombi User Token based off of this user credentials'
+					),
+					array(
+						'type' => 'password-alt',
+						'name' => 'ombiFallbackPassword',
+						'label' => 'Ombi Fallback Password',
+						'value' => $this->config['ombiFallbackPassword']
+					),
 				),
 				'Misc Options' => array(
 					array(