From 69411399d8de7de5eed6e9d556fbced1c6218e5d Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Thu, 23 Jan 2025 13:07:52 +0200 Subject: [PATCH] Added ability for custom records per TLD, fixed #175 --- automation/write-zone.php | 20 ++++++++++++++++++++ docs/configuration.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) 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.