From c9982bbcc01858dd09920f76b88b9a05bba774c2 Mon Sep 17 00:00:00 2001 From: Pinga Date: Tue, 13 May 2025 20:44:12 +0300 Subject: [PATCH] Update helpers.php --- epp/src/helpers.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/epp/src/helpers.php b/epp/src/helpers.php index c32c431..6b55884 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -1099,4 +1099,20 @@ function validateTcnId(string $domain, string $noticeId, string $notAfterUtc): b // Compare return hash_equals($tcnChecksum, $crc32Hex); +} + +function extractDomainFromHost(string $hostname, array $tlds): ?string { + $hostname = strtolower($hostname); + foreach ($tlds as $tld) { + $tld = ltrim(strtolower($tld), '.'); // remove dot if present + if (str_ends_with($hostname, '.' . $tld)) { + $labels = explode('.', $hostname); + $tld_parts = explode('.', $tld); + $domain_parts = array_slice($labels, -count($tld_parts) - 1); // 1 label before TLD + if (count($domain_parts) === count($tld_parts) + 1) { + return implode('.', $domain_parts); + } + } + } + return null; } \ No newline at end of file