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"
|
2014-07-07 22:30:11 +02:00
|
|
|
"flag"
|
2014-06-14 20:32:46 +02:00
|
|
|
"fmt"
|
2014-06-14 19:27:18 +02:00
|
|
|
"net/http"
|
2014-06-14 20:32:46 +02:00
|
|
|
"os"
|
2024-06-20 22:30:52 +02:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/sean-der/fail2go"
|
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-27 08:58:35 +02:00
|
|
|
var fail2goConn *fail2go.Conn
|
2014-06-18 07:53:54 +02:00
|
|
|
|
2014-06-13 06:06:27 +02:00
|
|
|
func main() {
|
2014-07-07 22:30:11 +02:00
|
|
|
configPath := flag.String("config", "config.json", "path to config.json")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
file, fileErr := os.Open(*configPath)
|
2014-06-14 20:32:46 +02:00
|
|
|
|
|
|
|
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-07-10 02:54:26 +02:00
|
|
|
r.HandleFunc("/whois/{object}", func(res http.ResponseWriter, req *http.Request) {
|
|
|
|
whoisHandler(res, req, fail2goConn)
|
|
|
|
}).Methods("GET")
|
2014-06-18 07:53:54 +02:00
|
|
|
|
2014-06-14 19:27:18 +02:00
|
|
|
http.Handle("/", r)
|
2014-06-27 16:10:35 +02:00
|
|
|
fmt.Println(http.ListenAndServe(configuration.Addr, nil))
|
2014-06-13 06:06:27 +02:00
|
|
|
}
|