diff --git a/epp/src/helpers.php b/epp/src/helpers.php index 20da880..8e748d3 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -615,4 +615,31 @@ function generateAuthInfo(): string { } return $retVal; +} + +function isIPv6($ip) { + // Validate if the IP is in IPv6 format + return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false; +} + +function expandIPv6($ip) { + if (strpos($ip, '::') !== false) { + // Split the IP by '::' + $parts = explode('::', $ip); + $left = explode(':', $parts[0]); + $right = isset($parts[1]) ? explode(':', $parts[1]) : []; + + // Calculate the number of missing groups and fill them with '0000' + $fill = array_fill(0, 8 - (count($left) + count($right)), '0000'); + $expanded = array_merge($left, $fill, $right); + } else { + $expanded = explode(':', $ip); + } + + // Ensure each block is four characters + foreach ($expanded as &$block) { + $block = str_pad($block, 4, '0', STR_PAD_LEFT); + } + + return implode(':', $expanded); } \ No newline at end of file diff --git a/epp/start_epp.php b/epp/start_epp.php index 85bd13e..321c857 100644 --- a/epp/start_epp.php +++ b/epp/start_epp.php @@ -76,6 +76,9 @@ $server->handle(function (Connection $conn) use ($table, $pool, $c, $log, $permi // Get the client information $clientInfo = $conn->exportSocket()->getpeername(); $clientIP = isset($clientInfo['address']) ? (strpos($clientInfo['address'], '::ffff:') === 0 ? substr($clientInfo['address'], 7) : $clientInfo['address']) : ''; + if (isIPv6($clientIP)) { + $clientIP = expandIPv6($clientIP); + } // Check if the IP is in the permitted list if (!$permittedIPsTable->exist($clientIP)) {