From 4efa30edc4bb20ea52191be09d3d83f789a880e8 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Sat, 29 Dec 2018 16:39:29 +0300 Subject: [PATCH] /dhcp/find_active_dhcp -- use interface name from request body --- dhcp.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dhcp.go b/dhcp.go index 33d27467..890ba6b4 100644 --- a/dhcp.go +++ b/dhcp.go @@ -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()