From 9762e87ff6fe1e07535df1518b814eea342fec5f Mon Sep 17 00:00:00 2001 From: "Alstra Solutions Ltd." <127345257+alstrasolutions@users.noreply.github.com> Date: Sun, 16 Jun 2024 06:04:55 +0000 Subject: [PATCH 1/2] Fix WHOIS to correctly extract the TLD for multi-segment TLDs (or SLDs) such as `co.uk`, `ngo.us` --- whois/port43/start_whois.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/whois/port43/start_whois.php b/whois/port43/start_whois.php index d717837..dde54c2 100644 --- a/whois/port43/start_whois.php +++ b/whois/port43/start_whois.php @@ -111,7 +111,13 @@ $server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pool // Extract TLD from the domain and prepend a dot $parts = explode('.', $domain); - $tld = "." . end($parts); + + // Handle multi-segment TLDs (e.g., co.uk, ngo.us, etc.) + if (count($parts) > 2) { + $tld = "." . $parts[count($parts) - 2] . "." . $parts[count($parts) - 1]; + } else { + $tld = "." . end($parts); + } // Check if the TLD exists in the domain_tld table $stmtTLD = $pdo->prepare("SELECT COUNT(*) FROM domain_tld WHERE tld = :tld"); From 75eeef5f53b3b34df92500b4b21f58ea0caa509d Mon Sep 17 00:00:00 2001 From: "Alstra Solutions Ltd." <127345257+alstrasolutions@users.noreply.github.com> Date: Sun, 16 Jun 2024 06:32:10 +0000 Subject: [PATCH 2/2] Fix RDAP to correctly extract the TLD for multi-segment TLDs --- rdap/start_rdap.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rdap/start_rdap.php b/rdap/start_rdap.php index 94a9803..a31b5ea 100644 --- a/rdap/start_rdap.php +++ b/rdap/start_rdap.php @@ -227,7 +227,13 @@ function handleDomainQuery($request, $response, $pdo, $domainName, $c, $log) { // Extract TLD from the domain $parts = explode('.', $domain); - $tld = "." . end($parts); + + // Handle multi-segment TLDs (e.g., co.uk, ngo.us, etc.) + if (count($parts) > 2) { + $tld = "." . $parts[count($parts) - 2] . "." . $parts[count($parts) - 1]; + } else { + $tld = "." . end($parts); + } // Check if the TLD exists in the domain_tld table $stmtTLD = $pdo->prepare("SELECT COUNT(*) FROM domain_tld WHERE tld = :tld");