mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-03-24 02:59:06 +03:00
http status, set config
This commit is contained in:
parent
c8db736745
commit
f5a50e2bc3
4 changed files with 59 additions and 13 deletions
|
@ -405,6 +405,11 @@ Response:
|
|||
"lease_duration":60,
|
||||
"icmp_timeout_msec":0
|
||||
},
|
||||
"config_v6":{
|
||||
"enabled":false,
|
||||
"range_start":"...",
|
||||
"lease_duration":60,
|
||||
}
|
||||
"leases":[
|
||||
{"ip":"...","mac":"...","hostname":"...","expires":"..."}
|
||||
...
|
||||
|
@ -463,14 +468,21 @@ Request:
|
|||
POST /control/dhcp/set_config
|
||||
|
||||
{
|
||||
"enabled":true,
|
||||
"interface_name":"vboxnet0",
|
||||
"gateway_ip":"192.169.56.1",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"range_start":"192.169.56.3",
|
||||
"range_end":"192.169.56.3",
|
||||
"enabled":true,
|
||||
"interface_name":"vboxnet0",
|
||||
|
||||
"gateway_ip":"192.169.56.1",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"range_start":"192.169.56.100",
|
||||
"range_end":"192.169.56.200",
|
||||
"lease_duration":60,
|
||||
"icmp_timeout_msec":0,
|
||||
|
||||
"v6":{
|
||||
"enabled":false,
|
||||
"range_start":"...",
|
||||
"lease_duration":60,
|
||||
"icmp_timeout_msec":0
|
||||
}
|
||||
}
|
||||
|
||||
Response:
|
||||
|
|
|
@ -40,11 +40,34 @@ func convertLeases(inputLeases []Lease, includeExpires bool) []map[string]string
|
|||
return leases
|
||||
}
|
||||
|
||||
type v6ServerConfJSON struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
RangeStart string `json:"range_start"`
|
||||
LeaseDuration uint32 `json:"lease_duration"`
|
||||
}
|
||||
|
||||
func v6ServerConfToJSON(c V6ServerConf) v6ServerConfJSON {
|
||||
return v6ServerConfJSON{
|
||||
Enabled: c.Enabled,
|
||||
RangeStart: c.RangeStart,
|
||||
LeaseDuration: c.LeaseDuration,
|
||||
}
|
||||
}
|
||||
|
||||
func v6JSONToServerConf(c v6ServerConfJSON) V6ServerConf {
|
||||
return V6ServerConf{
|
||||
Enabled: c.Enabled,
|
||||
RangeStart: c.RangeStart,
|
||||
LeaseDuration: c.LeaseDuration,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
||||
leases := convertLeases(s.Leases(LeasesDynamic), true)
|
||||
staticLeases := convertLeases(s.Leases(LeasesStatic), false)
|
||||
status := map[string]interface{}{
|
||||
"config": s.conf,
|
||||
"config_v6": v6ServerConfToJSON(s.conf.Conf6),
|
||||
"leases": leases,
|
||||
"static_leases": staticLeases,
|
||||
}
|
||||
|
@ -65,7 +88,7 @@ type staticLeaseJSON struct {
|
|||
|
||||
type dhcpServerConfigJSON struct {
|
||||
ServerConfig `json:",inline"`
|
||||
StaticLeases []staticLeaseJSON `json:"static_leases"`
|
||||
V6 v6ServerConfJSON `json:"v6"`
|
||||
}
|
||||
|
||||
func (s *Server) handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -92,6 +115,14 @@ func (s *Server) handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
|||
httpError(r, w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
s6, err := v6Create(v6JSONToServerConf(newconfig.V6))
|
||||
if s6 == nil {
|
||||
httpError(r, w, http.StatusBadRequest, "Invalid DHCPv6 configuration: %s", err)
|
||||
return
|
||||
}
|
||||
s.srv6 = s6
|
||||
|
||||
s.conf.ConfigModified()
|
||||
|
||||
if newconfig.Enabled {
|
||||
|
|
|
@ -269,11 +269,9 @@ func (s *Server) Start() error {
|
|||
}()
|
||||
}
|
||||
|
||||
if s.conf.Conf6.Enabled {
|
||||
err := s.srv6.Start(*iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.srv6.Start(*iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -284,6 +284,11 @@ func getIfaceIPv6(iface net.Interface) []net.IP {
|
|||
|
||||
// Start - start server
|
||||
func (s *V6Server) Start(iface net.Interface) error {
|
||||
if !s.conf.Enabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug("DHCPv6: starting...")
|
||||
s.conf.dnsIPAddrs = getIfaceIPv6(iface)
|
||||
if len(s.conf.dnsIPAddrs) == 0 {
|
||||
return fmt.Errorf("DHCPv6: no IPv6 address for interface %s", iface.Name)
|
||||
|
|
Loading…
Add table
Reference in a new issue