This project does not affiliate with Caddy nor IPInfo. It only extends Caddy with custom code to integrate the free databases provided by IPInfo into Caddy. Logo Copyright belongs to the corresponding project.
Caddy IPInfo free
Easy country and ASN lookup by IP with the free IPInfo database.
This module is still in development. Breaking changes will likely come. No stability checks yet.
$ curl "http://localhost:8080/?ip=1.1.1.1"
IP: 1.1.1.1
Country: Australia (AU)
Continent: Oceania (OC)
ASN: AS13335 Cloudflare, Inc. cloudflare.com
Why?
IPInfo distributes their country and ASN databases for free every 24h with full accuracy. With this module and a few lines of config in your Caddyfile, you can query the database anywhere with anything.
Installation
Web Download
Download a caddy binary from caddyserver.com with this package included here.
CLI Download (experimental)
This is equal to the version above but replaces your existing binary with the new one including the package.
Caddy has a feature to add packages to your current installation by running the following command:
This url can be easily found in the Dashboard of IPInfo after creating an account. Simply choose a database of your choice in the MMDB format and paste the url here. If you only choose the Country or ASN Database, only these values can be extracted and filled into the variables. The other values will simply be empty. If the Database with both types is chosen, all details will be available.
cron
valid crontab notation
Default: 10 16 * * *
Customize how often you want to check for a new database. The official time is published by IPInfo in their FAQ here. Timezone is UTC.
path
valid path to store the database
Default: os.TempDir() with directory caddy_ipinfo_free
This will be the path where the databases are stored after download. As there are different kinds of databases, we only accept a path and not a specific filename. Each database will be stored here by their corresponding names from the configured url.
If the configured path does not exist, the directories will be created. If not path is given, a temporary directory will be created in the systems temporary directory with the name caddy_ipinfo_free.
Allows enabling error logs when an invalid ip is given to the handler. If you debug something enabling this is recommended. The Variable ipinfo_free.error will be set regardless. The main use-case for this feature is to avoid overloading the logs in production when presented with invalid IPs by the client. NOTE: Previously known as quiet_on_invalid_ip, which made it more difficult to properly handle the default true state.
Do you have a neat way of using this library in your Caddyfile? Feel free to submit it.
Internals
This module will automatically update the database from ipinfo and store it in the configured path. You can freely configure the cron option to update the database in a timely manner of your choosing. However, the most frequent update rate that should be used is hourly as the database will only be updated by IPInfo every 24 hours.
git clone https://github.com/oltdaniel/caddy-ipinfo-free.git
cd caddy-ipinfo-free
CADDY_VERSION=master xcaddy run
# or
CADDY_VERSION=master xcaddy build --with github.com/oltdaniel/caddy-ipinfo-free=.
./caddy run