Skip to content

Commit

Permalink
Load existing zone at startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanedwardes committed Feb 10, 2024
1 parent 6199e5e commit a004282
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions misc/Ae.Dns.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,27 @@ async Task ReportStats(CancellationToken token)

if (dnsConfiguration.UpdateZoneName != null && dnsConfiguration.UpdateZoneFile != null)
{
var zoneFile = $"{dnsConfiguration.UpdateZoneName}.zone";

#pragma warning disable CS0618 // Type or member is obsolete
updateClient = new DnsUpdateClient(new DnsZone
var dnsZone = new DnsZone
{
Origin = dnsConfiguration.UpdateZoneName,
DefaultTtl = TimeSpan.FromHours(1),
ZoneUpdated = async zone => await File.WriteAllTextAsync($"{dnsConfiguration.UpdateZoneName}.zone", zone.SerializeZone())
});
ZoneUpdated = async zone => await File.WriteAllTextAsync(zoneFile, zone.SerializeZone())
};

if (File.Exists(zoneFile))
{
// Load the existing zone file
dnsZone.DeserializeZone(File.ReadAllText(zoneFile));
}
else
{
// Set some defaults for the new zone
dnsZone.Origin = dnsConfiguration.UpdateZoneName;
dnsZone.DefaultTtl = TimeSpan.FromHours(1);
}

updateClient = new DnsUpdateClient(dnsZone);
#pragma warning restore CS0618 // Type or member is obsolete
}

Expand Down

0 comments on commit a004282

Please sign in to comment.