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
$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";
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);
$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);

View file

@ -25,3 +25,5 @@ MAIL_API_KEY='test-api-key'
MAIL_API_PROVIDER='sendgrid'
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.
### 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

View file

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

View file

@ -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);