mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 13:42:17 +01:00
Add the ability to ban/unban IPs per jail
This commit is contained in:
parent
777a2df7a4
commit
cf7967390d
1 changed files with 38 additions and 0 deletions
38
jail.go
38
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")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue