mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-10 16:58:34 +02:00
Further IDN improvements
This commit is contained in:
parent
137f8170e2
commit
c8c8cc3c07
3 changed files with 36 additions and 6 deletions
|
@ -172,7 +172,8 @@ $http->start();
|
|||
|
||||
function handleDomainQuery($request, $response, $pdo, $domainName, $c, $log) {
|
||||
// Extract and validate the domain name from the request
|
||||
$domain = trim($domainName);
|
||||
$domain = urldecode($domainName);
|
||||
$domain = trim($domain);
|
||||
|
||||
// Empty domain check
|
||||
if (!$domain) {
|
||||
|
@ -1013,7 +1014,8 @@ function handleEntityQuery($request, $response, $pdo, $entityHandle, $c, $log) {
|
|||
|
||||
function handleNameserverQuery($request, $response, $pdo, $nameserverHandle, $c, $log) {
|
||||
// Extract and validate the nameserver handle from the request
|
||||
$ns = trim($nameserverHandle);
|
||||
$ns = urldecode($nameserverHandle);
|
||||
$ns = trim($ns);
|
||||
|
||||
// Empty nameserver check
|
||||
if (!$ns) {
|
||||
|
@ -1375,7 +1377,8 @@ function handleNameserverQuery($request, $response, $pdo, $nameserverHandle, $c,
|
|||
|
||||
function handleDomainSearchQuery($request, $response, $pdo, $searchPattern, $c, $log, $searchType) {
|
||||
// Extract and validate the domain name from the request
|
||||
$domain = trim($searchPattern);
|
||||
$domain = urldecode($searchPattern);
|
||||
$domain = trim($domain);
|
||||
|
||||
// Empty domain check
|
||||
if (!$domain) {
|
||||
|
@ -1946,7 +1949,8 @@ function handleDomainSearchQuery($request, $response, $pdo, $searchPattern, $c,
|
|||
|
||||
function handleNameserverSearchQuery($request, $response, $pdo, $searchPattern, $c, $log, $searchType) {
|
||||
// Extract and validate the nameserver handle from the request
|
||||
$ns = trim($searchPattern);
|
||||
$ns = urldecode($searchPattern);
|
||||
$ns = trim($ns);
|
||||
|
||||
// Perform the RDAP lookup
|
||||
try {
|
||||
|
|
|
@ -169,8 +169,20 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pool
|
|||
|
||||
$clidF = $stmt3->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// Check if the domain name is non-ASCII or starts with 'xn--'
|
||||
$isNonAsciiOrPunycode = !mb_check_encoding($f['name'], 'ASCII') || strpos($f['name'], 'xn--') === 0;
|
||||
|
||||
$res = "Domain Name: ".strtoupper($f['name'])
|
||||
."\nRegistry Domain ID: D".$f['id']."-".$c['roid']
|
||||
."\n";
|
||||
|
||||
// Add the Internationalized Domain Name line if the condition is met
|
||||
if ($isNonAsciiOrPunycode) {
|
||||
// Convert the domain name to UTF-8 and make it uppercase
|
||||
$internationalizedName = idn_to_utf8($f['name'], 0, INTL_IDNA_VARIANT_UTS46);
|
||||
$res .= "Internationalized Domain Name: " . mb_strtoupper($internationalizedName) . "\n";
|
||||
}
|
||||
|
||||
$res .= "Registry Domain ID: D".$f['id']."-".$c['roid']
|
||||
."\nRegistrar WHOIS Server: ".$clidF['whois_server']
|
||||
."\nRegistrar URL: ".$clidF['url']
|
||||
."\nUpdated Date: ".$f['lastupdate']
|
||||
|
|
|
@ -19,6 +19,20 @@ $rdapServer = 'https://' . $c['rdap_url'] . '/domain/';
|
|||
|
||||
$sanitized_domain = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
|
||||
|
||||
// Check if the domain is in Unicode and convert it to Punycode
|
||||
if (mb_check_encoding($domain, 'UTF-8') && !filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
|
||||
$punycodeDomain = idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
|
||||
|
||||
if ($punycodeDomain !== false) {
|
||||
$domain = $punycodeDomain;
|
||||
} else {
|
||||
echo json_encode(['error' => 'Invalid domain.']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sanitized_domain = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
|
||||
|
||||
if ($sanitized_domain) {
|
||||
$domain = $sanitized_domain;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue