Fix GeoIP download (HTTP 403) and clarify host setup

- db-ip.com rejects Python's default "Python-urllib" user agent with
  403; the download now sends "fail2ban-webui/<version> (+repo URL)"
- README quick start: edit .env and replace the example hosts in
  config/hosts.yaml; hosts.yaml.example marks its entries as examples

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
schiwagoaandClaude Opus 5.5 committed 2026-10-25 17:40:14 +01:00
1 parent 97b0c14dac
commit 66a8acd7f9
3 files changed
+8 -1

No files matched your search

+4 -1
View File
@@ -24,6 +24,7 @@ from datetime import date, datetime, timedelta
import maxminddb
log = logging.getLogger("webui")
USER_AGENT = "fail2ban-webui/{} (+https://git.retronerd.at/schiwagoa/fail2ban-webui)"
def fail(key, **args):
@@ -93,8 +94,10 @@ class Geo:
first = date.today().replace(day=1)
for month in (first, (first - timedelta(days=1)).replace(day=1)):
url = f"https://download.db-ip.com/free/dbip-city-lite-{month:%Y-%m}.mmdb.gz"
# db-ip.com answers 403 to Python's default "Python-urllib" user agent
req = urllib.request.Request(url, headers={"User-Agent": USER_AGENT.format(self.settings.version)})
try:
with urllib.request.urlopen(url, timeout=300) as resp, \
with urllib.request.urlopen(req, timeout=300) as resp, \
tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as tmp:
with gzip.GzipFile(fileobj=resp) as gz:
shutil.copyfileobj(gz, tmp)