Skip to content

Commit

Permalink
Fixed #33 #50
Browse files Browse the repository at this point in the history
  • Loading branch information
getpinga committed Dec 29, 2023
1 parent 82f9581 commit bd5ada8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
14 changes: 4 additions & 10 deletions cp/bin/file_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@

// 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) . "...";
echo "ICANN TLD List loaded from cache.".PHP_EOL;
}
12 changes: 6 additions & 6 deletions cp/bootstrap/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion cp/env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ MAIL_FROM_NAME='Example'
MAIL_API_KEY='test-api-key'
MAIL_API_PROVIDER='sendgrid'

STRIPE_SECRET_KEY='stripe-secret-key'
STRIPE_SECRET_KEY='stripe-secret-key'

TEST_TLDS=.test,.xx
8 changes: 8 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions epp/config.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ return [
'epp_prefix' => 'namingo',
'ssl_cert' => '',
'ssl_key' => '',
'test_tlds' => '.test,.xx',
];
14 changes: 8 additions & 6 deletions epp/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit bd5ada8

Please sign in to comment.