Skip to content

Commit

Permalink
working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
fredposner committed Nov 23, 2023
1 parent f3e5c3b commit bce21aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions clients/go/apiban-iptables/apiban-iptables-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
package main

import (
"crypto/tls"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"net/http"
"os"
"runtime"
"strconv"
Expand All @@ -39,19 +41,26 @@ import (
var configFileLocation string
var logFile string
var targetChain string
var skipVerify string

func init() {
flag.StringVar(&targetChain, "target", "REJECT", "target chain for matching entries")
flag.StringVar(&configFileLocation, "config", "", "location of configuration file")
flag.StringVar(&logFile, "log", "/var/log/apiban-client.log", "location of log file or - for stdout")
flag.StringVar(&skipVerify, "verify", "true", "set to false to skip verify of tls cert")

if skipVerify == "false" {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
}

// ApibanConfig is the structure for the JSON config file
type ApibanConfig struct {
APIKEY string `json:"APIKEY"`
LKID string `json:"LKID"`
VERSION string `json:"VERSION"`
FLUSH string `json:"FLUSH"`
APIKEY string `json:"apikey"`
LKID string `json:"lkid"`
VERSION string `json:"version"`
FLUSH string `json:"flush"`
SET string `json:"set"`

sourceFile string
}
Expand Down Expand Up @@ -92,15 +101,19 @@ func main() {
apiconfig, err := LoadConfig()
if err != nil {
log.Fatalln(err)
runtime.Goexit()
}

// if no APIKEY, exit
if apiconfig.APIKEY == "" {
log.Fatalln("Invalid APIKEY. Exiting.")
runtime.Goexit()
}

// if no APIKEY, exit
if apiconfig.APIKEY == "MY API KEY" {
log.Fatalln("Invalid APIKEY. Exiting. Go to apiban.org and get an api key.")
runtime.Goexit()
}

// allow cli of FULL to reset LKID to 100
Expand Down
4 changes: 2 additions & 2 deletions clients/go/apiban/apiban.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
// NOTE: this is used by the server to indicate both that an IP address is not
// blocked (when calling Check) and that the list is complete (when calling
// Banned)
var ErrBadRequest = errors.New("Bad Request")
var ErrBadRequest = errors.New("bad request")

// Entry describes a set of blocked IP addresses from APIBAN.org
type Entry struct {
Expand Down Expand Up @@ -123,7 +123,7 @@ func Check(key string, ip string) (bool, error) {
func queryServer(c *http.Client, u string) (*Entry, error) {
resp, err := http.Get(u)
if err != nil {
return nil, fmt.Errorf("Query Error: %s", err.Error())
return nil, fmt.Errorf("query error: %s", err.Error())
}
defer resp.Body.Close()

Expand Down

0 comments on commit bce21aa

Please sign in to comment.