diff --git a/src/storage.cr b/src/storage.cr index e2c8576..82e2f87 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -221,8 +221,7 @@ class DNSManager::Storage zone << rr - # Update the zone. - zones_by_domain.update_or_create zone.domain, zone + update_zone zone Response::RRAdded.new zone.domain, rr rescue e @@ -230,6 +229,13 @@ class DNSManager::Storage Response::Error.new "error while adding a resource record in domain #{domain}" 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 # User must exist. 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 } - # Update the zone. - zones_by_domain.update_or_create zone.domain, zone + update_zone zone Response::RRUpdated.new domain, rr rescue e @@ -298,8 +303,7 @@ class DNSManager::Storage zone.resources.select! { |x| x.rrid != rrid } - # Update the zone. - zones_by_domain.update_or_create zone.domain, zone + update_zone zone Response::RRDeleted.new rrid rescue e diff --git a/src/storage/zone.cr b/src/storage/zone.cr index ece98a7..d3b2c6f 100644 --- a/src/storage/zone.cr +++ b/src/storage/zone.cr @@ -594,6 +594,15 @@ class DNSManager::Storage::Zone end end + def update_serial + @resources.each do |rr| + case rr + when SOA + rr.serial += 1 + end + end + end + def get_errors? : Array(Error)? errors = [] of Error unless Zone.is_domain_valid? @domain