mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-04-01 15:03:30 +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,
|
"lease_duration":60,
|
||||||
"icmp_timeout_msec":0
|
"icmp_timeout_msec":0
|
||||||
},
|
},
|
||||||
|
"config_v6":{
|
||||||
|
"enabled":false,
|
||||||
|
"range_start":"...",
|
||||||
|
"lease_duration":60,
|
||||||
|
}
|
||||||
"leases":[
|
"leases":[
|
||||||
{"ip":"...","mac":"...","hostname":"...","expires":"..."}
|
{"ip":"...","mac":"...","hostname":"...","expires":"..."}
|
||||||
...
|
...
|
||||||
|
@ -463,14 +468,21 @@ Request:
|
||||||
POST /control/dhcp/set_config
|
POST /control/dhcp/set_config
|
||||||
|
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"enabled":true,
|
||||||
"interface_name":"vboxnet0",
|
"interface_name":"vboxnet0",
|
||||||
"gateway_ip":"192.169.56.1",
|
|
||||||
"subnet_mask":"255.255.255.0",
|
"gateway_ip":"192.169.56.1",
|
||||||
"range_start":"192.169.56.3",
|
"subnet_mask":"255.255.255.0",
|
||||||
"range_end":"192.169.56.3",
|
"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,
|
"lease_duration":60,
|
||||||
"icmp_timeout_msec":0
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Response:
|
Response:
|
||||||
|
|
|
@ -40,11 +40,34 @@ func convertLeases(inputLeases []Lease, includeExpires bool) []map[string]string
|
||||||
return leases
|
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) {
|
func (s *Server) handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
leases := convertLeases(s.Leases(LeasesDynamic), true)
|
leases := convertLeases(s.Leases(LeasesDynamic), true)
|
||||||
staticLeases := convertLeases(s.Leases(LeasesStatic), false)
|
staticLeases := convertLeases(s.Leases(LeasesStatic), false)
|
||||||
status := map[string]interface{}{
|
status := map[string]interface{}{
|
||||||
"config": s.conf,
|
"config": s.conf,
|
||||||
|
"config_v6": v6ServerConfToJSON(s.conf.Conf6),
|
||||||
"leases": leases,
|
"leases": leases,
|
||||||
"static_leases": staticLeases,
|
"static_leases": staticLeases,
|
||||||
}
|
}
|
||||||
|
@ -65,7 +88,7 @@ type staticLeaseJSON struct {
|
||||||
|
|
||||||
type dhcpServerConfigJSON struct {
|
type dhcpServerConfigJSON struct {
|
||||||
ServerConfig `json:",inline"`
|
ServerConfig `json:",inline"`
|
||||||
StaticLeases []staticLeaseJSON `json:"static_leases"`
|
V6 v6ServerConfJSON `json:"v6"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
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)
|
httpError(r, w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
|
||||||
return
|
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()
|
s.conf.ConfigModified()
|
||||||
|
|
||||||
if newconfig.Enabled {
|
if newconfig.Enabled {
|
||||||
|
|
|
@ -269,11 +269,9 @@ func (s *Server) Start() error {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.conf.Conf6.Enabled {
|
err = s.srv6.Start(*iface)
|
||||||
err := s.srv6.Start(*iface)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -284,6 +284,11 @@ func getIfaceIPv6(iface net.Interface) []net.IP {
|
||||||
|
|
||||||
// Start - start server
|
// Start - start server
|
||||||
func (s *V6Server) Start(iface net.Interface) error {
|
func (s *V6Server) Start(iface net.Interface) error {
|
||||||
|
if !s.conf.Enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug("DHCPv6: starting...")
|
||||||
s.conf.dnsIPAddrs = getIfaceIPv6(iface)
|
s.conf.dnsIPAddrs = getIfaceIPv6(iface)
|
||||||
if len(s.conf.dnsIPAddrs) == 0 {
|
if len(s.conf.dnsIPAddrs) == 0 {
|
||||||
return fmt.Errorf("DHCPv6: no IPv6 address for interface %s", iface.Name)
|
return fmt.Errorf("DHCPv6: no IPv6 address for interface %s", iface.Name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue