/dhcp/find_active_dhcp -- use interface name from request body

This commit is contained in:
Eugene Bujak 2018-12-29 16:39:29 +03:00
parent 7ab03e9335
commit 4efa30edc4
1 changed files with 16 additions and 1 deletions

17
dhcp.go
View File

@ -121,7 +121,22 @@ func handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
}
func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
found, err := dhcpd.CheckIfOtherDHCPServersPresent(config.DHCP.InterfaceName)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
errorText := fmt.Sprintf("failed to read request body: %s", err)
log.Println(errorText)
http.Error(w, errorText, http.StatusBadRequest)
return
}
interfaceName := strings.TrimSpace(string(body))
if interfaceName == "" {
errorText := fmt.Sprintf("empty interface name specified")
log.Println(errorText)
http.Error(w, errorText, http.StatusBadRequest)
return
}
found, err := dhcpd.CheckIfOtherDHCPServersPresent(interfaceName)
result := map[string]interface{}{}
if err != nil {
result["error"] = err.Error()