Start implementing jailControl

This commit is contained in:
Sean DuBois 2014-06-15 07:14:13 +00:00
parent 52d3885d74
commit 59f9d9b0a2
2 changed files with 44 additions and 0 deletions

43
jailControl.go Normal file
View 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")
}

View file

@ -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)
}