mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-16 09:37:00 +02:00
Small fix in EPP regarding different representation of IPv6
This commit is contained in:
parent
5c6ff7f087
commit
ea6a79b5c5
2 changed files with 30 additions and 0 deletions
|
@ -616,3 +616,30 @@ 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);
|
||||
}
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue