From 4613005b836cf2435adcdbb1e803090bfa3e9cee Mon Sep 17 00:00:00 2001 From: j Date: Fri, 4 Mar 2016 12:50:44 +0530 Subject: [PATCH] use geoip2 api to fix ipv6 lookups --- pandora/app/config.py | 12 ++---------- pandora/user/models.py | 5 +++-- requirements.txt | 3 ++- update.py | 6 ++++++ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pandora/app/config.py b/pandora/app/config.py index 060f661a..973a2b4e 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -308,17 +308,9 @@ def update_static(): os.symlink(default_script, script) def update_geoip(force=False): - path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCity.dat') + path = os.path.join(settings.GEOIP_PATH, 'GeoLite2-City.mmdb') if not os.path.exists(path) or force: - url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz' - print('download', url) - ox.net.save_url(url, "%s.gz"%path) - if os.path.exists(path): - os.unlink(path) - os.system('gunzip "%s.gz"' % path) - path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCityv6.dat') - if not os.path.exists(path) or force: - url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz' + url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz' print('download', url) ox.net.save_url(url, "%s.gz"%path) if os.path.exists(path): diff --git a/pandora/user/models.py b/pandora/user/models.py index 6f7d1c1f..4aaf4c7c 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -7,7 +7,8 @@ from django.contrib.auth.models import User, Group from django.db import models from django.db.models import Max from django.conf import settings -from django.contrib.gis.geoip import GeoIP +from django.contrib.gis.geoip2 import GeoIP2 + import ox @@ -66,7 +67,7 @@ class SessionData(models.Model): self.parse_useragent() if self.ip: try: - g = GeoIP() + g = GeoIP2() location = g.city(self.ip) if location: country = ox.get_country_name(location['country_code']) diff --git a/requirements.txt b/requirements.txt index f643a72a..2f04c901 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,5 +6,6 @@ django-celery==3.1.17 django-extensions==1.6.1 gunicorn==19.4.5 html5lib -requests==2.2.1 +requests==2.9.1 tornado==4.1 +geoip2==2.2.0 diff --git a/update.py b/update.py index 2a16b14a..ae31bdcf 100755 --- a/update.py +++ b/update.py @@ -191,6 +191,12 @@ if __name__ == "__main__": if os.path.exists('/lib/systemd/system'): print('\tsudo cp %s/etc/systemd/%s.service /lib/systemd/system/' % (base, service)) print('\tsudo service %s restart' % service) + if old <= 5432: + import pandora.settings + run('./bin/pip', 'install', '-r', 'requirements.txt') + path = os.path.join(pandora.settings.GEOIP_PATH, 'GeoLite2-City.mmdb') + if not os.path.exists(path): + run('./pandora/manage.py', 'update_geoip') else: if len(sys.argv) == 1: release = get_release()