From 61574091f9137bc727e5d06aadfddb09051b0576 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Thu, 20 Jun 2024 16:30:52 -0400 Subject: [PATCH] Start Go Module --- CONTRIBUTING.md | 2 +- README.md | 16 ++++++++-------- fail2rest.go | 5 +++-- global.go | 5 +++-- go.mod | 14 ++++++++++++++ go.sum | 10 ++++++++++ jail.go | 2 +- whois.go | 7 ++++--- 8 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 729c49f..97ce071 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 3fe8859..9354896 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/fail2rest.go b/fail2rest.go index 50faee7..a607897 100644 --- a/fail2rest.go +++ b/fail2rest.go @@ -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 { diff --git a/global.go b/global.go index 8dd2669..6303cd6 100644 --- a/global.go +++ b/global.go @@ -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) { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cce552b --- /dev/null +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0a3a2ac --- /dev/null +++ b/go.sum @@ -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= diff --git a/jail.go b/jail.go index 0312db2..181ccfc 100644 --- a/jail.go +++ b/jail.go @@ -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) { diff --git a/whois.go b/whois.go index f12dcbf..e310b00 100644 --- a/whois.go +++ b/whois.go @@ -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) {