Added ability for custom records per TLD, fixed #175

This commit is contained in:
Pinga 2025-01-23 13:07:52 +02:00
parent a63f733a7c
commit 69411399d8
2 changed files with 50 additions and 0 deletions

View file

@ -70,6 +70,26 @@ Coroutine::create(function () use ($pool, $log, $c) {
$zone->addResourceRecord($nsRecord);
}
// Include custom records if the file exists
$customRecordsFile = "/opt/registry/automation/{$cleanedTld}.php";
if (file_exists($customRecordsFile)) {
$log->info("Loading custom records for {$cleanedTld} from {$customRecordsFile}.");
$customRecords = require $customRecordsFile;
foreach ($customRecords as $record) {
try {
$customRecord = new ResourceRecord;
$customRecord->setName($record['name']);
$customRecord->setClass(Classes::INTERNET);
$customRecord->setRdata(Factory::{$record['type']}(...$record['parameters']));
$zone->addResourceRecord($customRecord);
} catch (Throwable $e) {
$log->error("Failed to add custom record for {$cleanedTld}: " . $e->getMessage());
}
}
}
// Fetch domains for this TLD
$sthDomains = $pdo->prepare('SELECT DISTINCT domain.id, domain.name FROM domain WHERE tldid = :id AND (exdate > CURRENT_TIMESTAMP OR rgpstatus = \'pendingRestore\') ORDER BY domain.name');

View file

@ -252,6 +252,36 @@ WEB_AUTHN_ENABLED=true
sudo systemctl reload caddy
```
#### 1.4.11. Zone generator custom records
Each TLD can have its own custom records file, located in `/opt/registry/automation/`. For example, for the TLD `example`, create the file `/opt/registry/automation/example.php`.
The content of a custom records file should be:
```php
<?php
return [
// A record
[
'name' => '@', // The name of the record (e.g., @ for the root domain or a subdomain)
'type' => 'A', // Record type (A, AAAA, TXT, etc.)
'parameters' => ['192.0.2.1'], // Parameters required for the record type
],
// AAAA record
[
'name' => 'www',
'type' => 'AAAA',
'parameters' => ['2001:db8::1'],
],
// TXT record
[
'name' => '@',
'type' => 'TXT',
'parameters' => ['"v=spf1 include:example.com ~all"'],
],
];
```
## 2. Recommended Components and Integrations
This section outlines recommended components to enhance the functionality and reliability of your Namingo setup. These include essential services like DNS servers, monitoring tools, and other integrations that can help maintain a robust registry environment.