Automatically update the SOA serial.

This commit is contained in:
Philippe Pittoli 2024-03-07 02:52:59 +01:00
parent 62199f27e3
commit 26d01a0b63
2 changed files with 19 additions and 6 deletions

View File

@ -221,8 +221,7 @@ class DNSManager::Storage
zone << rr zone << rr
# Update the zone. update_zone zone
zones_by_domain.update_or_create zone.domain, zone
Response::RRAdded.new zone.domain, rr Response::RRAdded.new zone.domain, rr
rescue e rescue e
@ -230,6 +229,13 @@ class DNSManager::Storage
Response::Error.new "error while adding a resource record in domain #{domain}" Response::Error.new "error while adding a resource record in domain #{domain}"
end end
# Any modification of the zone must be performed here.
# This function updates the SOA serial before storing the modified zone.
def update_zone(zone : Zone)
zone.update_serial
zones_by_domain.update_or_create zone.domain, zone
end
def update_rr(user_id : Int32, domain : String, rr : Zone::ResourceRecord) : IPC::JSON def update_rr(user_id : Int32, domain : String, rr : Zone::ResourceRecord) : IPC::JSON
# User must exist. # User must exist.
user_data = user_data_by_uid.get? user_id.to_s user_data = user_data_by_uid.get? user_id.to_s
@ -269,8 +275,7 @@ class DNSManager::Storage
zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x } zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
# Update the zone. update_zone zone
zones_by_domain.update_or_create zone.domain, zone
Response::RRUpdated.new domain, rr Response::RRUpdated.new domain, rr
rescue e rescue e
@ -298,8 +303,7 @@ class DNSManager::Storage
zone.resources.select! { |x| x.rrid != rrid } zone.resources.select! { |x| x.rrid != rrid }
# Update the zone. update_zone zone
zones_by_domain.update_or_create zone.domain, zone
Response::RRDeleted.new rrid Response::RRDeleted.new rrid
rescue e rescue e

View File

@ -594,6 +594,15 @@ class DNSManager::Storage::Zone
end end
end end
def update_serial
@resources.each do |rr|
case rr
when SOA
rr.serial += 1
end
end
end
def get_errors? : Array(Error)? def get_errors? : Array(Error)?
errors = [] of Error errors = [] of Error
unless Zone.is_domain_valid? @domain unless Zone.is_domain_valid? @domain