Pārlūkot izejas kodu

add ombi v3 work

causefx 8 gadi atpakaļ
vecāks
revīzija
c44ae7f099
6 mainītis faili ar 96 papildinājumiem un 4 dzēšanām
  1. 1 0
      .gitignore
  2. 3 0
      config/configDefaults.php
  3. 21 4
      functions.php
  4. 22 0
      index.php
  5. 31 0
      settings.php
  6. 18 0
      user.php

+ 1 - 0
.gitignore

@@ -71,3 +71,4 @@ images/cache/*
 backups/*
 backups/
 backups
+test*.php

+ 3 - 0
config/configDefaults.php

@@ -47,6 +47,9 @@ return array(
 	"sabnzbdURL" => "",
 	"sabnzbdKey" => "",
 	"sabnzbdHomeAuth" => false,
+	"ombiURL" => "",
+	"ombiKey" => "",
+	"ombiAuth" => false,
 	"headphonesURL" => "",
 	"headphonesKey" => "",
 	"headphonesHomeAuth" => false,

+ 21 - 4
functions.php

@@ -193,9 +193,11 @@ if (function_exists('curl_version')) :
 	// Pass credentials to Plex Backend
 	function plugin_auth_plex($username, $password) {
 		// Quick out
+		$isAdmin = false;
 		if ((strtolower(PLEXUSERNAME) == strtolower($username)) && $password == PLEXPASSWORD) {
-   			writeLog("success", $username." authenticated by plex");
-			return true;
+   			writeLog("success", "Admin: ".$username." authenticated by plex");
+			//return true;
+			$isAdmin = true;
 		}
 
 		//Get User List
@@ -217,7 +219,7 @@ if (function_exists('curl_version')) :
 				}
 			}
 
-			if ($isUser) {
+			if ($isUser || $isAdmin) {
 				//Login User
 				$connectURL = 'https://plex.tv/users/sign_in.json';
 				$headers = array(
@@ -238,7 +240,8 @@ if (function_exists('curl_version')) :
 						writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
                         return array(
 							'email' => $json['user']['email'],
-							'image' => $json['user']['thumb']
+							'image' => $json['user']['thumb'],
+							'token' => $json['user']['authToken']
 						);
 					}
 				}
@@ -4693,6 +4696,20 @@ function q2a($q){
 	}
 }
 
+function getOmbiToken($username, $password){
+	$headers = array(
+		"Accept" => "application/json",
+		"Content-Type" => "application/json"
+	);
+	$json = array(
+		"username" => $username,
+        "password" => $password,
+		"rememberMe" => "true",
+         );
+	$api = curl_post(OMBIURL."/api/v1/Token", $json, $headers);
+    return json_decode($api['content'], true)['access_token'];
+}
+
 class Mobile_Detect
 {
     /**

+ 22 - 0
index.php

@@ -1330,6 +1330,28 @@ $group = (isset($group) ? $group : "guest");
 		<script src="<?=$baseURL;?>js/mousetrap.min.js"></script>
 		<script src="<?=$baseURL;?>js/jquery.simpleWeather.js"></script>
 		<script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
+		<script>
+		function getCookie(cname) {
+			var name = cname + "=";
+			var decodedCookie = decodeURIComponent(document.cookie);
+			var ca = decodedCookie.split(';');
+			for(var i = 0; i <ca.length; i++) {
+				var c = ca[i];
+				while (c.charAt(0) == ' ') {
+					c = c.substring(1);
+				}
+				if (c.indexOf(name) == 0) {
+					return c.substring(name.length, c.length);
+				}
+			}
+			return "";
+		}
+		if (localStorageSupport) {
+			if(getCookie('mpt') !== ''){
+				localStorage.setItem("myPlexAccessToken",getCookie('mpt'));
+			}
+		}
+		</script>
 		<?php if(CHAT == "true" && qualifyUser(CHATAUTH)){?>
 			<script src="chatjs.php" defer="true"></script>
 			<script type="text/javascript">

+ 31 - 0
settings.php

@@ -1477,6 +1477,37 @@ echo buildSettings(
 					),
 				),
 			),
+			array(
+				'title' => 'Ombi',
+				'id' => 'ombiSettings',
+				'image' => 'images/ombi.png',
+				'fields' => array(
+					array(
+						'type' => $userSelectType,
+						'labelTranslate' => 'SHOW_ON_HOMEPAGE',
+						'name' => 'ombiAuth',
+						'value' => OMBIAUTH,
+						'options' => $userTypes,
+					),
+					array(
+						'type' => 'text',
+						'placeholder' => 'http://hostname:5000',
+						'labelTranslate' => 'OMBI_URL',
+						'assist' => 'http://hostname:5000 | http://hostname/ombi | http://hostname:5000/ombi',
+						'name' => 'ombiURL',
+						'pattern' => $urlPattern,
+						'value' => OMBIURL,
+					),
+					array(
+						'type' => 'text',
+						'placeholder' => randString(32),
+						'labelTranslate' => 'OMBI_KEY',
+						'name' => 'ombiKey',
+						'value' => OMBIKEY,
+					),
+
+				),
+			),
 			array(
 				'title' => 'Speed Test',
 				'id' => 'speedTestSettings',

+ 18 - 0
user.php

@@ -417,6 +417,9 @@
             unset($_COOKIE['cookiePassword']);
             setcookie("cookiePassword", '', time() - 3600, '/', DOMAIN);
             setcookie("cookiePassword", '', time() - 3600, '/');
+			unset($_COOKIE['Auth']);
+            setcookie("Auth", '', time() - 3600, '/', DOMAIN);
+            setcookie("Auth", '', time() - 3600, '/');
 		}
 		/**
 		 * Validate a username. Empty usernames or names
@@ -469,6 +472,9 @@
                         unset($_COOKIE['cookiePassword']);
                         setcookie("cookiePassword", '', time() - 3600, '/', DOMAIN);
                         setcookie("cookiePassword", '', time() - 3600, '/');
+						unset($_COOKIE['Auth']);
+			            setcookie("Auth", '', time() - 3600, '/', DOMAIN);
+			            setcookie("Auth", '', time() - 3600, '/');
                         return false;
                     }
                 }else{
@@ -665,6 +671,15 @@
 						setcookie("OrganizrU", $username, time() + (86400 * 7), "/", DOMAIN);
 
 					}
+					if(OMBIURL){
+						$ombiToken = getOmbiToken($username, $password);
+						if($ombiToken){
+							setcookie("Auth", $ombiToken, time() + (86400 * 7), "/", DOMAIN);
+						}
+					}
+					if(PLEXURL && isset($authSuccess['token'])){
+						setcookie("mpt", $authSuccess['token'], time() + (86400 * 7), "/", DOMAIN);
+					}
 					$this->info("Welcome $username");
 					file_put_contents(FAIL_LOG, $buildLog($username, "good_auth"));
 					chmod(FAIL_LOG, 0660);
@@ -790,6 +805,9 @@
             unset($_COOKIE['cookiePassword']);
             setcookie("cookiePassword", '', time() - 3600, '/', DOMAIN);
             setcookie("cookiePassword", '', time() - 3600, '/');
+			unset($_COOKIE['Auth']);
+            setcookie("Auth", '', time() - 3600, '/', DOMAIN);
+            setcookie("Auth", '', time() - 3600, '/');
    			writeLog("success", "$username has signed out");
 			return true;
 		}