From af69cb6166e6c583b2bb96f2f5d1d99b8f8d2644 Mon Sep 17 00:00:00 2001 From: Pinga Date: Tue, 29 Apr 2025 09:27:12 +0300 Subject: [PATCH] Added ability to use IP ranges for registrar whitelist --- cp/app/Controllers/RegistrarsController.php | 42 +++++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/cp/app/Controllers/RegistrarsController.php b/cp/app/Controllers/RegistrarsController.php index ca8f1fc..cae3eb6 100644 --- a/cp/app/Controllers/RegistrarsController.php +++ b/cp/app/Controllers/RegistrarsController.php @@ -34,11 +34,17 @@ class RegistrarsController extends Controller $countries = $iso3166->all(); $ipAddressValidator = v::when( - v::arrayType()->notEmpty(), // Condition: If it's a non-empty array - v::arrayType()->each(v::ip()), // Then: Each element must be a valid IP address - v::equals('') // Else: Allow it to be an empty string + v::arrayType()->notEmpty(), + v::arrayType()->each( + v::oneOf( + v::ip(), // Accepts IPv4 and IPv6 + v::regex('/^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/'), // IPv4 CIDR + v::regex('/^([0-9a-fA-F:]+)\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$/') // IPv6 CIDR + ) + ), + v::equals('') ); - + $data['owner']['cc'] = strtoupper($data['owner']['cc']); $data['billing']['cc'] = strtoupper($data['billing']['cc']); $data['abuse']['cc'] = strtoupper($data['abuse']['cc']); @@ -645,11 +651,17 @@ class RegistrarsController extends Controller $countries = $iso3166->all(); $ipAddressValidator = v::when( - v::arrayType()->notEmpty(), // Condition: If it's a non-empty array - v::arrayType()->each(v::ip()), // Then: Each element must be a valid IP address - v::equals('') // Else: Allow it to be an empty string + v::arrayType()->notEmpty(), + v::arrayType()->each( + v::oneOf( + v::ip(), // Accepts IPv4 and IPv6 + v::regex('/^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/'), // IPv4 CIDR + v::regex('/^([0-9a-fA-F:]+)\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$/') // IPv6 CIDR + ) + ), + v::equals('') ); - + $data['owner']['cc'] = strtoupper($data['owner']['cc']); $data['billing']['cc'] = strtoupper($data['billing']['cc']); $data['abuse']['cc'] = strtoupper($data['abuse']['cc']); @@ -901,11 +913,17 @@ class RegistrarsController extends Controller $countries = $iso3166->all(); $ipAddressValidator = v::when( - v::arrayType()->notEmpty(), // Condition: If it's a non-empty array - v::arrayType()->each(v::ip()), // Then: Each element must be a valid IP address - v::equals('') // Else: Allow it to be an empty string + v::arrayType()->notEmpty(), + v::arrayType()->each( + v::oneOf( + v::ip(), // Accepts IPv4 and IPv6 + v::regex('/^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/'), // IPv4 CIDR + v::regex('/^([0-9a-fA-F:]+)\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$/') // IPv6 CIDR + ) + ), + v::equals('') ); - + $data['owner']['cc'] = strtoupper($data['owner']['cc']); $data['billing']['cc'] = strtoupper($data['billing']['cc']); $data['abuse']['cc'] = strtoupper($data['abuse']['cc']);