This commit is contained in:
Pinga 2023-12-29 13:27:59 +02:00
parent 82f9581c44
commit bd5ada89b9
6 changed files with 30 additions and 23 deletions

View file

@ -28,17 +28,11 @@ if (!$cachedFile->isHit()) {
// Save the file content to cache // Save the file content to cache
$cachedFile->set($fileContent); $cachedFile->set($fileContent);
$cachedFile->expiresAfter(86400); // Cache for 24 hours, for example $cachedFile->expiresAfter(86400 * 7); // Cache for 7 days
$cache->save($cachedFile); $cache->save($cachedFile);
echo "File downloaded and cached.\n"; echo "ICANN TLD List downloaded and cached.".PHP_EOL;
} else { } else {
// Retrieve the file content from the cache // Retrieve the file content from the cache
$fileContent = $cachedFile->get(); $fileContent = $cachedFile->get();
echo "File loaded from cache.\n"; echo "ICANN TLD List loaded from cache.".PHP_EOL;
} }
// Use $fileContent as needed
// ...
// For demonstration: Writing first 200 characters of the content
echo substr($fileContent, 0, 50) . "...";

View file

@ -284,17 +284,17 @@ function extractDomainAndTLD($urlString) {
$cachedFile = $cache->getItem($cacheKey); $cachedFile = $cache->getItem($cacheKey);
$fileContent = $cachedFile->get(); $fileContent = $cachedFile->get();
// Define a list of fake TLDs used in your QA environment // Load a list of test TLDs used in your QA environment
$fakeTlds = ['test', 'xx']; $testTlds = explode(',', envi('TEST_TLDS'));
// Parse the URL to get the host // Parse the URL to get the host
$parts = parse_url($urlString); $parts = parse_url($urlString);
$host = $parts['host'] ?? $urlString; $host = $parts['host'] ?? $urlString;
// Check if the TLD is a known fake TLD // Check if the TLD is a known test TLD
foreach ($fakeTlds as $fakeTld) { foreach ($testTlds as $testTld) {
if (str_ends_with($host, ".$fakeTld")) { if (str_ends_with($host, "$testTld")) {
// Handle the fake TLD case // Handle the test TLD case
$hostParts = explode('.', $host); $hostParts = explode('.', $host);
$tld = array_pop($hostParts); $tld = array_pop($hostParts);
$sld = array_pop($hostParts); $sld = array_pop($hostParts);

View file

@ -24,4 +24,6 @@ MAIL_FROM_NAME='Example'
MAIL_API_KEY='test-api-key' MAIL_API_KEY='test-api-key'
MAIL_API_PROVIDER='sendgrid' MAIL_API_PROVIDER='sendgrid'
STRIPE_SECRET_KEY='stripe-secret-key' STRIPE_SECRET_KEY='stripe-secret-key'
TEST_TLDS=.test,.xx

View file

@ -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. 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: ## 8. Setup Web Lookup:
```bash ```bash

View file

@ -14,4 +14,5 @@ return [
'epp_prefix' => 'namingo', 'epp_prefix' => 'namingo',
'ssl_cert' => '', 'ssl_cert' => '',
'ssl_key' => '', 'ssl_key' => '',
'test_tlds' => '.test,.xx',
]; ];

View file

@ -231,6 +231,8 @@ function validate_label($label, $pdo) {
} }
function extractDomainAndTLD($urlString) { function extractDomainAndTLD($urlString) {
global $c;
$cachePath = '/var/www/cp/cache'; // Cache directory $cachePath = '/var/www/cp/cache'; // Cache directory
$adapter = new LocalFilesystemAdapter($cachePath, null, LOCK_EX); $adapter = new LocalFilesystemAdapter($cachePath, null, LOCK_EX);
$filesystem = new Filesystem($adapter); $filesystem = new Filesystem($adapter);
@ -239,17 +241,17 @@ function extractDomainAndTLD($urlString) {
$cachedFile = $cache->getItem($cacheKey); $cachedFile = $cache->getItem($cacheKey);
$fileContent = $cachedFile->get(); $fileContent = $cachedFile->get();
// Define a list of fake TLDs used in your QA environment // Load a list of test TLDs used in your QA environment
$fakeTlds = ['test', 'xx']; $testTlds = explode(',', $c['test_tlds']);
// Parse the URL to get the host // Parse the URL to get the host
$parts = parse_url($urlString); $parts = parse_url($urlString);
$host = $parts['host'] ?? $urlString; $host = $parts['host'] ?? $urlString;
// Check if the TLD is a known fake TLD // Check if the TLD is a known test TLD
foreach ($fakeTlds as $fakeTld) { foreach ($testTlds as $testTld) {
if (str_ends_with($host, ".$fakeTld")) { if (str_ends_with($host, "$testTld")) {
// Handle the fake TLD case // Handle the test TLD case
$hostParts = explode('.', $host); $hostParts = explode('.', $host);
$tld = array_pop($hostParts); $tld = array_pop($hostParts);
$sld = array_pop($hostParts); $sld = array_pop($hostParts);