From 23f608e173fed01b4bfe8f10fcc9851ef722d196 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Fri, 31 Dec 2021 06:12:38 +0000 Subject: [PATCH] Everything IP! Updated IpRange to fix an undefined index (where it tried to convert an IP to a ip/bits format but some didn't contain that, so absolute ip addresses will just have /32 appended) Implemented the logic into WebContextManager.php --- globals/Dependencies/Web/IpRange.php | 3 +++ globals/Dependencies/Web/WebContextManager.php | 3 ++- globals/config.php | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/globals/Dependencies/Web/IpRange.php b/globals/Dependencies/Web/IpRange.php index 9d04ec0..1b75d4a 100644 --- a/globals/Dependencies/Web/IpRange.php +++ b/globals/Dependencies/Web/IpRange.php @@ -182,6 +182,9 @@ namespace Alphaland\Web { */ public static function IsIpInCidrRange(string $ip, string $cidr) { + if (strpos($cidr, '/') === false) + $cidr = "$cidr/32"; + list($subnet, $bits) = explode('/', $cidr); if ($bits === null) { $bits = 32; diff --git a/globals/Dependencies/Web/WebContextManager.php b/globals/Dependencies/Web/WebContextManager.php index 5201449..44da04e 100644 --- a/globals/Dependencies/Web/WebContextManager.php +++ b/globals/Dependencies/Web/WebContextManager.php @@ -3,6 +3,7 @@ namespace Alphaland\Web { use PDO; + use Alphaland\Web\IpHelper; class WebContextManager { @@ -16,7 +17,7 @@ namespace Alphaland\Web { $currentIp = WebContextManager::GetCurrentIPAddress(); $ipWhitelist = explode(";", WebsiteSettings::GetSetting("webservice_whitelist", "127.0.0.0/8;192.168.0.0/16;10.0.0.0/8")); - return in_array($currentIp, $ipWhitelist); + return IpHelper::IsIpInCidrNetmaskOrRangeList($currentIp, $ipWhitelist); } public static function CanBypassMaintenance() diff --git a/globals/config.php b/globals/config.php index 8ea3153..cb3638d 100644 --- a/globals/config.php +++ b/globals/config.php @@ -125,6 +125,7 @@ try include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Economy/EconomyHelper.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Groups/Group.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/WebsiteSettings.php"; + include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/IpRange.php"; //authenticator $authenticator = new PHPGangsta_GoogleAuthenticator();