Switch GeoIP code to use GeoIPv2 databases

This commit is contained in:
Tom Hughes 2020-01-01 18:50:48 +00:00
parent ae83f2afc2
commit e0df631848
4 changed files with 12 additions and 12 deletions

View file

@ -93,8 +93,8 @@ gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_1
# Load faraday for mockable HTTP client
gem "faraday"
# Load geoip for querying Maxmind GeoIP database
gem "geoip"
# Load maxminddb for querying Maxmind GeoIP database
gem "maxminddb"
# Load rotp to generate TOTP tokens
gem "rotp"

View file

@ -208,7 +208,6 @@ GEM
fspath (3.1.2)
gd2-ffij (0.4.0)
ffi (>= 1.0.0)
geoip (1.6.4)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashdiff (1.0.0)
@ -260,6 +259,7 @@ GEM
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
maxminddb (0.1.22)
method_source (0.9.2)
mimemagic (0.3.3)
mini_magick (4.9.5)
@ -489,7 +489,6 @@ DEPENDENCIES
faraday
ffi-libarchive
gd2-ffij (>= 0.4.0)
geoip
htmlentities
http_accept_language (~> 2.0.0)
i18n-js (>= 3.0.0)
@ -502,6 +501,7 @@ DEPENDENCIES
libxml-ruby (>= 2.0.5)
listen
logstasher
maxminddb
mimemagic
mini_magick
minitest (~> 5.1)

View file

@ -49,8 +49,8 @@ max_messages_per_hour: 60
#messages_domain: "messages.openstreetmap.org"
# Geonames authentication details
#geonames_username: ""
# GeoIP database
#geoip_database: ""
# MaxMind GeoIPv2 database
#maxmind_database: ""
# Users to show as being nearby
nearby_users: 30
# Max radius, in km, for nearby users

View file

@ -511,10 +511,10 @@ module OSM
end
def self.ip_to_country(ip_address)
ipinfo = geoip_database.country(ip_address) if Settings.key?(:geoip_database)
ipinfo = maxmind_database.lookup(ip_address) if Settings.key?(:maxmind_database)
if ipinfo
country = ipinfo.country_code2
if ipinfo.found?
country = ipinfo.country.iso_code
else
country = http_client.get("https://api.hostip.info/country.php?ip=#{ip_address}").body
country = "GB" if country == "UK"
@ -575,8 +575,8 @@ module OSM
@http_client ||= Faraday.new
end
# Return the GeoIP database handle
def self.geoip_database
@geoip_database ||= GeoIP.new(Settings.geoip_database) if Settings.key?(:geoip_database)
# Return the MaxMindDB database handle
def self.maxmind_database
@maxmind_database ||= MaxMindDB.new(Settings.maxmind_database) if Settings.key?(:maxmind_database)
end
end