2014-06-13 06:06:27 +02:00
|
|
|
package main
|
|
|
|
|
2014-06-14 19:27:18 +02:00
|
|
|
import (
|
2014-06-14 20:32:46 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2014-06-18 07:53:54 +02:00
|
|
|
"github.com/Sean-Der/fail2go"
|
2014-06-14 19:27:18 +02:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"net/http"
|
2014-06-14 20:32:46 +02:00
|
|
|
"os"
|
2014-06-14 19:27:18 +02:00
|
|
|
)
|
2014-06-13 06:06:27 +02:00
|
|
|
|
2014-06-14 20:32:46 +02:00
|
|
|
type Configuration struct {
|
2014-06-18 07:53:54 +02:00
|
|
|
Addr string
|
|
|
|
Fail2banSocket string
|
2014-06-14 20:32:46 +02:00
|
|
|
}
|
|
|
|
|
2014-06-18 07:53:54 +02:00
|
|
|
var fail2goConn *fail2go.Fail2goConn
|
|
|
|
|
2014-06-13 06:06:27 +02:00
|
|
|
func main() {
|
2014-06-14 20:32:46 +02:00
|
|
|
file, fileErr := os.Open("config.json")
|
|
|
|
|
|
|
|
if fileErr != nil {
|
|
|
|
fmt.Println("failed to open config:", fileErr)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
configuration := new(Configuration)
|
|
|
|
configErr := json.NewDecoder(file).Decode(configuration)
|
|
|
|
|
|
|
|
if configErr != nil {
|
|
|
|
fmt.Println("config error:", configErr)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2014-06-18 07:53:54 +02:00
|
|
|
fail2goConn := fail2go.Newfail2goConn(configuration.Fail2banSocket)
|
2014-06-14 19:27:18 +02:00
|
|
|
r := mux.NewRouter()
|
2014-06-18 07:53:54 +02:00
|
|
|
|
|
|
|
globalHandler(r.PathPrefix("/global").Subrouter(), fail2goConn)
|
|
|
|
jailHandler(r.PathPrefix("/jail").Subrouter(), fail2goConn)
|
|
|
|
|
2014-06-14 19:27:18 +02:00
|
|
|
http.Handle("/", r)
|
2014-06-14 20:32:46 +02:00
|
|
|
http.ListenAndServe(configuration.Addr, nil)
|
2014-06-13 06:06:27 +02:00
|
|
|
}
|