Skip to content

Real-time network monitor + outbound firewall — see & block every connection. Privacy-first, local-first, Rust fleet agent, SIEM exports, 8 languages. / Moniteur réseau temps réel + pare-feu sortant, agent de flotte Rust, exports SIEM. 100 % local.

geo: bundle DB-IP Lite gzip'd — geolocation works out of the box, zero network calls

MoneyLisa39b8df400f62
diff --git a/README.md b/README.md
index 79519af..7686d7c 100644
--- a/README.md
+++ b/README.md
@@ -48,14 +48,14 @@ The entire interface is available in **English and French**: use the `EN / FR` t
| Backend API | FastAPI — WebSockets — SQLite |
| Frontend | React 18 — Vite — D3.js v7 — TopoJSON |
| Desktop wrapper | Electron 33 |
-| Geolocation | **Offline only** — DB-IP Lite (CC BY 4.0) or MaxMind GeoLite2 `.mmdb` in the user data dir |
+| Geolocation | **Offline only** — DB-IP Lite (CC BY 4.0) bundled gzip'd in `backend/data/geo/`, decompressed on first run; MaxMind GeoLite2 `.mmdb` also supported |
### Security & privacy
- **API token** — every REST endpoint and the WebSocket require a token. Electron generates it per launch; in Docker/browser it's printed once in the backend logs and stored in `data/api_token.txt`. Open the UI with `http://localhost:8000/?token=<TOKEN>` (or enter it when prompted).
- **Loopback-only by default** — the API binds `127.0.0.1` in every mode. Set `SNITCH_BIND=0.0.0.0` only if you explicitly want LAN access (token auth still applies).
- **CORS/WebSocket origin allowlist** — only `localhost:5173`, the backend's own origin and Electron `file://` pages may connect.
-- **Geolocation is offline-only** — there is *no* online lookup. Drop `dbip-city-lite.mmdb` + `dbip-asn-lite.mmdb` ([DB-IP Lite](https://db-ip.com/db/lite.php), CC BY 4.0) or `GeoLite2-City.mmdb`/`GeoLite2-ASN.mmdb` (MaxMind) into `<data_dir>/geo/` for local lookups — or download DB-IP Lite from the Settings panel (explicit consent, the only possible outbound call). Without a DB, IPs simply show no geo.
+- **Geolocation is offline-only** — there is *no* online lookup. DB-IP Lite ([CC BY 4.0](https://db-ip.com/db/lite.php)) ships gzip'd in `backend/data/geo/` and is auto-extracted into `<data_dir>/geo/` on first launch — geo works out of the box, zero network calls. You may still drop newer `GeoLite2-City.mmdb`/`GeoLite2-ASN.mmdb` (MaxMind) into `<data_dir>/geo/`, or download a fresh DB-IP Lite from the Settings panel (explicit consent, the only possible outbound call).
- **All data stays local** — `snitch.db` (24 h sliding window, configurable via `retention_hours` setting) and `data/logs/snitch.log` never leave the machine. No telemetry. The **only** possible outbound call is the opt-in DB-IP Lite download (Settings → "Download DB-IP Lite"), which requires an explicit click.
- **Settings persist** — port filters, excluded processes, the IP whitelist, language and retention are stored in SQLite and restored on restart.
- **Alert suppression** — each alert has an "Ignore this type/host" action; suppression rules are persisted (`alert_suppressions` table), applied before alerts are emitted or logged, and survivable across restarts via `POST /alerts/ignore` / `DELETE /alerts/ignore` / `GET /alerts/ignore`.
@@ -190,14 +190,14 @@ Toute l'interface est disponible en **français et en anglais** : utilisez le s
| API backend | FastAPI — WebSockets — SQLite |
| Frontend | React 18 — Vite — D3.js v7 — TopoJSON |
| Conteneur bureau | Electron 33 |
-| Géolocalisation | **Hors ligne uniquement** — DB-IP Lite (CC BY 4.0) ou MaxMind GeoLite2 `.mmdb` dans le dossier de données |
+| Géolocalisation | **Hors ligne uniquement** — DB-IP Lite (CC BY 4.0) embarquée gzipée dans `backend/data/geo/`, décompressée au premier lancement ; MaxMind GeoLite2 `.mmdb` aussi pris en charge |
### Sécurité & confidentialité
- **Jeton API** — chaque endpoint REST et le WebSocket exigent un jeton. Electron le génère à chaque lancement ; sous Docker/navigateur il est affiché une fois dans les logs du backend et stocké dans `data/api_token.txt`. Ouvrez l'UI via `http://localhost:8000/?token=<JETON>` (ou saisissez-le à l'invite).
- **Loopback uniquement par défaut** — l'API écoute sur `127.0.0.1` dans tous les modes. Ne mettez `SNITCH_BIND=0.0.0.0` que pour un accès LAN explicite (le jeton reste exigé).
- **Liste blanche CORS/Origin WebSocket** — seuls `localhost:5173`, l'origine propre du backend et les pages `file://` d'Electron peuvent se connecter.
-- **Géolocalisation 100 % hors ligne** — il n'y a *aucune* recherche en ligne. Déposez `dbip-city-lite.mmdb` + `dbip-asn-lite.mmdb` ([DB-IP Lite](https://db-ip.com/db/lite.php), CC BY 4.0) ou `GeoLite2-City.mmdb`/`GeoLite2-ASN.mmdb` (MaxMind) dans `<data_dir>/geo/` — ou téléchargez DB-IP Lite depuis le panneau Réglages (consentement explicite, seul appel sortant possible). Sans base, les IP n'ont simplement pas de géo.
+- **Géolocalisation 100 % hors ligne** — *aucune* recherche en ligne. DB-IP Lite ([CC BY 4.0](https://db-ip.com/db/lite.php)) est embarquée gzipée dans `backend/data/geo/` et auto-extraite vers `<data_dir>/geo/` au premier lancement — la géo fonctionne d'emblée, zéro appel réseau. Vous pouvez toujours déposer des `GeoLite2-City.mmdb`/`GeoLite2-ASN.mmdb` (MaxMind) plus récents dans `<data_dir>/geo/`, ou télécharger une DB-IP Lite fraîche depuis Réglages (consentement explicite, seul appel sortant possible).
- **Toutes les données restent locales** — `snitch.db` (fenêtre glissante de 24 h, configurable via le réglage `retention_hours`) et `data/logs/snitch.log` ne quittent jamais la machine. Pas de télémétrie. Le **seul** appel sortant possible est le téléchargement opt-in de DB-IP Lite (Réglages → « Télécharger DB-IP Lite »), qui exige un clic explicite.
- **Réglages persistés** — filtres de ports, processus exclus, whitelist IP, langue et rétention sont stockés dans SQLite et restaurés au redémarrage.
- **Suppression d'alertes** — chaque alerte offre « Ignorer ce type/cet hôte » ; les règles sont persistées (`alert_suppressions`), appliquées avant émission, et gérables via `POST /alerts/ignore`, `DELETE /alerts/ignore`, `GET /alerts/ignore`.
diff --git a/backend/backend.spec b/backend/backend.spec
index 2245eb3..bbeabab 100644
--- a/backend/backend.spec
+++ b/backend/backend.spec
@@ -34,7 +34,12 @@ a = Analysis(
# FR: Embarquer classifier/lists/ (listes trackers + CDN) pour que l'app
# figée les trouve — _list_dir() résout via sys._MEIPASS.
datas=[('classifier/lists', 'classifier/lists'),
- ('scanner/oui_table.txt.gz', 'scanner')],
+ ('scanner/oui_table.txt.gz', 'scanner'),
+ # EN: bundled DB-IP Lite (gzip'd) — geo works offline, zero
+ # runtime download; resolver extracts them into <data>/geo.
+ # FR: DB-IP Lite embarquée (gzipée) — la géo marche hors ligne,
+ # zéro téléchargement ; le resolver les extrait dans <data>/geo.
+ ('data/geo', 'data/geo')],
hiddenimports=(
# ── uvicorn internals / éléments internes d'uvicorn ─────────────
collect_submodules('uvicorn')
diff --git a/backend/resolver/dns_geo.py b/backend/resolver/dns_geo.py
index eee8f35..6bd8975 100644
--- a/backend/resolver/dns_geo.py
+++ b/backend/resolver/dns_geo.py
@@ -10,8 +10,9 @@ EN: Enrichment pipeline for remote IPs:
Lite; raw maxminddb reads both formats)
PRIVACY: there is NO online geolocation fallback. ip-api.com was removed —
- a privacy tool must never leak visited IPs in plaintext. If no .mmdb is
- present the UI shows "no geo" and the README explains how to enable it.
+ a privacy tool must never leak visited IPs in plaintext. DB-IP Lite ships
+ gzip'd inside the repo (CC BY 4.0) and is decompressed into GEO_DIR on
+ first use — so geo works out of the box with zero network calls.
Databases live in the per-OS user data dir (paths.data_dir()), NOT next to
__file__ — the old Path(__file__)/data code pointed inside the read-only
PyInstaller bundle.
@@ -32,8 +33,9 @@ FR: Pipeline d'enrichissement des IP distantes :
CONFIDENTIALITÉ : AUCUN repli de géolocalisation en ligne. ip-api.com a été
supprimé — un outil de confidentialité ne doit jamais divulguer les IP
- visitées en clair. Sans .mmdb, l'UI affiche « sans géo » et le README
- explique comment l'activer. Les bases vivent dans le dossier de données
+ visitées en clair. DB-IP Lite est embarquée gzipée dans le repo (CC BY 4.0)
+ et décompressée dans GEO_DIR au premier usage — la géo marche d'emblée
+ sans aucun appel réseau. Les bases vivent dans le dossier de données
utilisateur de l'OS (paths.data_dir()), PAS à côté de __file__ — l'ancien
code Path(__file__)/data pointait dans le bundle PyInstaller en lecture
seule.
@@ -46,10 +48,13 @@ FR: Pipeline d'enrichissement des IP distantes :
"""
import asyncio
+import gzip
import ipaddress
import logging
import socket
+import sys
import threading
+from pathlib import Path
import time
from functools import lru_cache
from typing import Optional
@@ -76,6 +81,19 @@ socket.setdefaulttimeout(3)
GEO_DIR = data_dir() / "geo"
+# EN: Bundled gzip'd DB-IP Lite databases, shipped inside the repo/package so
+# geolocation works out of the box with ZERO runtime download. On first
+# use we decompress them into GEO_DIR (~130 MB — kept .gz in git to stay
+# under the 100 MB/file host limit).
+# FR: Bases DB-IP Lite gzipées embarquées dans le repo/paquet pour que la
+# géolocalisation marche d'emblée sans AUCUN téléchargement. À la première
+# utilisation on les décompresse dans GEO_DIR (~130 Mo — gardées en .gz
+# dans git pour rester sous la limite de 100 Mo/fichier de l'hébergeur).
+_BUNDLED_GEO_DIRS = [
+ Path(__file__).resolve().parent.parent / "data" / "geo", # EN: source tree / FR: arborescence source
+ Path(getattr(sys, "_MEIPASS", "/nonexistent")) / "data" / "geo", # EN: PyInstaller bundle / FR: bundle PyInstaller
+]
+
_CITY_NAMES = ("dbip-city-lite.mmdb", "GeoLite2-City.mmdb")
_ASN_NAMES = ("dbip-asn-lite.mmdb", "GeoLite2-ASN.mmdb")
@@ -179,6 +197,32 @@ def reset_readers() -> None:
resolve_geo.cache_clear()
+def _install_bundled_dbs() -> None:
+ """
+ EN: Decompress each bundled `data/geo/*.mmdb.gz` into GEO_DIR when the
+ plain .mmdb isn't already there. Never overwrites a DB the user
+ installed/downloaded themselves. Idempotent and cheap once done.
+ FR: Décompresser chaque `data/geo/*.mmdb.gz` embarqué dans GEO_DIR quand le
+ .mmdb correspondant n'y est pas déjà. N'écrase jamais une base
+ installée/téléchargée par l'utilisateur. Idempotent et négligeable
+ une fois fait.
+ """
+ try:
+ bundled = next((d for d in _BUNDLED_GEO_DIRS if d.is_dir()), None)
+ if bundled is None:
+ return
+ for gz in bundled.glob("*.mmdb.gz"):
+ target = GEO_DIR / gz.name[:-3]
+ if target.exists():
+ continue
+ GEO_DIR.mkdir(parents=True, exist_ok=True)
+ with gzip.open(gz, "rb") as src, open(target, "wb") as dst:
+ dst.write(src.read())
+ logger.info("bundled geo database installed: %s", target.name)
+ except Exception as exc:
+ logger.warning("bundled geo install failed: %s", exc)
+
+
def _get_reader(kind: str):
"""
EN: Lazy-open one .mmdb reader ('city' or 'asn'). Prefers DB-IP Lite
@@ -192,6 +236,7 @@ def _get_reader(kind: str):
with _readers_lock:
if kind in _readers:
return _readers[kind]
+ _install_bundled_dbs()
names = _CITY_NAMES if kind == "city" else _ASN_NAMES
reader = None
for name in names: