From cf699aede04fe483352cf169b70f87c2e5518b06 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sun, 28 Jun 2020 14:09:48 -0400 Subject: [PATCH] Lookup the respective country for IP addresses in the admin panel (#1512) * Adds support for looking up countries by IP address. * Shows country and flag for a user/team's IP addresses in the admin panel * Adds support for `GEOIP_DATABASE_PATH` in config.py * Closes #1115 --- .../admin/templates/modals/teams/addresses.html | 12 ++++++++++++ .../admin/templates/modals/users/addresses.html | 12 ++++++++++++ CTFd/themes/admin/templates/teams/team.html | 2 +- CTFd/themes/admin/templates/users/user.html | 2 +- CTFd/utils/countries/geoip.py | 15 +++++++++++++++ CTFd/utils/initialization/__init__.py | 4 +++- populate.py | 10 ++++++++++ requirements.txt | 2 ++ 8 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 CTFd/utils/countries/geoip.py diff --git a/CTFd/themes/admin/templates/modals/teams/addresses.html b/CTFd/themes/admin/templates/modals/teams/addresses.html index b3e4760d..aacd8a2d 100644 --- a/CTFd/themes/admin/templates/modals/teams/addresses.html +++ b/CTFd/themes/admin/templates/modals/teams/addresses.html @@ -6,6 +6,7 @@ User IP Address Last Seen + Country @@ -20,6 +21,17 @@ + {% set country = lookup_ip_address(addr.ip) %} + {% if country %} + + +   + {{ lookup_country_code(country) }} + + {% else %} + + + {% endif %} {% endfor %} diff --git a/CTFd/themes/admin/templates/modals/users/addresses.html b/CTFd/themes/admin/templates/modals/users/addresses.html index 218a64ee..75af0a26 100644 --- a/CTFd/themes/admin/templates/modals/users/addresses.html +++ b/CTFd/themes/admin/templates/modals/users/addresses.html @@ -5,6 +5,7 @@ IP Address Last Seen + Country @@ -14,6 +15,17 @@ + {% set country = lookup_ip_address(addr.ip) %} + {% if country %} + + +   + {{ lookup_country_code(country) }} + + {% else %} + + + {% endif %} {% endfor %} diff --git a/CTFd/themes/admin/templates/teams/team.html b/CTFd/themes/admin/templates/teams/team.html index 62cef227..dcb627ec 100644 --- a/CTFd/themes/admin/templates/teams/team.html +++ b/CTFd/themes/admin/templates/teams/team.html @@ -71,7 +71,7 @@