Browse Source

covert local IP Range to IP Listing with multiple values

CauseFX 4 years ago
parent
commit
53453a9f53
4 changed files with 41 additions and 18 deletions
  1. 1 16
      api/classes/organizr.class.php
  2. 1 0
      api/config/default.php
  3. 37 1
      api/functions/normal-functions.php
  4. 2 1
      js/functions.js

+ 1 - 16
api/classes/organizr.class.php

@@ -2612,22 +2612,7 @@ class Organizr
 					'help' => 'Default status of Remember Me button on login screen',
 					'value' => $this->config['rememberMe'],
 				),
-				array(
-					'type' => 'input',
-					'name' => 'localIPFrom',
-					'label' => 'Override Local IP From',
-					'value' => $this->config['localIPFrom'],
-					'placeholder' => 'i.e. 123.123.123.123',
-					'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
-				),
-				array(
-					'type' => 'input',
-					'name' => 'localIPTo',
-					'label' => 'Override Local IP To',
-					'value' => $this->config['localIPTo'],
-					'placeholder' => 'i.e. 123.123.123.123',
-					'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
-				),
+				$this->settingsOption('multiple-url', 'localIPList', ['label' => 'Override Local IP', 'placeholder' => 'i.e. 123.123.123.123', 'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To']),
 				array(
 					'type' => 'input',
 					'name' => 'wanDomain',

+ 1 - 0
api/config/default.php

@@ -409,6 +409,7 @@ return [
 	'overseerrLimit' => '50',
 	'localIPFrom' => '',
 	'localIPTo' => '',
+	'localIPList' => '',
 	'sandbox' => 'allow-presentation,allow-forms,allow-same-origin,allow-pointer-lock,allow-scripts,allow-popups,allow-modals,allow-top-navigation,allow-downloads,allow-orientation-lock,allow-popups-to-escape-sandbox,allow-top-navigation-by-user-activation',
 	'description' => 'Organizr - Accept no others',
 	'debugErrors' => false,

+ 37 - 1
api/functions/normal-functions.php

@@ -488,6 +488,27 @@ trait NormalFunctions
 		}
 	}
 	
+	public function convertIPToRange($ip)
+	{
+		if (strpos($ip, '/') !== false) {
+			$explodeIP = explode('/', $ip);
+			$prefix = $explodeIP[1];
+			$start_ip = $explodeIP[0];
+			$ip_count = 1 << (32 - $prefix);
+			$start_ip_long = long2ip(ip2long($start_ip));
+			$last_ip_long = long2ip(ip2long($start_ip) + $ip_count - 1);
+		} elseif (substr_count($ip, '.') == 3) {
+			$start_ip_long = long2ip(ip2long($ip));
+			$last_ip_long = long2ip(ip2long($ip));
+		} else {
+			return false;
+		}
+		return [
+			'from' => $start_ip_long,
+			'to' => $last_ip_long
+		];
+	}
+	
 	public function localIPRanges()
 	{
 		$mainArray = array(
@@ -508,7 +529,20 @@ trait NormalFunctions
 				'to' => '127.255.255.255'
 			),
 		);
-		$override = false;
+		if (isset($this->config['localIPList'])) {
+			if ($this->config['localIPList'] !== '') {
+				$ipListing = explode(',', $this->config['localIPList']);
+				if (count($ipListing) > 0) {
+					foreach ($ipListing as $ip) {
+						$ipInfo = $this->convertIPToRange($ip);
+						if ($ipInfo) {
+							array_push($mainArray, $ipInfo);
+						}
+					}
+				}
+			}
+		}
+		/*
 		if ($this->config['localIPFrom']) {
 			$from = trim($this->config['localIPFrom']);
 			$override = true;
@@ -516,6 +550,7 @@ trait NormalFunctions
 		if ($this->config['localIPTo']) {
 			$to = trim($this->config['localIPTo']);
 		}
+		
 		if ($override) {
 			$newArray = array(
 				'from' => $from,
@@ -523,6 +558,7 @@ trait NormalFunctions
 			);
 			array_push($mainArray, $newArray);
 		}
+		*/
 		return $mainArray;
 	}
 	

+ 2 - 1
js/functions.js

@@ -9626,11 +9626,12 @@ function checkLocalForwardStatus(array){
                 if(activeInfo.settings.user.local && currentSite.indexOf(remoteSite) !== -1 && currentURL.indexOf('override') === -1){
 	                organizrConsole('Organizr Function','Local Login Status: Local | Forwarding Now');
                     window.location = localSite;
+                }else{
+	                organizrConsole('Organizr Function','Local Login Status: Not Local or Override was set - Ignoring Forward Request');
                 }
             } catch(e) {
                 console.error(e);
             }
-	        organizrConsole('Organizr Function','Local Login Status: Not Local');
         }
     }
 }