From 82a60a73fd7217c3ae0882cd12fb8c90fc2dd9a5 Mon Sep 17 00:00:00 2001 From: erikssonk Date: Tue, 17 Sep 2013 16:13:49 +0200 Subject: [PATCH 1/3] * Fixed reloading of zones on zone updates * Added two args for ReloadBIND, Arguments and zoneName * Changed the behavior of zone reloading to just reload that zone --- .../IscBind.cs | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs b/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs index d039fc1f..321a0e5f 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs @@ -30,10 +30,12 @@ using System; using System.IO; using System.Collections.Generic; using System.Text; +using System.Diagnostics; using System.ServiceProcess; using WebsitePanel.Server.Utils; using WebsitePanel.Providers.Utils; + namespace WebsitePanel.Providers.DNS { public class IscBind : HostingServiceProviderBase, IDnsServer @@ -152,9 +154,6 @@ namespace WebsitePanel.Providers.DNS // add DNS zone UpdateZone(zoneName, records); - - // reload config - ReloadBIND(); } public virtual void AddSecondaryZone(string zoneName, string[] masterServers) @@ -185,7 +184,7 @@ namespace WebsitePanel.Providers.DNS File.Create(GetZoneFilePath(zoneName)).Close(); // reload config - ReloadBIND(); + //ReloadBIND(); No need, we don't have a valid NS record, will generate a servfail on bind } public virtual DnsRecord[] GetZoneRecords(string zoneName) @@ -256,7 +255,7 @@ namespace WebsitePanel.Providers.DNS File.Delete(zonePath); // reload config - ReloadBIND(); + ReloadBIND("reconfig", ""); } #endregion @@ -912,6 +911,10 @@ namespace WebsitePanel.Providers.DNS { string path = GetZoneFilePath(zoneName); File.WriteAllText(path, zoneContent); + + // This is need so bind reloads after update else you will get serverfail if new zone + // If update the change will not be accesseble from bind + ReloadBIND("reload", zoneName); } private string GetZoneFilePath(string zoneName) @@ -924,10 +927,26 @@ namespace WebsitePanel.Providers.DNS return StringUtils.ReplaceStringVariable(ZoneFileNameTemplate, "domain_name", zoneName); } - private void ReloadBIND() + private void ReloadBIND(string Args, string zoneName) { - FileUtils.ExecuteSystemCommand(BindReloadBatch, ""); + // We don't use a bat file for reloading all zone files.. that's crazy talk + // Both bind 8 & 9 supports reloadind it's config and or reloading a single zone file + // rndc reconfig Will reload named.conf (perfect when adding a primary zone) + // rnd reload mydomain.com will reload the domain and only that domain + // Used Bind Reload Batch for inputing correct path to rndc + // Best Reguards, kenneth@cancode.se + Process rndc = new Process(); + + rndc.StartInfo.FileName = BindReloadBatch; + string rndcArguments = Args; + if (zoneName.Length > 0) { + rndcArguments += " " + zoneName; + } + rndc.StartInfo.Arguments = rndcArguments; + rndc.StartInfo.CreateNoWindow = true; + rndc.Start(); } + #endregion public override bool IsInstalled() From d8b0f858a7d8a7ebd60c20537be375f4d2a15cd5 Mon Sep 17 00:00:00 2001 From: erikssonk Date: Tue, 17 Sep 2013 16:56:39 +0200 Subject: [PATCH 2/3] Change where the ReloadBIND was calld from, also fixed a typo. --- .../WebsitePanel.Providers.DNS.Bind/IscBind.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs b/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs index 321a0e5f..77e741c5 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs @@ -151,7 +151,7 @@ namespace WebsitePanel.Providers.DNS soa.PrimaryNsServer = System.Net.Dns.GetHostEntry("LocalHost").HostName; soa.PrimaryPerson = "hostmaster";//"hostmaster." + zoneName; records.Add(soa); - + ReloadBIND("reconfig", ""); // add DNS zone UpdateZone(zoneName, records); } @@ -184,7 +184,7 @@ namespace WebsitePanel.Providers.DNS File.Create(GetZoneFilePath(zoneName)).Close(); // reload config - //ReloadBIND(); No need, we don't have a valid NS record, will generate a servfail on bind + ReloadBIND("reconfig", ""); } public virtual DnsRecord[] GetZoneRecords(string zoneName) @@ -254,9 +254,9 @@ namespace WebsitePanel.Providers.DNS if (File.Exists(zonePath)) File.Delete(zonePath); - // reload config + // reload named.conf ReloadBIND("reconfig", ""); - } + } #endregion #region Resource records @@ -818,6 +818,7 @@ namespace WebsitePanel.Providers.DNS // update zone file UpdateZoneFile(zoneName, sb.ToString()); + ReloadBIND("reload", zoneName); } private string CorrectRecordName(string zoneName, string host) @@ -911,11 +912,7 @@ namespace WebsitePanel.Providers.DNS { string path = GetZoneFilePath(zoneName); File.WriteAllText(path, zoneContent); - - // This is need so bind reloads after update else you will get serverfail if new zone - // If update the change will not be accesseble from bind - ReloadBIND("reload", zoneName); - } + } private string GetZoneFilePath(string zoneName) { @@ -932,7 +929,7 @@ namespace WebsitePanel.Providers.DNS // We don't use a bat file for reloading all zone files.. that's crazy talk // Both bind 8 & 9 supports reloadind it's config and or reloading a single zone file // rndc reconfig Will reload named.conf (perfect when adding a primary zone) - // rnd reload mydomain.com will reload the domain and only that domain + // rndc reload mydomain.com will reload the domain and only that domain // Used Bind Reload Batch for inputing correct path to rndc // Best Reguards, kenneth@cancode.se Process rndc = new Process(); From a151a24e816330aa420ac2286428697159656254 Mon Sep 17 00:00:00 2001 From: erikssonk Date: Sun, 29 Sep 2013 11:46:51 +0200 Subject: [PATCH 3/3] Detect rndc.exe in BindReloadBatch var, if so use it correctly. --- .../IscBind.cs | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs b/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs index 77e741c5..923c54a7 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.DNS.Bind/IscBind.cs @@ -926,22 +926,37 @@ namespace WebsitePanel.Providers.DNS private void ReloadBIND(string Args, string zoneName) { - // We don't use a bat file for reloading all zone files.. that's crazy talk - // Both bind 8 & 9 supports reloadind it's config and or reloading a single zone file - // rndc reconfig Will reload named.conf (perfect when adding a primary zone) - // rndc reload mydomain.com will reload the domain and only that domain - // Used Bind Reload Batch for inputing correct path to rndc - // Best Reguards, kenneth@cancode.se - Process rndc = new Process(); - rndc.StartInfo.FileName = BindReloadBatch; - string rndcArguments = Args; - if (zoneName.Length > 0) { - rndcArguments += " " + zoneName; + // Do we have a rndc.exe? if so use it - improves handling + if (BindReloadBatch.IndexOf("rndc.exe") > 0) + { + Process rndc = new Process(); + rndc.StartInfo.FileName = BindReloadBatch; + string rndcArguments = Args; + if (zoneName.Length > 0) + { + rndcArguments += " " + zoneName; + } + rndc.StartInfo.Arguments = rndcArguments; + rndc.StartInfo.CreateNoWindow = true; + rndc.Start(); + + /* + * Can't figure out how to log the output of the process to auditlog. If someone could be of assistans and fix this. + * it's rndcOutput var that should be written to audit log.s + * + string rndcOutput = ""; + while (!rndc.StandardOutput.EndOfStream) + { + rndcOutput += rndc.StandardOutput.ReadLine(); + } + */ + + } + else + { + FileUtils.ExecuteSystemCommand(BindReloadBatch, ""); } - rndc.StartInfo.Arguments = rndcArguments; - rndc.StartInfo.CreateNoWindow = true; - rndc.Start(); } #endregion