DnsWebService: Save zone file code updated to allow storing all records for a given authoritative zone in a single file instead of different file for each sub domain. Implemented delete zone file feature accordingly.

This commit is contained in:
Shreyas Zare
2017-11-17 18:54:11 +05:30
parent 1e59c2f677
commit 0cef5021f5

View File

@@ -691,10 +691,8 @@ namespace DnsServerCore
if (string.IsNullOrEmpty(domain))
throw new DnsWebServiceException("Parameter 'domain' missing.");
string[] deletedZones = _dnsServer.AuthoritativeZoneRoot.DeleteZone(domain);
foreach (string deletedZone in deletedZones)
DeleteZoneFile(deletedZone);
_dnsServer.AuthoritativeZoneRoot.DeleteZone(domain);
DeleteZoneFile(domain);
}
private void EnableZone(HttpListenerRequest request)
@@ -1311,26 +1309,22 @@ namespace DnsServerCore
private void SaveZoneFile(string domain)
{
domain = domain.ToLower();
DnsResourceRecord[] records = _dnsServer.AuthoritativeZoneRoot.GetAllRecords(domain, false);
DnsResourceRecord[] records = _dnsServer.AuthoritativeZoneRoot.GetAllRecords(domain, true, true);
if ((records == null) || (records.Length == 0))
{
DeleteZoneFile(domain);
}
else
{
using (FileStream fS = new FileStream(Path.Combine(_configFolder, domain + ".zone"), FileMode.Create, FileAccess.Write))
{
BincodingEncoder encoder = new BincodingEncoder(fS, "DZ", 1);
string authZone = records[0].Name.ToLower();
encoder.Encode(records);
}
using (FileStream fS = new FileStream(Path.Combine(_configFolder, authZone + ".zone"), FileMode.Create, FileAccess.Write))
{
BincodingEncoder encoder = new BincodingEncoder(fS, "DZ", 1);
encoder.Encode(records);
}
}
private void DeleteZoneFile(string domain)
{
domain = domain.ToLower();
File.Delete(Path.Combine(_configFolder, domain + ".zone"));
}