Regenerate Bind9 zone files on any update.

This commit is contained in:
Philippe PITTOLI 2024-07-01 02:03:19 +02:00
parent 8d9f4051e6
commit a51fd8b31b

View File

@ -71,7 +71,7 @@ class DNSManager::Storage
end end
end end
def generate_zonefile_(domain : String) : Nil def generate_bind9_zonefile(domain : String) : Nil
zone = zone_must_exist! domain zone = zone_must_exist! domain
# Safe write. # Safe write.
@ -89,7 +89,7 @@ class DNSManager::Storage
# Only an admin can access this function. # Only an admin can access this function.
def generate_zonefile(domain : String) : IPC::JSON def generate_zonefile(domain : String) : IPC::JSON
generate_zonefile_ domain generate_bind9_zonefile domain
Response::Success.new Response::Success.new
end end
@ -97,7 +97,7 @@ class DNSManager::Storage
def generate_all_zonefiles() : IPC::JSON def generate_all_zonefiles() : IPC::JSON
Baguette::Log.info "writing all zone files in #{@zonefiledir}/" Baguette::Log.info "writing all zone files in #{@zonefiledir}/"
zones.each do |zone| zones.each do |zone|
generate_zonefile_ zone.domain generate_bind9_zonefile zone.domain
end end
Response::Success.new Response::Success.new
end end
@ -248,6 +248,8 @@ class DNSManager::Storage
# Add -or replace- the zone. # Add -or replace- the zone.
zones_by_domain.update_or_create zone.domain, zone zones_by_domain.update_or_create zone.domain, zone
generate_bind9_zonefile zone.domain
Response::Success.new Response::Success.new
end end
@ -267,14 +269,19 @@ class DNSManager::Storage
update_zone zone update_zone zone
generate_bind9_zonefile zone.domain
Response::RRAdded.new zone.domain, rr Response::RRAdded.new zone.domain, rr
end end
# Any modification of the zone must be performed here. # Any modification of the zone must be performed here.
# This function updates the SOA serial before storing the modified zone. # This function updates the SOA serial before storing the modified zone.
# Also, this function generate the Bind9 file.
def update_zone(zone : Zone) def update_zone(zone : Zone)
zone.update_serial zone.update_serial
zones_by_domain.update_or_create zone.domain, zone zones_by_domain.update_or_create zone.domain, zone
generate_bind9_zonefile zone.domain
end end
def update_rr(user_id : UserDataID, domain : String, rr : Zone::ResourceRecord) : IPC::JSON def update_rr(user_id : UserDataID, domain : String, rr : Zone::ResourceRecord) : IPC::JSON
@ -319,6 +326,11 @@ class DNSManager::Storage
Response::RRDeleted.new rrid Response::RRDeleted.new rrid
end 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 def delete_domain(user_id : UserDataID, domain_name : String) : IPC::JSON
zone_must_exist! domain_name zone_must_exist! domain_name
user_should_own! user_id, 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. # Remove this domain_name from the list of user's domains.
domains_by_name.delete domain_name domains_by_name.delete domain_name
remove_bind9_zonefile domain_name
Response::DomainDeleted.new domain_name Response::DomainDeleted.new domain_name
end end