diff --git a/automation/write-zone.php b/automation/write-zone.php index 9143073..52617f3 100644 --- a/automation/write-zone.php +++ b/automation/write-zone.php @@ -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'); diff --git a/docs/configuration.md b/docs/configuration.md index 6a87c90..6670197 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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 + '@', // 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.