Skip to content

Commit

Permalink
Include an older default GeoLite2-City database
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Jan 19, 2020
1 parent bc20b95 commit 51185b4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mmdb filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data/client/king_phisher/style/.sass-cache/*
!.github/*.yml
!data/client/king_phisher/plugin-documentation.html
!data/server/docker/docker-compose.yml
!data/server/king_phisher/*.mmdb
!data/server/king_phisher/error_*.html
!data/server/king_phisher/server_config.yml
!data/server/king_phisher/server_config_verification.yml
Expand Down
3 changes: 3 additions & 0 deletions data/server/king_phisher/GeoLite2-City.mmdb
Git LFS file not shown
9 changes: 7 additions & 2 deletions king_phisher/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import threading

from king_phisher import errors
from king_phisher import find
from king_phisher import ipaddress

import geoip2.database
Expand Down Expand Up @@ -119,8 +120,12 @@ def init_database(database_file):
"""
# pylint: disable=global-statement
global _geoip_db
if not (os.path.isfile(database_file) and os.access(database_file, os.R_OK)):
raise errors.KingPhisherResourceError('the geoip database path is not a file')
if not os.path.isfile(database_file):
db_path = find.data_file('GeoLite2-City.mmdb')
if db_path is None:
raise errors.KingPhisherResourceError('the default geoip database file is unavailable')
logger.info('initializing the default geoip database')
shutil.copyfile(db_path, database_file)
_geoip_db = geoip2.database.Reader(database_file)
metadata = _geoip_db.metadata()
if not metadata.database_type == 'GeoLite2-City':
Expand Down

0 comments on commit 51185b4

Please sign in to comment.