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(); }
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 static void FallbackProcedures() { Logger.Info("[config] fallback procedures"); if (!Parameter.IsUnix) { return; } const string localNetwork = "10.11.0.0"; const string localIp = "10.11.254.254"; const string localRange = "16"; const string localHostname = "box01"; const string localDomain = "install.local"; #region [ Host Configuration ] HostConfiguration.SetHostInfoName(localHostname); HostConfiguration.ApplyHostInfo(); Logger.Info("host configured"); #endregion #region [ Name Service ] HostConfiguration.SetNsHosts(new[] { "127.0.0.1 localhost", $"{localIp} {localHostname}.{localDomain} {localHostname}" }); HostConfiguration.ApplyNsHosts(); HostConfiguration.SetNsNetworks(new[] { "loopback 127.0.0.0", "link-local 169.254.0.0", $"{localDomain} {localNetwork}" }); HostConfiguration.ApplyNsNetworks(); HostConfiguration.SetNsResolv(new[] { $"nameserver {localIp}", $"search {localDomain}", $"domain {localDomain}" }); HostConfiguration.ApplyNsResolv(); HostConfiguration.SetNsSwitch(new[] { "passwd: compat db files nis", "shadow: compat db files nis", "group: compat db files nis", "hosts: files dns", "networks: files dns", "services: db files", "protocols: db files", "rpc: db files", "ethers: db files", "netmasks: files", "netgroup: files", "bootparams: files", "automount: files", "aliases: files" }); HostConfiguration.ApplyNsSwitch(); Logger.Info("name service ready"); #endregion #region [ Network ] var npi = NetworkConfiguration.InterfacePhysical; var nifs = NetworkConfiguration.Get().Interfaces; const string nifName = "br0"; var tryget = nifs?.FirstOrDefault(_ => _.Interface == nifName); if (tryget == null) { NetworkConfiguration.AddInterfaceSetting(new NetworkInterfaceConfigurationModel { Interface = nifName, Mode = NetworkInterfaceMode.Static, Status = NetworkInterfaceStatus.Up, StaticAddress = localIp, StaticRange = localRange, Type = NetworkInterfaceType.Bridge, InterfaceList = npi.ToList() }); } NetworkConfiguration.ApplyDefaultInterfaceSetting(); #endregion #region [ Dhcpd ] DhcpdConfiguration.Save(new DhcpdConfigurationModel { ZoneName = localDomain, ZonePrimaryAddress = localIp, DdnsDomainName = $"{localDomain}.", Option = new List <string> { $"domain-name \"{localDomain}\"", "routers eth0", "local-proxy-config code 252 = text" }, KeySecret = "ND991KFHCCA9tUrafsf29uxDM3ZKfnrVR4f1I2J27Ow=", SubnetNtpServers = localIp, SubnetTimeServers = localIp, SubnetOptionRouters = localIp, SubnetDomainNameServers = localIp, SubnetIpMask = "255.255.0.0", SubnetMask = "255.255.0.0", SubnetBroadcastAddress = "10.11.255.255", SubnetIpFamily = localNetwork }); DhcpdConfiguration.Set(); #endregion #region [ Bind ] BindConfiguration.Save(new BindConfigurationModel { ControlIp = localIp, AclInternalInterfaces = new List <string> { localIp }, AclInternalNetworks = new List <string> { $"{localNetwork}/{localRange}" }, Zones = new List <BindConfigurationZoneModel> { new BindConfigurationZoneModel { Name = "11.10.in-addr.arpa", Type = "master", File = "" //todo crea e gestisci file della zona }, new BindConfigurationZoneModel { Name = localDomain, Type = "master", File = "" //todo crea e gestisci file della zona }, } }); BindConfiguration.Set(); #endregion }