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(); }
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); }; }