mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 21:52:18 +01:00
598eea73e3
This reverts commit c5a2d036d7
.
This commit was reverted since it breaks 'go run *.go', I plan on
bringing back custom config.json location with a switch instead.
47 lines
896 B
Go
47 lines
896 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/Sean-Der/fail2go"
|
|
"github.com/gorilla/mux"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
type Configuration struct {
|
|
Addr string
|
|
Fail2banSocket string
|
|
}
|
|
|
|
type ErrorBody struct {
|
|
Error string
|
|
}
|
|
|
|
var fail2goConn *fail2go.Conn
|
|
|
|
func main() {
|
|
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)
|
|
}
|
|
|
|
fail2goConn := fail2go.Newfail2goConn(configuration.Fail2banSocket)
|
|
r := mux.NewRouter()
|
|
|
|
globalHandler(r.PathPrefix("/global").Subrouter(), fail2goConn)
|
|
jailHandler(r.PathPrefix("/jail").Subrouter(), fail2goConn)
|
|
|
|
http.Handle("/", r)
|
|
fmt.Println(http.ListenAndServe(configuration.Addr, nil))
|
|
}
|