* control,dhcp: use dhcpServerConfigJSON struct

This commit is contained in:
Simon Zolin 2019-05-14 12:59:59 +03:00
parent cc366495d3
commit 626c1ae753
1 changed files with 7 additions and 3 deletions

10
dhcp.go
View File

@ -47,9 +47,13 @@ func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
} }
} }
type dhcpServerConfigJSON struct {
dhcpd.ServerConfig `json:",inline"`
}
func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) { func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
log.Tracef("%s %v", r.Method, r.URL) log.Tracef("%s %v", r.Method, r.URL)
newconfig := dhcpd.ServerConfig{} newconfig := dhcpServerConfigJSON{}
err := json.NewDecoder(r.Body).Decode(&newconfig) err := json.NewDecoder(r.Body).Decode(&newconfig)
if err != nil { if err != nil {
httpError(w, http.StatusBadRequest, "Failed to parse new DHCP config json: %s", err) httpError(w, http.StatusBadRequest, "Failed to parse new DHCP config json: %s", err)
@ -72,14 +76,14 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
} }
} }
err = dhcpServer.Start(&newconfig) err = dhcpServer.Start(&newconfig.ServerConfig)
if err != nil { if err != nil {
httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err) httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err)
return return
} }
} }
config.DHCP = newconfig config.DHCP = newconfig.ServerConfig
httpUpdateConfigReloadDNSReturnOK(w, r) httpUpdateConfigReloadDNSReturnOK(w, r)
} }