예제 #1
0
        private void AddDnsServer(string dnsServer)
        {
            try
            {
                var dnsServerIPEndPoint = Cleaners.MakeDnsIPEndPoint(dnsServer);
                DnsServers.Add(dnsServerIPEndPoint);

                Logger.Debug($"'{dnsServerIPEndPoint}' has been added as Resolving DNS Server");
            }
            catch (Exception ex)
            {
                Logger.Error($"Could not add '{dnsServer}' as DNS Server", ex);
            }
        }
예제 #2
0
        private void AddDnsZone(IConfigurationSection dnsZone)
        {
            string            zone = string.Empty;
            List <IPEndPoint> ips  = new List <IPEndPoint>();

            try
            {
                if (string.IsNullOrEmpty(dnsZone["zone"]))
                {
                    throw new Exception("'zone' cannot be empty for DNS zone");
                }

                zone = dnsZone["zone"];

                var servers = dnsZone.GetSection("servers");

                if (servers.GetChildren().Count() == 0 && servers.Value == null)
                {
                    throw new Exception("'servers' cannot be empty for DNS zone");
                }
                if (ConfigSectionArray(servers))
                {
                    foreach (var server in servers.GetChildren())
                    {
                        ips.Add(Cleaners.MakeDnsIPEndPoint(server.Value));
                    }
                }
                else
                {
                    ips.Add(Cleaners.MakeDnsIPEndPoint(servers.Value));
                }

                var newLocalZone = new LocalZone(zone, ips);
                LocalZones.Add(newLocalZone);

                Logger.Debug($"'{newLocalZone}' has been added to DNS Zone Overrides");
            }
            catch (Exception ex)
            {
                Logger.Error($"Could not add Local DNS Server", ex);
            }
        }
예제 #3
0
        public DnsConfig()
        {
            _Config = new ConfigurationBuilder()
                      .AddJsonFile("dns.json", optional: false, reloadOnChange: true)
                      .Build();

            var serverAliases = _Config.GetSection("serverAliases");
            var dnsServers    = _Config.GetSection("dnsServers");
            var searchDomains = _Config.GetSection("searchDomains");
            var hostOverrides = _Config.GetSection("hostOverrides");
            var dnsZones      = _Config.GetSection("dnsZones");
            var fileZones     = _Config.GetSection("fileZones");
            var blackLists    = _Config.GetSection("blackLists");

            if (ConfigSectionArray(dnsServers))
            {
                foreach (var dnsServer in dnsServers.GetChildren())
                {
                    AddDnsServer(dnsServer.Value);
                }
            }
            else
            {
                DnsServers.Add(Cleaners.MakeDnsIPEndPoint(dnsServers.Value));
            }

            if (ConfigSectionArray(searchDomains))
            {
                foreach (var searchDomain in searchDomains.GetChildren())
                {
                    AddSearchDomain(searchDomain.Value);
                }
            }
            else
            {
                SearchDomains.Add(Cleaners.MakeDnsZoneProper(searchDomains.Value));
            }

            if (ConfigSectionArray(hostOverrides))
            {
                foreach (var hostOverride in hostOverrides.GetChildren())
                {
                    AddHostOverride(hostOverride);
                }
            }
            else
            {
                AddHostOverride(hostOverrides.GetChildren().First());
            }

            if (ConfigSectionArray(dnsZones))
            {
                foreach (var dnsZone in dnsZones.GetChildren())
                {
                    AddDnsZone(dnsZone);
                }
            }
            else
            {
                AddDnsZone(dnsZones);
            }

            if (ConfigSectionArray(blackLists))
            {
                foreach (var blackList in blackLists.GetChildren())
                {
                    AddBlackList(blackList);
                }
            }
            else
            {
                AddBlackList(blackLists);
            }

            Logger.Info("Configuration file has been loaded");
        }