Start Go Module

This commit is contained in:
Sean DuBois 2024-06-20 16:30:52 -04:00
parent 42cfa4101b
commit 61574091f9
8 changed files with 44 additions and 17 deletions

View file

@ -3,7 +3,7 @@ To quickly run fail2rest just execute `go run *.go`
#Guidelines
* Put as much logic as possible into [fail2go](https://github.com/Sean-Der/fail2go)
* Put as much logic as possible into [fail2go](https://github.com/sean-der/fail2go)
* Make sure code is properly formated [gofmt](http://blog.golang.org/go-fmt-your-code)
* Make sure you code compiles
* If adding new REST endpoints try to follow the current style

View file

@ -15,8 +15,8 @@ Some libraries currently are not building on older versions of Go, I recommend r
## Installing
Once you have a working Golang installation all you need to do is run
go get -v github.com/Sean-Der/fail2rest
go install -v github.com/Sean-Der/fail2rest
go get -v github.com/sean-der/fail2rest
go install -v github.com/sean-der/fail2rest
fail2rest will now be available as a binary in your GOPATH, you can run 'fail2rest' from the command line, or copy it
somewhere else to make it available to all users.
@ -25,24 +25,24 @@ Use `whereis fail2rest` to locate your fail2rest binary.
Next you need to configure fail2rest, and then finally make it a system service.
## Configuration
fail2rest is configured via config.json, the default is located [here](https://raw.githubusercontent.com/Sean-Der/fail2rest/master/config.json).
fail2rest is configured via config.json, the default is located [here](https://raw.githubusercontent.com/sean-der/fail2rest/master/config.json).
To load your config.json you use the --config flag `fail2rest --config=my_config.json`
fail2rest has two options that be configured via config.json
* **Fail2banSocket** - The path to the fail2ban socket, can usually be found via `grep socket /etc/fail2ban/fail2ban.conf` you also have to run fail2rest as a user who has permissions to use this socket
* **Addr** - The address that fail2rest is served upon, it is usually best so serve to the loopback, and then allow access via nginx see an example config in the [fail2web](https://github.com/Sean-Der/fail2web) repository
* **Addr** - The address that fail2rest is served upon, it is usually best so serve to the loopback, and then allow access via nginx see an example config in the [fail2web](https://github.com/sean-der/fail2web) repository
The default configuration file used by init-scripts is `/etc/fail2rest.json`. You should download the config to your /tmp/ dir and modify it to your needs.
cd /tmp/
wget https://raw.githubusercontent.com/Sean-Der/fail2rest/master/config.json
wget https://raw.githubusercontent.com/sean-der/fail2rest/master/config.json
Once you finished editing the configuration file, you should move it from /tmp/config.json to /etc/fail2rest.json executing `mv /tmp/config.json /etc/fail2rest.json`
## Running
Once you have a config.json all you need to do is run `fail2rest --config config.json`
However, fail2rest is designed to run as a service, so init scripts are provided that allow easy management of fail2rest. They can be found [here](https://github.com/Sean-Der/fail2rest/tree/master/init-scripts)
However, fail2rest is designed to run as a service, so init scripts are provided that allow easy management of fail2rest. They can be found [here](https://github.com/sean-der/fail2rest/tree/master/init-scripts)
Download the appropriate init file your Distribution. You may need to customize your init script to load your config.json, but most scripts default to /etc/fail2rest.json
## Service
@ -53,11 +53,11 @@ To run as a service you can either copy or create symlinks for systemd and the f
Debian
ln -s $GOPATH/src/github.com/Sean-Der/fail2rest/init-scripts/systemd /etc/systemd/system/fail2rest.service
ln -s $GOPATH/src/github.com/sean-der/fail2rest/init-scripts/systemd /etc/systemd/system/fail2rest.service
Other Linux
ln -s $GOPATH/src/github.com/Sean-Der/fail2rest/init-scripts/systemd /usr/lib/systemd/system/fail2rest.service
ln -s $GOPATH/src/github.com/sean-der/fail2rest/init-scripts/systemd /usr/lib/systemd/system/fail2rest.service
Enable fail2rest service to run at startup

View file

@ -4,10 +4,11 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/Sean-Der/fail2go"
"github.com/gorilla/mux"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/sean-der/fail2go"
)
type Configuration struct {

View file

@ -2,9 +2,10 @@ package main
import (
"encoding/json"
"github.com/Sean-Der/fail2go"
"github.com/gorilla/mux"
"net/http"
"github.com/gorilla/mux"
"github.com/sean-der/fail2go"
)
func globalStatusHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {

14
go.mod Normal file
View file

@ -0,0 +1,14 @@
module github.com/sean-der/fail2rest
go 1.19
require (
github.com/gorilla/mux v1.8.1
github.com/sean-der/fail2go v0.0.1
github.com/sean-der/goWHOIS v0.0.0-20140709054325-70c302b526cf
)
require (
github.com/kisielk/og-rek v1.2.0 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
)

10
go.sum Normal file
View file

@ -0,0 +1,10 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/kisielk/og-rek v1.2.0 h1:CTvDIin+YnetsSQAYbe+QNAxXU3B50C5hseEz8xEoJw=
github.com/kisielk/og-rek v1.2.0/go.mod h1:6ihsOSzSAxR/65S3Bn9zNihoEqRquhDQZ2c6I2+MG3c=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/sean-der/fail2go v0.0.1 h1:AOZ5b/ewYzStnhsPXO/bLWzg97eogEV4gXkiwEJKLxU=
github.com/sean-der/fail2go v0.0.1/go.mod h1:xfDepiRfuCxHX5LZyBl4nAIUvL+8Aed6o8fcxvCMPD4=
github.com/sean-der/goWHOIS v0.0.0-20140709054325-70c302b526cf h1:EmuSitACP3cGjR5/KrEUiyDXPCDI6MNoPzrt4weR0Fw=
github.com/sean-der/goWHOIS v0.0.0-20140709054325-70c302b526cf/go.mod h1:VrJMtetl51Wyuc1JaF5UhewOiLRYBN1PozQtYJp8vCY=

View file

@ -8,8 +8,8 @@ import (
"regexp"
"strings"
"github.com/Sean-Der/fail2go"
"github.com/gorilla/mux"
"github.com/sean-der/fail2go"
)
func jailGetHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {

View file

@ -2,10 +2,11 @@ package main
import (
"encoding/json"
"github.com/Sean-Der/fail2go"
"github.com/Sean-Der/goWHOIS"
"github.com/gorilla/mux"
"net/http"
"github.com/gorilla/mux"
"github.com/sean-der/fail2go"
"github.com/sean-der/goWHOIS"
)
func whoisHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {