mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 13:42:17 +01:00
Start implementing jailControl
This commit is contained in:
parent
52d3885d74
commit
59f9d9b0a2
2 changed files with 44 additions and 0 deletions
43
jailControl.go
Normal file
43
jailControl.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func JailControlStatusHandler(res http.ResponseWriter, req *http.Request) {
|
||||
fail2banInput := make([]string, 2)
|
||||
fail2banInput[0] = "status"
|
||||
fail2banInput[1] = mux.Vars(req)["jail"]
|
||||
|
||||
fail2banOutput, err := fail2banRequest(fail2banInput)
|
||||
if err != nil {
|
||||
}
|
||||
|
||||
//TODO use reflection to assert data structures and give proper errors
|
||||
action := fail2banOutput.([]interface{})[1].([]interface{})[1].([]interface{})[1]
|
||||
filter := fail2banOutput.([]interface{})[1].([]interface{})[0].([]interface{})[1]
|
||||
|
||||
output := make(map[string]map[string]interface{})
|
||||
output["action"] = make(map[string]interface{})
|
||||
output["filter"] = make(map[string]interface{})
|
||||
|
||||
output["filter"]["currentlyFailed"] = filter.([]interface{})[0].([]interface{})[1]
|
||||
output["filter"]["totalFailed"] = filter.([]interface{})[1].([]interface{})[1]
|
||||
output["filter"]["fileList"] = filter.([]interface{})[2].([]interface{})[1]
|
||||
|
||||
output["action"]["currentlyBanned"] = action.([]interface{})[0].([]interface{})[1]
|
||||
output["action"]["totalBanned"] = action.([]interface{})[1].([]interface{})[1]
|
||||
output["action"]["ipList"] = action.([]interface{})[2].([]interface{})[1]
|
||||
|
||||
encodedOutput, err := json.Marshal(output)
|
||||
if err != nil {
|
||||
}
|
||||
|
||||
res.Write(encodedOutput)
|
||||
}
|
||||
|
||||
func JailControlHandler(basicRouter *mux.Router) {
|
||||
basicRouter.HandleFunc("/status/{jail}", JailControlStatusHandler).Methods("GET")
|
||||
}
|
1
main.go
1
main.go
|
@ -30,6 +30,7 @@ func main() {
|
|||
|
||||
r := mux.NewRouter()
|
||||
BasicHandler(r.PathPrefix("/basic").Subrouter())
|
||||
JailControlHandler(r.PathPrefix("/jailControl").Subrouter())
|
||||
http.Handle("/", r)
|
||||
http.ListenAndServe(configuration.Addr, nil)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue