public AntdBindModule() { Get["/bind"] = x => { var model = new PageBindModel(); var bindConfiguration = new BindConfiguration(); var bindIsActive = bindConfiguration.IsActive(); model.BindIsActive = bindIsActive; model.BindOptions = bindConfiguration.Get() ?? new BindConfigurationModel(); model.BindZones = bindConfiguration.Get()?.Zones; return(JsonConvert.SerializeObject(model)); }; Post["/bind/set"] = x => { var bindConfiguration = new BindConfiguration(); bindConfiguration.Set(); return(HttpStatusCode.OK); }; Post["/bind/restart"] = x => { var bindConfiguration = new BindConfiguration(); bindConfiguration.Start(); bindConfiguration.RndcReconfig(); bindConfiguration.RndcReload(); return(HttpStatusCode.OK); }; Post["/bind/stop"] = x => { var bindConfiguration = new BindConfiguration(); bindConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/bind/enable"] = x => { var dhcpdConfiguration = new BindConfiguration(); dhcpdConfiguration.Enable(); dhcpdConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/bind/disable"] = x => { var dhcpdConfiguration = new BindConfiguration(); dhcpdConfiguration.Disable(); dhcpdConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/bind/options"] = x => { string notify = Request.Form.Notify; string maxCacheSize = Request.Form.MaxCacheSize; string maxCacheTtl = Request.Form.MaxCacheTtl; string maxNcacheTtl = Request.Form.MaxNcacheTtl; string forwarders = Request.Form.Forwarders; string allowNotify = Request.Form.AllowNotify; string allowTransfer = Request.Form.AllowTransfer; string recursion = Request.Form.Recursion; string transferFormat = Request.Form.TransferFormat; string querySourceAddress = Request.Form.QuerySourceAddress; string querySourcePort = Request.Form.QuerySourcePort; string version = Request.Form.Version; string allowQuery = Request.Form.AllowQuery; string allowRecursion = Request.Form.AllowRecursion; string ixfrFromDifferences = Request.Form.IxfrFromDifferences; string listenOnV6 = Request.Form.ListenOnV6; string listenOnPort53 = Request.Form.ListenOnPort53; string dnssecEnabled = Request.Form.DnssecEnabled; string dnssecValidation = Request.Form.DnssecValidation; string dnssecLookaside = Request.Form.DnssecLookaside; string authNxdomain = Request.Form.AuthNxdomain; string keyName = Request.Form.KeyName; string keySecret = Request.Form.KeySecret; string controlAcl = Request.Form.ControlAcl; string controlIp = Request.Form.ControlIp; string controlPort = Request.Form.ControlPort; string controlAllow = Request.Form.ControlAllow; string loggingChannel = Request.Form.LoggingChannel; string loggingDaemon = Request.Form.LoggingDaemon; string loggingSeverity = Request.Form.LoggingSeverity; string loggingPrintCategory = Request.Form.LoggingPrintCategory; string loggingPrintSeverity = Request.Form.LoggingPrintSeverity; string loggingPrintTime = Request.Form.LoggingPrintTime; string trustedKeys = Request.Form.TrustedKey; string aclLocalInterfaces = Request.Form.AclLocalInterfaces; string aclInternalInterfaces = Request.Form.AclInternalInterfaces; string aclExternalInterfaces = Request.Form.AclExternalInterfaces; string aclLocalNetworks = Request.Form.AclLocalNetworks; string aclInternalNetworks = Request.Form.AclInternalNetworks; string aclExternalNetworks = Request.Form.AclExternalNetworks; var model = new BindConfigurationModel { Notify = notify, MaxCacheSize = maxCacheSize, MaxCacheTtl = maxCacheTtl, MaxNcacheTtl = maxNcacheTtl, Forwarders = forwarders.SplitToList().Select(_ => _.Trim()).ToList(), AllowNotify = allowNotify.SplitToList().Select(_ => _.Trim()).ToList(), AllowTransfer = allowTransfer.SplitToList().Select(_ => _.Trim()).ToList(), Recursion = recursion, TransferFormat = transferFormat, QuerySourceAddress = querySourceAddress, QuerySourcePort = querySourcePort, Version = version, AllowQuery = allowQuery.SplitToList().Select(_ => _.Trim()).ToList(), AllowRecursion = allowRecursion.SplitToList().Select(_ => _.Trim()).ToList(), IxfrFromDifferences = ixfrFromDifferences, ListenOnV6 = listenOnV6.SplitToList().Select(_ => _.Trim()).ToList(), ListenOnPort53 = listenOnPort53.SplitToList().Select(_ => _.Trim()).ToList(), DnssecEnabled = dnssecEnabled, DnssecValidation = dnssecValidation, DnssecLookaside = dnssecLookaside, AuthNxdomain = authNxdomain, KeyName = keyName, KeySecret = keySecret, ControlAcl = controlAcl, ControlIp = controlIp, ControlPort = controlPort, ControlAllow = controlAllow.SplitToList().Select(_ => _.Trim()).ToList(), LoggingChannel = loggingChannel, LoggingDaemon = loggingDaemon, LoggingSeverity = loggingSeverity, LoggingPrintCategory = loggingPrintCategory, LoggingPrintSeverity = loggingPrintSeverity, LoggingPrintTime = loggingPrintTime, TrustedKeys = trustedKeys, AclLocalInterfaces = aclLocalInterfaces.SplitToList().Select(_ => _.Trim()).ToList(), AclInternalInterfaces = aclInternalInterfaces.SplitToList().Select(_ => _.Trim()).ToList(), AclExternalInterfaces = aclExternalInterfaces.SplitToList().Select(_ => _.Trim()).ToList(), AclLocalNetworks = aclLocalNetworks.SplitToList().Select(_ => _.Trim()).ToList(), AclInternalNetworks = aclInternalNetworks.SplitToList().Select(_ => _.Trim()).ToList(), AclExternalNetworks = aclExternalNetworks.SplitToList().Select(_ => _.Trim()).ToList() }; var bindConfiguration = new BindConfiguration(); bindConfiguration.Save(model); return(HttpStatusCode.OK); }; Post["/bind/zone"] = x => { string name = Request.Form.Name; string type = Request.Form.Type; string file = Request.Form.File; string serialUpdateMethod = Request.Form.NameSerialUpdateMethod; string allowUpdate = Request.Form.AllowUpdate; string allowQuery = Request.Form.AllowQuery; string allowTransfer = Request.Form.AllowTransfer; var model = new BindConfigurationZoneModel { Name = name, Type = type, File = file, SerialUpdateMethod = serialUpdateMethod, AllowQuery = allowQuery.SplitToList().Select(_ => _.Trim()).ToList(), AllowUpdate = allowUpdate.SplitToList().Select(_ => _.Trim()).ToList(), AllowTransfer = allowTransfer.SplitToList().Select(_ => _.Trim()).ToList() }; var bindConfiguration = new BindConfiguration(); bindConfiguration.AddZone(model); return(HttpStatusCode.OK); }; Post["/bind/zone/del"] = x => { string guid = Request.Form.Guid; var bindConfiguration = new BindConfiguration(); bindConfiguration.RemoveZone(guid); return(HttpStatusCode.OK); }; }
private void SaveNamedFile() { Directory.CreateDirectory(BindDirectory); Directory.CreateDirectory(BindZonesDirectory); var newModel = BindConfiguration.Get(); if (!newModel.Forwarders.Contains(_host.InternalHostIpPrimary)) { newModel.Forwarders.Add(_host.InternalHostIpPrimary); } if (!newModel.Forwarders.Contains(_host.ExternalHostIpPrimary)) { newModel.Forwarders.Add(_host.ExternalHostIpPrimary); } newModel.ControlIp = _host.InternalHostIpPrimary; //if(!newModel.AclInternalInterfaces.Contains(_host.InternalHostIpPrimary)) { // newModel.AclInternalInterfaces.Add(_host.InternalHostIpPrimary); //} //if(!newModel.AclExternalInterfaces.Contains(_host.ExternalHostIpPrimary)) { // newModel.AclExternalInterfaces.Add(_host.ExternalHostIpPrimary); //} //if(!newModel.AclInternalNetworks.Contains(_host.InternalNetPrimary)) { // newModel.AclInternalNetworks.Add(_host.InternalNetPrimary); //} //if(!newModel.AclExternalNetworks.Contains(_host.ExternalNetPrimary)) { // newModel.AclExternalNetworks.Add(_host.ExternalNetPrimary); //} var zones = newModel.Zones; var internalZoneName = _host.InternalDomainPrimary; if (newModel.Zones.FirstOrDefault(_ => _.Name == internalZoneName) == null) { var filePath = $"{BindZonesDirectory}/host.{internalZoneName}.db"; var z = new BindConfigurationZoneModel { Guid = Guid.NewGuid().ToString(), File = filePath, SerialUpdateMethod = "unixtime", AllowUpdate = new List <string> { "loif", "iif", "lonet", "inet", "onet", "key updbindkey" }, AllowQuery = new List <string> { "any" }, AllowTransfer = new List <string> { "loif", "iif", "lonet", "inet", "onet" } }; zones.Add(z); } var internalReverseZoneName = _host.InternalArpaPrimary; if (newModel.Zones.FirstOrDefault(_ => _.Name == internalReverseZoneName) == null) { var filePath = $"{BindZonesDirectory}/rev.{internalReverseZoneName}.db"; var z = new BindConfigurationZoneModel { Guid = Guid.NewGuid().ToString(), File = filePath, SerialUpdateMethod = "unixtime", AllowUpdate = new List <string> { "loif", "iif", "lonet", "inet", "onet", "key updbindkey" }, AllowQuery = new List <string> { "any" }, AllowTransfer = new List <string> { "loif", "iif", "lonet", "inet", "onet" } }; zones.Add(z); } var externalZoneName = _host.ExternalDomainPrimary; if (newModel.Zones.FirstOrDefault(_ => _.Name == externalZoneName) == null) { var filePath = $"{BindZonesDirectory}/host.{externalZoneName}.db"; var z = new BindConfigurationZoneModel { Guid = Guid.NewGuid().ToString(), File = filePath, SerialUpdateMethod = "unixtime", AllowUpdate = new List <string> { "loif", "iif", "lonet", "inet", "onet", "key updbindkey" }, AllowQuery = new List <string> { "any" }, AllowTransfer = new List <string> { "loif", "iif", "lonet", "inet", "onet" } }; zones.Add(z); } var externalReverseZoneName = _host.ExternalArpaPrimary; if (newModel.Zones.FirstOrDefault(_ => _.Name == externalReverseZoneName) == null) { var filePath = $"{BindZonesDirectory}/rev.{externalReverseZoneName}.db"; var z = new BindConfigurationZoneModel { Guid = Guid.NewGuid().ToString(), File = filePath, SerialUpdateMethod = "unixtime", AllowUpdate = new List <string> { "loif", "iif", "lonet", "inet", "onet", "key updbindkey" }, AllowQuery = new List <string> { "any" }, AllowTransfer = new List <string> { "loif", "iif", "lonet", "inet", "onet" } }; zones.Add(z); } newModel.Zones = zones; var zonesFile = newModel.ZoneFiles; if (newModel.ZoneFiles.FirstOrDefault(_ => _.Name == $"{BindZonesDirectory}/host.{internalZoneName}.db") == null) { var filePath = $"{BindZonesDirectory}/host.{internalZoneName}.db"; var z = new BindConfigurationZoneFileModel { Guid = Guid.NewGuid().ToString(), Name = filePath, Configuration = "unixtime" }; zonesFile.Add(z); File.WriteAllLines(filePath, BindConfiguration.GetHostZoneText(_host.HostName, _host.InternalDomainPrimary, _host.InternalHostIpPrimary)); } if (newModel.ZoneFiles.FirstOrDefault(_ => _.Name == $"{BindZonesDirectory}/rev.{internalReverseZoneName}.db") == null) { var filePath = $"{BindZonesDirectory}/rev.{internalReverseZoneName}.db"; var z = new BindConfigurationZoneFileModel { Guid = Guid.NewGuid().ToString(), Name = filePath, Configuration = "unixtime" }; zonesFile.Add(z); File.WriteAllLines(filePath, BindConfiguration.GetReverseZoneText(_host.HostName, _host.InternalDomainPrimary, _host.InternalArpaPrimary, _host.InternalHostIpPrimary.Split('.').Skip(2).JoinToString("."))); } if (newModel.ZoneFiles.FirstOrDefault(_ => _.Name == $"{BindZonesDirectory}/host.{externalZoneName}.db") == null) { var filePath = $"{BindZonesDirectory}/host.{externalZoneName}.db"; var z = new BindConfigurationZoneFileModel { Guid = Guid.NewGuid().ToString(), Name = filePath, Configuration = "unixtime" }; zonesFile.Add(z); File.WriteAllLines(filePath, BindConfiguration.GetHostZoneText(_host.HostName, _host.ExternalDomainPrimary, _host.ExternalHostIpPrimary)); } if (newModel.ZoneFiles.FirstOrDefault(_ => _.Name == $"{BindZonesDirectory}/rev.{externalReverseZoneName}.db") == null) { var filePath = $"{BindZonesDirectory}/rev.{externalReverseZoneName}.db"; var z = new BindConfigurationZoneFileModel { Guid = Guid.NewGuid().ToString(), Name = filePath, Configuration = "unixtime" }; zonesFile.Add(z); File.WriteAllLines(filePath, BindConfiguration.GetReverseZoneText(_host.HostName, _host.ExternalDomainPrimary, _host.ExternalArpaPrimary, _host.ExternalHostIpPrimary.Split('.').Skip(2).JoinToString("."))); } newModel.ZoneFiles = zonesFile; BindConfiguration.Save(newModel); BindConfiguration.Set(); }