mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-12 22:08:12 +02:00
More RST preparations
This commit is contained in:
parent
ebe8982b00
commit
3d3ffe46d5
3 changed files with 22 additions and 10 deletions
|
@ -1040,18 +1040,26 @@ function ipMatches($ip, $cidr) {
|
|||
}
|
||||
|
||||
list($subnet, $mask) = explode('/', $cidr);
|
||||
if (!is_numeric($mask) || $mask < 0 || $mask > 32) {
|
||||
return false; // invalid mask
|
||||
}
|
||||
$ipBin = inet_pton($ip);
|
||||
$subnetBin = inet_pton($subnet);
|
||||
|
||||
$ipLong = ip2long($ip);
|
||||
$subnetLong = ip2long($subnet);
|
||||
|
||||
if ($ipLong === false || $subnetLong === false) {
|
||||
if ($ipBin === false || $subnetBin === false) {
|
||||
return false; // invalid IP
|
||||
}
|
||||
|
||||
$maskLong = -1 << (32 - (int)$mask);
|
||||
$ipLen = strlen($ipBin) * 8; // 32 for IPv4, 128 for IPv6
|
||||
|
||||
return ($ipLong & $maskLong) === ($subnetLong & $maskLong);
|
||||
if (!is_numeric($mask) || $mask < 0 || $mask > $ipLen) {
|
||||
return false; // invalid mask
|
||||
}
|
||||
|
||||
$maskBin = str_repeat("f", intval($mask / 4));
|
||||
if ($mask % 4) {
|
||||
$bits = $mask % 4;
|
||||
$maskBin .= dechex(bindec(str_repeat('1', $bits) . str_repeat('0', 4 - $bits)));
|
||||
}
|
||||
$maskBin = str_pad($maskBin, $ipLen / 4, '0'); // pad to full length
|
||||
$maskBin = pack("H*", $maskBin);
|
||||
|
||||
return ($ipBin & $maskBin) === ($subnetBin & $maskBin);
|
||||
}
|
|
@ -973,6 +973,7 @@ function handleEntityQuery($request, $response, $pdo, $entityHandle, $c, $log) {
|
|||
'links' => [
|
||||
[
|
||||
'href' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'value' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'rel' => 'self',
|
||||
'type' => 'application/rdap+json',
|
||||
]
|
||||
|
@ -2892,6 +2893,7 @@ function handleEntitySearchQuery($request, $response, $pdo, $searchPattern, $c,
|
|||
'links' => [
|
||||
[
|
||||
'href' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'value' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'rel' => 'self',
|
||||
'type' => 'application/rdap+json',
|
||||
]
|
||||
|
|
|
@ -973,6 +973,7 @@ function handleEntityQuery($request, $response, $pdo, $entityHandle, $c, $log) {
|
|||
'links' => [
|
||||
[
|
||||
'href' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'value' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'rel' => 'self',
|
||||
'type' => 'application/rdap+json',
|
||||
]
|
||||
|
@ -2892,6 +2893,7 @@ function handleEntitySearchQuery($request, $response, $pdo, $searchPattern, $c,
|
|||
'links' => [
|
||||
[
|
||||
'href' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'value' => $c['rdap_url'] . '/entity/' . ($registrarDetails['iana_id'] ?: $registrarDetails['id']),
|
||||
'rel' => 'self',
|
||||
'type' => 'application/rdap+json',
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue