From cf7967390d10a24f69664276a57f18643ed7880e Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Tue, 17 Jun 2014 06:02:54 +0000 Subject: [PATCH] Add the ability to ban/unban IPs per jail --- jail.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/jail.go b/jail.go index c8e137b..0cac162 100644 --- a/jail.go +++ b/jail.go @@ -27,7 +27,45 @@ func jailGetHandler(res http.ResponseWriter, req *http.Request) { res.Write(encodedOutput) } +type jailBanIPBody struct { + IP string +} + +func jailBanIPHandler(res http.ResponseWriter, req *http.Request) { + var input jailBanIPBody + err := json.NewDecoder(req.Body).Decode(&input) + if err != nil { + } + + output, _ := fail2go.JailBanIP(mux.Vars(req)["jail"], input.IP) + + encodedOutput, err := json.Marshal(output) + if err != nil { + } + + res.Write(encodedOutput) +} + +func jailUnbanIPHandler(res http.ResponseWriter, req *http.Request) { + var input jailBanIPBody + err := json.NewDecoder(req.Body).Decode(&input) + if err != nil { + } + + output, _ := fail2go.JailUnbanIP(mux.Vars(req)["jail"], input.IP) + + encodedOutput, err := json.Marshal(output) + if err != nil { + } + + res.Write(encodedOutput) + +} + func jailHandler(jailRouter *mux.Router) { + jailRouter.HandleFunc("/{jail}/banip", jailBanIPHandler).Methods("POST") + jailRouter.HandleFunc("/{jail}/unbanip", jailUnbanIPHandler).Methods("POST") + jailRouter.HandleFunc("/{jail}", jailGetHandler).Methods("GET") }