From 9ff42ce91446837d5e1a56f8e8bc72504eb7e3d4 Mon Sep 17 00:00:00 2001 From: Corey Date: Thu, 25 Apr 2024 23:17:43 +0000 Subject: [PATCH] Switch geolocation to MaxMind --- .gitignore | 2 ++ README.md | 2 +- api/.env.example | 5 +++++ api/api/settings.py | 2 +- api/docker-compose.yml | 29 +++++++++++++++++----------- api/geoip/GeoLite2-City.mmdb | 3 --- api/v1/models/server.py | 9 ++++++--- client/src/components/ServerCard.tsx | 4 ++-- client/src/pages/ServerDetails.tsx | 4 ++-- 9 files changed, 37 insertions(+), 23 deletions(-) delete mode 100644 api/geoip/GeoLite2-City.mmdb diff --git a/.gitignore b/.gitignore index 1cad36b..93903b5 100644 --- a/.gitignore +++ b/.gitignore @@ -450,3 +450,5 @@ sketch .ionide # End of https://www.toptal.com/developers/gitignore/api/python,django,node,react,git,visualstudiocode,dotenv + +api/geoip diff --git a/README.md b/README.md index d1488ce..f6bba52 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Ixion is designed to catalog public [LandSandBoat](https://github.com/LandSandBo The React client fetches server data from the API and displays it in a relevant way to users. Filtering is built into the client for now. When the API response fails or is empty, a default LSB demo server is displayed, pulling some info from GitHub. -[IP Geolocation by DB-IP](https://db-ip.com) +[This product includes GeoLite2 Data created by MaxMind.](https://www.maxmind.com/) ## Features diff --git a/api/.env.example b/api/.env.example index 3c838ed..f8e0c98 100644 --- a/api/.env.example +++ b/api/.env.example @@ -6,3 +6,8 @@ CORS_ALLOWED_ORIGINS=https://ixion.dev # API configuration SERVER_UPDATE_INTERVAL=10 + +GEOIPUPDATE_ACCOUNT_ID=XXXXXX +GEOIPUPDATE_LICENSE_KEY=XXXXXXXXXXXXXXXX +GEOIPUPDATE_EDITION_IDS=GeoLite2-City +GEOIPUPDATE_FREQUENCY=72 diff --git a/api/api/settings.py b/api/api/settings.py index c6f340b..e62778d 100644 --- a/api/api/settings.py +++ b/api/api/settings.py @@ -84,7 +84,7 @@ WSGI_APPLICATION = "api.wsgi.application" DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + "NAME": BASE_DIR / "db" / "db.sqlite3", } } diff --git a/api/docker-compose.yml b/api/docker-compose.yml index 0701ec4..a121e9a 100644 --- a/api/docker-compose.yml +++ b/api/docker-compose.yml @@ -4,39 +4,46 @@ services: command: gunicorn api.wsgi:application --bind 0.0.0.0:8000 restart: always volumes: - - .:/app + - database:/app/db - static:/app/static + - geoipupdate_data:/app/geoip expose: - 8000 depends_on: - redis + - geoipupdate celery: build: . command: celery -A api worker -l info restart: always - volumes: - - .:/app depends_on: - - redis + - api celery-beat: build: . command: celery -A api beat -l info restart: always - volumes: - - .:/app depends_on: - - redis - redis: - image: redis:alpine - restart: always + - api nginx: image: nginx + restart: always ports: - 9969:80 volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf - - ./static:/app/static + - static:/app/static depends_on: - api + redis: + image: redis:alpine + restart: always + geoipupdate: + image: ghcr.io/maxmind/geoipupdate + env_file: .env + restart: always + volumes: + - geoipupdate_data:/usr/share/GeoIP volumes: + database: static: + geoipupdate_data: diff --git a/api/geoip/GeoLite2-City.mmdb b/api/geoip/GeoLite2-City.mmdb deleted file mode 100644 index c56c012..0000000 --- a/api/geoip/GeoLite2-City.mmdb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6d059fb98f00275a580adb0c5f75ccb6d5722e7a2c9139084f3b50a753ad6a3c -size 105210428 diff --git a/api/v1/models/server.py b/api/v1/models/server.py index 5374e53..0366836 100644 --- a/api/v1/models/server.py +++ b/api/v1/models/server.py @@ -147,9 +147,12 @@ class Server(models.Model): # except socket.error: # return False - g = GeoIP2() - city = g.city(f"{self.url}") - self.location = city["continent_code"] + try: + g = GeoIP2() + city = g.city(f"{self.url}") + self.location = city["continent_code"] + except: + self.location = "??" return True diff --git a/client/src/components/ServerCard.tsx b/client/src/components/ServerCard.tsx index 907745b..4610ff1 100644 --- a/client/src/components/ServerCard.tsx +++ b/client/src/components/ServerCard.tsx @@ -174,12 +174,12 @@ export default function ServerCard({ server }: { server: ServerData }) { { event.stopPropagation(); diff --git a/client/src/pages/ServerDetails.tsx b/client/src/pages/ServerDetails.tsx index c274b60..f0fc122 100644 --- a/client/src/pages/ServerDetails.tsx +++ b/client/src/pages/ServerDetails.tsx @@ -144,12 +144,12 @@ export default function ServerDetails({ { event.stopPropagation();