Skip to content

Commit

Permalink
#minor: move to ipbase.com api
Browse files Browse the repository at this point in the history
  • Loading branch information
circa10a committed Aug 10, 2022
1 parent a71e5bb commit 23ff57a
Show file tree
Hide file tree
Showing 8 changed files with 757 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
go-version: ${{ steps.vars.outputs.go_version }}
- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.26.0
uses: anothrNick/github-tag-action@1.39.0
id: tagging
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: --timeout=2m0s
4 changes: 2 additions & 2 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ route /* {
# Not specifying a TTL sets no expiration on cached items and will live until restart
cache_ttl 168h

# freegeoip.app API token, this example reads from an environment variable
freegeoip_api_token {$FREEGEOIP_API_TOKEN}
# ipbase.com API token, this example reads from an environment variable
ipbase_api_token {$IPBASE_API_TOKEN}

# radius is the the distance of the geofence, only clients within the distance will be allowed.
# If not supplied, will default to 0.0 kilometers
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# caddy-geofence

A caddy module for IP geofencing your caddy web server using freegeoip.app
A caddy module for IP geofencing your caddy web server using https://ipbase.com/

![Build Status](https://github.com/circa10a/caddy-geofence/workflows/deploy/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/circa10a/caddy-geofence)](https://goreportcard.com/report/github.com/circa10a/caddy-geofence)
Expand All @@ -21,9 +21,9 @@ A caddy module for IP geofencing your caddy web server using freegeoip.app
## Usage

1. For an IP that is not within the geofence, `403` will be returned on the matching route.
2. An API token from [freegeoip.app](https://freegeoip.app/) is **required** to run this module.
2. An API token from [ipbase.com](https://ipbase.com/) is **required** to run this module.

> Free tier includes 15,000 requests per hour
> Free tier includes 150 requests per month
### Build with caddy

Expand All @@ -35,7 +35,7 @@ xcaddy build --with github.com/circa10a/caddy-geofence
### Docker

```shell
docker run --net host -v /your/Caddyfile:/etc/caddy/Caddyfile -e FREEGEOIP_API_TOKEN -p 80:80 -p 443:443 circa10a/caddy-geofence
docker run --net host -v /your/Caddyfile:/etc/caddy/Caddyfile -e IPBASE_API_TOKEN -p 80:80 -p 443:443 circa10a/caddy-geofence
```

## Caddyfile example
Expand All @@ -55,8 +55,8 @@ route /* {
# Not specifying a TTL sets no expiration on cached items and will live until restart
cache_ttl 168h
# freegeoip.app API token, this example reads from an environment variable
freegeoip_api_token {$FREEGEOIP_API_TOKEN}
# ipbase.com API token, this example reads from an environment variable
ipbase_api_token {$IPBASE_API_TOKEN}
// radius is the distance of the geofence in kilometers
// If not supplied, will default to 0.0 kilometers
Expand Down Expand Up @@ -89,7 +89,7 @@ Requires [xcaddy](https://caddyserver.com/docs/build#xcaddy) to be installed
### Run

```shell
export FREEGEOIP_API_TOKEN=<token>
export IPBASE_API_TOKEN=<token>
make run
```

Expand Down
12 changes: 6 additions & 6 deletions caddy_geofence.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (
type CaddyGeofence struct {
logger *zap.Logger
GeofenceClient *geofence.Geofence
// freegeoip_api_token is REQUIRED and is an API token from freegeoip.app
// Free tier includes 15000 requests per hour
FreeGeoIPAPIToken string `json:"freegeoip_api_token,omitempty"`
// ipbase_api_token is REQUIRED and is an API token ipbase.com
// Free tier includes 150 requests per month
IPBaseAPIToken string `json:"ipbase_api_token,omitempty"`
// remote_ip is the IP address to geofence against
// Not specifying this field results in geofencing the public address of the machine caddy is running on
RemoteIP string `json:"remote_ip,omitempty"`
Expand Down Expand Up @@ -71,8 +71,8 @@ func (cg *CaddyGeofence) Provision(ctx caddy.Context) error {
cg.logger = caddy.Log()

// Verify API Token is set
if cg.FreeGeoIPAPIToken == "" {
return fmt.Errorf("freegeoip_api_token: freegeoip API token not set")
if cg.IPBaseAPIToken == "" {
return fmt.Errorf("ipbase_api_token: ipbase.com API token not set")
}

// Set cache to never expire if not set
Expand All @@ -88,7 +88,7 @@ func (cg *CaddyGeofence) Provision(ctx caddy.Context) error {
// Setup client
geofenceClient, err := geofence.New(&geofence.Config{
IPAddress: cg.RemoteIP,
Token: cg.FreeGeoIPAPIToken,
Token: cg.IPBaseAPIToken,
Radius: cg.Radius,
AllowPrivateIPAddresses: cg.AllowPrivateIPAddresses,
CacheTTL: cg.CacheTTL,
Expand Down
4 changes: 2 additions & 2 deletions caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func (cg *CaddyGeofence) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return err
}
cg.CacheTTL = cacheTTL
case "freegeoip_api_token":
case "ipbase_api_token":
if !d.NextArg() {
return d.ArgErr()
}
cg.FreeGeoIPAPIToken = d.Val()
cg.IPBaseAPIToken = d.Val()
case "remote_ip":
if !d.NextArg() {
return d.ArgErr()
Expand Down
134 changes: 75 additions & 59 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,117 @@ module github.com/circa10a/caddy-geofence
go 1.17

require (
github.com/caddyserver/caddy/v2 v2.4.6
github.com/circa10a/go-geofence v0.5.0
go.uber.org/zap v1.19.0
github.com/caddyserver/caddy/v2 v2.5.2
github.com/circa10a/go-geofence v0.6.0
go.uber.org/zap v1.22.0
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/EpicStep/go-simple-geo/v2 v2.0.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f // indirect
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220804214150-8b0cc382067f // indirect
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/caddyserver/certmagic v0.15.2 // indirect
github.com/caddyserver/certmagic v0.16.2 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.0.4-0.20200906165740-41ebdbffecfd // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/cel-go v0.7.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/cel-go v0.12.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/libdns/libdns v0.2.1 // indirect
github.com/lucas-clemente/quic-go v0.23.0 // indirect
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/manifoldco/promptui v0.8.0 // indirect
github.com/lucas-clemente/quic-go v0.28.1 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/marten-seemann/qpack v0.2.1 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mholt/acmez v1.0.1 // indirect
github.com/mholt/acmez v1.0.4 // indirect
github.com/micromdm/scep/v2 v2.1.0 // indirect
github.com/miekg/dns v1.1.43 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rs/xid v1.2.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/samfoo/ansi v0.0.0-20160124022901-b6bd2ded7189 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/smallstep/certificates v0.17.5-0.20211008195551-04fe3126bebf // indirect
github.com/smallstep/cli v0.17.6 // indirect
github.com/smallstep/nosql v0.3.8 // indirect
github.com/smallstep/truststore v0.9.6 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/slackhq/nebula v1.6.0 // indirect
github.com/smallstep/certificates v0.21.0 // indirect
github.com/smallstep/cli v0.21.0 // indirect
github.com/smallstep/nosql v0.4.0 // indirect
github.com/smallstep/truststore v0.11.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/urfave/cli v1.22.5 // indirect
github.com/tailscale/tscert v0.0.0-20220316030059-54bbcb9f74e2 // indirect
github.com/urfave/cli v1.22.9 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
go.step.sm/cli-utils v0.6.0 // indirect
go.step.sm/crypto v0.11.0 // indirect
go.step.sm/linkedca v0.5.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20210719143636-1d5a45f8e492 // indirect
google.golang.org/grpc v1.39.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
go.step.sm/cli-utils v0.7.3 // indirect
go.step.sm/crypto v0.17.0 // indirect
go.step.sm/linkedca v0.17.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
howett.net/plist v1.0.0 // indirect
)

exclude github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f
Loading

0 comments on commit 23ff57a

Please sign in to comment.