Skip to content

Instantly share code, notes, and snippets.

@TehPeGaSuS
Last active September 24, 2024 14:47
Show Gist options
  • Save TehPeGaSuS/604947957fd7bc7be89d621458339487 to your computer and use it in GitHub Desktop.
Save TehPeGaSuS/604947957fd7bc7be89d621458339487 to your computer and use it in GitHub Desktop.
UnrealIRCd GeoIP Maxmind
#!/usr/bin/env bash
###
# Set here your license key
###
licenseKey="LICENSE_KEY"
###
# Path to the executable
###
executablePath="/home/ircd/unrealircd/unrealircd"
###
# Path to UnrealIRCd's data folder
###
dataFolder="/home/ircd/unrealircd/data"
###
# DON'T TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
##
# If you touch the code below and then complain the script "suddenly stopped working" I'll touch you at night. (THANKS thommey)
###
###
# Get Country database
###
wget -O geoip.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${licenseKey}&suffix=tar.gz" &&
###
# Extract ONLY the mmdb database to UnrealIRCd's data folder
###
tar zxf geoip.tar.gz -C "$dataFolder" --strip-components 1 --wildcards --no-anchored '*.mmdb' &&
###
# Now we need to rehash UnrealIRCd so the new
# database is taken in account
###
"$executablePath" rehash &&
###
# Let's remove the tar.gz since we don't need it anymore until the next update
rm "$HOME"/geoip.tar.gz
@TehPeGaSuS
Copy link
Author

TehPeGaSuS commented Dec 5, 2021

ATTENTION

UnrealIRCd MUST be compiled/recompiled with libmaxminddb support. To do so, go to UnrealIRCd source folder, type ./Config and answer libmaxminddb when you see the following:

GeoIP is a feature that allows converting an IP address to a location (country)
Possible build options:
     classic: This is the DEFAULT geoip engine. It should work on all systems
              and receives automatic updates.
libmaxminddb: This uses the libmaxminddb library. If you want to use this, then
              you need to install the libmaxminddb library on your system first
        none: Don't build with any geoip library (geoip-csv is still built)
Choose one of: classic, libmaxminddb, none
[classic] ->

Then, just do the usual make followed by make install and follow the instructions below.


Instructions

  • Download this shell script with:
wget https://gist.githubusercontent.com/PeGaSuS-Coder/604947957fd7bc7be89d621458339487/raw/unrealircd_geoip.sh  
  • Edit the script to add your license key from Maxmind and to set the correct paths

  • Make the script executable with:

chmod +x unrealircd_geoip.sh
  • Edit unrealircd.conf and add the following to the end of the file:
blacklist-module "geoip_classic";
loadmodule "geoip_maxmind";
@if module-loaded("geoip_maxmind")
set {
	geoip-maxmind {
		database "GeoLite2-Country.mmdb";
	}
}
@endif  
  • Execute the script manually once with:
./unrealircd_geoip.sh
  • Choose a cronjob from the following options (edit the paths), to update the database (every five days should be more than enough):
  • Every Day:
0 0 * * * /home/ircd/unrealircd_geoip.sh >/dev/null 2>&1
  • Even days:
0 0 */2 * * /home/ircd/unrealircd_geoip.sh >/dev/null 2>&1
  • Every 5 Days:
0 0 */5 * * /home/ircd/unrealircd_geoip.sh >/dev/null 2>&1
  • Every 10 Days:
0 0 */10 * * /home/ircd/unrealircd_geoip.sh >/dev/null 2>&1
  • Every Half Month:
0 0 */15 * * /home/ircd/unrealircd_geoip.sh >/dev/null 2>&1
  • Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment