Skip to content

Commit

Permalink
Removes config/code from console app around DHCP.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanedwardes committed Feb 11, 2024
1 parent 0dcfabe commit e532dd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
3 changes: 0 additions & 3 deletions misc/Ae.Dns.Console/DnsConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ public sealed class DnsConfiguration
public string[] DisallowedDomainSuffixes { get; set; } = new string[0];
public string[] DisallowedQueryTypes { get; set; } = new string[0];
public string[] HostFiles { get; set; } = new string[0];
public string? DhcpdLeasesFile { get; set; }
public string? DhcpdConfigFile { get; set; }
public string? DhcpdLeasesHostnameSuffix { get; set; }
public string? UpdateZoneName { get; set; }
public DnsInfluxDbConfiguration? InfluxDbMetrics { get; set; }
public Dictionary<string, string[]> ClientGroups { get; set; } = new Dictionary<string, string[]>();
Expand Down
22 changes: 7 additions & 15 deletions misc/Ae.Dns.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using System.Threading;
using System.Threading.Tasks;

#pragma warning disable CS0618 // Type or member is obsolete

namespace Ae.Dns.Console
{
class Program
Expand Down Expand Up @@ -191,24 +193,11 @@ async Task ReportStats(CancellationToken token)
staticLookupSources.Add(ActivatorUtilities.CreateInstance<HostsFileDnsLookupSource>(provider, new FileInfo(hostFile)));
}

if (!string.IsNullOrWhiteSpace(dnsConfiguration.DhcpdConfigFile))
{
staticLookupSources.Add(ActivatorUtilities.CreateInstance<DhcpdConfigDnsLookupSource>(provider, new FileInfo(dnsConfiguration.DhcpdConfigFile), dnsConfiguration.DhcpdLeasesHostnameSuffix ?? throw new NullReferenceException("DhcpdLeasesHostnameSuffix is null")));
}

if (!string.IsNullOrWhiteSpace(dnsConfiguration.DhcpdLeasesFile))
{
staticLookupSources.Add(ActivatorUtilities.CreateInstance<DhcpdLeasesDnsLookupSource>(provider, new FileInfo(dnsConfiguration.DhcpdLeasesFile), dnsConfiguration.DhcpdLeasesHostnameSuffix ?? throw new NullReferenceException("DhcpdLeasesHostnameSuffix is null")));
}

#pragma warning disable CS0618 // Type or member is obsolete
var dnsZone = new DnsZone();
staticLookupSources.Add(new DnsZoneLookupSource(dnsZone));

IDnsClient updateClient = DnsNotImplementedClient.Instance;

if (dnsConfiguration.UpdateZoneName != null)
{
var dnsZone = new DnsZone();
var zoneFile = $"{dnsConfiguration.UpdateZoneName}.zone";

if (File.Exists(zoneFile))
Expand All @@ -228,9 +217,12 @@ async Task ReportStats(CancellationToken token)
// Update the file when the zone is updated
dnsZone.ZoneUpdated = async zone => await File.WriteAllTextAsync(zoneFile, zone.SerializeZone());

// Replace the clients with clients for the zone
queryClient = new DnsZoneClient(queryClient, dnsZone);
updateClient = new DnsUpdateClient(dnsZone);
#pragma warning restore CS0618 // Type or member is obsolete

// Add the zone file as a source of automatic reverse lookups
staticLookupSources.Add(new DnsZoneLookupSource(dnsZone));
}

if (staticLookupSources.Count > 0)
Expand Down

0 comments on commit e532dd4

Please sign in to comment.