From a51fd8b31b345c599a2a724b18b22af6ba48de50 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Mon, 1 Jul 2024 02:03:19 +0200 Subject: [PATCH] Regenerate Bind9 zone files on any update. --- src/storage.cr | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/storage.cr b/src/storage.cr index e7fc438..ed3d914 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -71,7 +71,7 @@ class DNSManager::Storage end end - def generate_zonefile_(domain : String) : Nil + def generate_bind9_zonefile(domain : String) : Nil zone = zone_must_exist! domain # Safe write. @@ -89,7 +89,7 @@ class DNSManager::Storage # Only an admin can access this function. def generate_zonefile(domain : String) : IPC::JSON - generate_zonefile_ domain + generate_bind9_zonefile domain Response::Success.new end @@ -97,7 +97,7 @@ class DNSManager::Storage def generate_all_zonefiles() : IPC::JSON Baguette::Log.info "writing all zone files in #{@zonefiledir}/" zones.each do |zone| - generate_zonefile_ zone.domain + generate_bind9_zonefile zone.domain end Response::Success.new end @@ -248,6 +248,8 @@ class DNSManager::Storage # Add -or replace- the zone. zones_by_domain.update_or_create zone.domain, zone + generate_bind9_zonefile zone.domain + Response::Success.new end @@ -267,14 +269,19 @@ class DNSManager::Storage update_zone zone + generate_bind9_zonefile zone.domain + Response::RRAdded.new zone.domain, rr end # Any modification of the zone must be performed here. # This function updates the SOA serial before storing the modified zone. + # Also, this function generate the Bind9 file. def update_zone(zone : Zone) zone.update_serial zones_by_domain.update_or_create zone.domain, zone + + generate_bind9_zonefile zone.domain end def update_rr(user_id : UserDataID, domain : String, rr : Zone::ResourceRecord) : IPC::JSON @@ -319,6 +326,11 @@ class DNSManager::Storage Response::RRDeleted.new rrid end + # TODO + def remove_bind9_zonefile(domain : String) + Baguette::Log.info "Removing a Bind9 zone file." + end + def delete_domain(user_id : UserDataID, domain_name : String) : IPC::JSON zone_must_exist! domain_name user_should_own! user_id, domain_name @@ -343,6 +355,8 @@ class DNSManager::Storage # Remove this domain_name from the list of user's domains. domains_by_name.delete domain_name + remove_bind9_zonefile domain_name + Response::DomainDeleted.new domain_name end