diff --git a/cp/bin/file_cache.php b/cp/bin/file_cache.php index 6256dba..b8608bb 100644 --- a/cp/bin/file_cache.php +++ b/cp/bin/file_cache.php @@ -28,17 +28,11 @@ if (!$cachedFile->isHit()) { // Save the file content to cache $cachedFile->set($fileContent); - $cachedFile->expiresAfter(86400); // Cache for 24 hours, for example + $cachedFile->expiresAfter(86400 * 7); // Cache for 7 days $cache->save($cachedFile); - echo "File downloaded and cached.\n"; + echo "ICANN TLD List downloaded and cached.".PHP_EOL; } else { // Retrieve the file content from the cache $fileContent = $cachedFile->get(); - echo "File loaded from cache.\n"; -} - -// Use $fileContent as needed -// ... - -// For demonstration: Writing first 200 characters of the content -echo substr($fileContent, 0, 50) . "..."; \ No newline at end of file + echo "ICANN TLD List loaded from cache.".PHP_EOL; +} \ No newline at end of file diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index 47d6a69..79fedd8 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -284,17 +284,17 @@ function extractDomainAndTLD($urlString) { $cachedFile = $cache->getItem($cacheKey); $fileContent = $cachedFile->get(); - // Define a list of fake TLDs used in your QA environment - $fakeTlds = ['test', 'xx']; + // Load a list of test TLDs used in your QA environment + $testTlds = explode(',', envi('TEST_TLDS')); // Parse the URL to get the host $parts = parse_url($urlString); $host = $parts['host'] ?? $urlString; - // Check if the TLD is a known fake TLD - foreach ($fakeTlds as $fakeTld) { - if (str_ends_with($host, ".$fakeTld")) { - // Handle the fake TLD case + // Check if the TLD is a known test TLD + foreach ($testTlds as $testTld) { + if (str_ends_with($host, "$testTld")) { + // Handle the test TLD case $hostParts = explode('.', $host); $tld = array_pop($hostParts); $sld = array_pop($hostParts); diff --git a/cp/env-sample b/cp/env-sample index d791152..33fcd97 100644 --- a/cp/env-sample +++ b/cp/env-sample @@ -24,4 +24,6 @@ MAIL_FROM_NAME='Example' MAIL_API_KEY='test-api-key' MAIL_API_PROVIDER='sendgrid' -STRIPE_SECRET_KEY='stripe-secret-key' \ No newline at end of file +STRIPE_SECRET_KEY='stripe-secret-key' + +TEST_TLDS=.test,.xx \ No newline at end of file diff --git a/docs/install.md b/docs/install.md index c4d8610..ce012b5 100644 --- a/docs/install.md +++ b/docs/install.md @@ -294,6 +294,14 @@ This command will install the dependencies defined in your ```composer.json``` f 5. Remove the Script: Once verified, delete the script to maintain system security. +### Download TLD List: + +To get the starting list of TLDs (Top-Level Domains) from ICANN and cache it for quick access later, please run the following command: + +```bash +php /var/www/cp/bin/file_cache.php +``` + ## 8. Setup Web Lookup: ```bash diff --git a/epp/config.php.dist b/epp/config.php.dist index 8b8c475..e94bac7 100644 --- a/epp/config.php.dist +++ b/epp/config.php.dist @@ -14,4 +14,5 @@ return [ 'epp_prefix' => 'namingo', 'ssl_cert' => '', 'ssl_key' => '', + 'test_tlds' => '.test,.xx', ]; \ No newline at end of file diff --git a/epp/src/helpers.php b/epp/src/helpers.php index 5607dcb..e68bf83 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -231,6 +231,8 @@ function validate_label($label, $pdo) { } function extractDomainAndTLD($urlString) { + global $c; + $cachePath = '/var/www/cp/cache'; // Cache directory $adapter = new LocalFilesystemAdapter($cachePath, null, LOCK_EX); $filesystem = new Filesystem($adapter); @@ -239,17 +241,17 @@ function extractDomainAndTLD($urlString) { $cachedFile = $cache->getItem($cacheKey); $fileContent = $cachedFile->get(); - // Define a list of fake TLDs used in your QA environment - $fakeTlds = ['test', 'xx']; + // Load a list of test TLDs used in your QA environment + $testTlds = explode(',', $c['test_tlds']); // Parse the URL to get the host $parts = parse_url($urlString); $host = $parts['host'] ?? $urlString; - // Check if the TLD is a known fake TLD - foreach ($fakeTlds as $fakeTld) { - if (str_ends_with($host, ".$fakeTld")) { - // Handle the fake TLD case + // Check if the TLD is a known test TLD + foreach ($testTlds as $testTld) { + if (str_ends_with($host, "$testTld")) { + // Handle the test TLD case $hostParts = explode('.', $host); $tld = array_pop($hostParts); $sld = array_pop($hostParts);