private void SaveDhcpdFile() { Directory.CreateDirectory("/etc/dhcp"); Directory.CreateDirectory(BindDirectory); Directory.CreateDirectory(BindZonesDirectory); var newModel = DhcpdConfiguration.Get(); newModel.ZoneName = _host.InternalDomainPrimary; newModel.ZonePrimaryAddress = _host.InternalHostIpPrimary; //newModel.SubnetIpFamily = EnumerableExtensions.JoinToString(_host.InternalHostIpPrimary.Split('.').Take(2), ".").TrimEnd('.') + ".0.0"; //newModel.SubnetIpMask = _host.InternalBroadcastPrimary; //newModel.SubnetOptionRouters = _host.InternalHostIpPrimary; //newModel.SubnetNtpServers = _host.InternalHostIpPrimary; //newModel.SubnetTimeServers = _host.InternalHostIpPrimary; //newModel.SubnetDomainNameServers = _host.InternalHostIpPrimary; //newModel.SubnetBroadcastAddress = _host.InternalHostIpPrimary; //newModel.SubnetMask = _host.InternalBroadcastPrimary; newModel.DdnsDomainName = _host.InternalDomainPrimary; DhcpdConfiguration.Save(newModel); DhcpdConfiguration.Set(); }
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 }
public AntdDhcpdModule() { Get["/dhcpd"] = x => { var dhcpdIsActive = DhcpdConfiguration.IsActive(); var model = new PageDhcpdModel { DhcpdIsActive = dhcpdIsActive, DhcpdOptions = DhcpdConfiguration.Get() ?? new DhcpdConfigurationModel(), DhcpdClass = DhcpdConfiguration.Get()?.Classes, DhcpdReservation = DhcpdConfiguration.Get()?.Reservations }; return(JsonConvert.SerializeObject(model)); }; Post["/dhcpd/set"] = x => { DhcpdConfiguration.Set(); return(HttpStatusCode.OK); }; Post["/dhcpd/restart"] = x => { DhcpdConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/dhcpd/stop"] = x => { DhcpdConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/dhcpd/enable"] = x => { DhcpdConfiguration.Enable(); DhcpdConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/dhcpd/disable"] = x => { DhcpdConfiguration.Disable(); DhcpdConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/dhcpd/options"] = x => { string allow = Request.Form.Allow; string updateStaticLeases = Request.Form.UpdateStaticLeases; string updateConflictDetection = Request.Form.UpdateConflictDetection; string useHostDeclNames = Request.Form.UseHostDeclNames; string doForwardUpdates = Request.Form.DoForwardUpdates; string doReverseUpdates = Request.Form.DoReverseUpdates; string logFacility = Request.Form.LogFacility; string option = Request.Form.Option; string zoneName = Request.Form.ZoneName; string zonePrimaryAddress = Request.Form.ZonePrimaryAddress; string ddnsUpdateStyle = Request.Form.DdnsUpdateStyle; string ddnsUpdates = Request.Form.DdnsUpdates; string ddnsDomainName = Request.Form.DdnsDomainName; string ddnsRevDomainName = Request.Form.DdnsRevDomainName; string defaultLeaseTime = Request.Form.DefaultLeaseTime; string maxLeaseTime = Request.Form.MaxLeaseTime; string keyName = Request.Form.KeyName; string keySecret = Request.Form.KeySecret; string ipFamily = Request.Form.IpFamily; string ipMask = Request.Form.IpMask; string optionRouters = Request.Form.OptionRouters; string ntpServers = Request.Form.NtpServers; string timeServers = Request.Form.DoForTimeServerswardUpdates; string domainNameServers = Request.Form.DomainNameServers; string broadcastAddress = Request.Form.BroadcastAddress; string subnetMask = Request.Form.SubnetMask; var model = new DhcpdConfigurationModel { Allow = allow.SplitToList().Select(_ => _.Trim()).ToList(), UpdateStaticLeases = updateStaticLeases, UpdateConflictDetection = updateConflictDetection, UseHostDeclNames = useHostDeclNames, DoForwardUpdates = doForwardUpdates, DoReverseUpdates = doReverseUpdates, LogFacility = logFacility, ZoneName = zoneName, ZonePrimaryAddress = zonePrimaryAddress, DdnsUpdateStyle = ddnsUpdateStyle, DdnsUpdates = ddnsUpdates, DdnsDomainName = ddnsDomainName, DdnsRevDomainName = ddnsRevDomainName, DefaultLeaseTime = defaultLeaseTime, MaxLeaseTime = maxLeaseTime, KeyName = keyName, KeySecret = keySecret }; DhcpdConfiguration.Save(model); return(HttpStatusCode.OK); }; Post["/dhcpd/class"] = x => { string name = Request.Form.Name; string macVendor = Request.Form.MacVendor; var model = new DhcpdClass { Name = name, VendorMacAddress = macVendor }; DhcpdConfiguration.AddClass(model); return(HttpStatusCode.OK); }; Post["/dhcpd/class/del"] = x => { string guid = Request.Form.Guid; DhcpdConfiguration.RemoveClass(guid); return(HttpStatusCode.OK); }; Post["/dhcpd/pool"] = x => { //string option = Request.Form.Option; //var model = new DhcpdPool { // Options = option.SplitToList().Select(_ => _.Trim()).ToList() //}; //DhcpdConfiguration.AddPool(model); return(HttpStatusCode.OK); }; Post["/dhcpd/pool/del"] = x => { string guid = Request.Form.Guid; //DhcpdConfiguration.RemovePool(guid); return(HttpStatusCode.OK); }; Post["/dhcpd/reservation"] = x => { string hostName = Request.Form.HostName; string macAddress = Request.Form.MacAddress; string ipAddress = Request.Form.IpAddress; var model = new DhcpdReservation { HostName = hostName, MacAddress = macAddress, IpAddress = ipAddress }; DhcpdConfiguration.AddReservation(model); return(HttpStatusCode.OK); }; Post["/dhcpd/reservation/del"] = x => { string guid = Request.Form.Guid; DhcpdConfiguration.RemoveReservation(guid); return(HttpStatusCode.OK); }; }