Switch GeoIP code to use GeoIPv2 databases
This commit is contained in:
parent
ae83f2afc2
commit
e0df631848
4 changed files with 12 additions and 12 deletions
4
Gemfile
4
Gemfile
|
@ -93,8 +93,8 @@ gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_1
|
||||||
# Load faraday for mockable HTTP client
|
# Load faraday for mockable HTTP client
|
||||||
gem "faraday"
|
gem "faraday"
|
||||||
|
|
||||||
# Load geoip for querying Maxmind GeoIP database
|
# Load maxminddb for querying Maxmind GeoIP database
|
||||||
gem "geoip"
|
gem "maxminddb"
|
||||||
|
|
||||||
# Load rotp to generate TOTP tokens
|
# Load rotp to generate TOTP tokens
|
||||||
gem "rotp"
|
gem "rotp"
|
||||||
|
|
|
@ -208,7 +208,6 @@ GEM
|
||||||
fspath (3.1.2)
|
fspath (3.1.2)
|
||||||
gd2-ffij (0.4.0)
|
gd2-ffij (0.4.0)
|
||||||
ffi (>= 1.0.0)
|
ffi (>= 1.0.0)
|
||||||
geoip (1.6.4)
|
|
||||||
globalid (0.4.2)
|
globalid (0.4.2)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
hashdiff (1.0.0)
|
hashdiff (1.0.0)
|
||||||
|
@ -260,6 +259,7 @@ GEM
|
||||||
mini_mime (>= 0.1.1)
|
mini_mime (>= 0.1.1)
|
||||||
marcel (0.3.3)
|
marcel (0.3.3)
|
||||||
mimemagic (~> 0.3.2)
|
mimemagic (~> 0.3.2)
|
||||||
|
maxminddb (0.1.22)
|
||||||
method_source (0.9.2)
|
method_source (0.9.2)
|
||||||
mimemagic (0.3.3)
|
mimemagic (0.3.3)
|
||||||
mini_magick (4.9.5)
|
mini_magick (4.9.5)
|
||||||
|
@ -489,7 +489,6 @@ DEPENDENCIES
|
||||||
faraday
|
faraday
|
||||||
ffi-libarchive
|
ffi-libarchive
|
||||||
gd2-ffij (>= 0.4.0)
|
gd2-ffij (>= 0.4.0)
|
||||||
geoip
|
|
||||||
htmlentities
|
htmlentities
|
||||||
http_accept_language (~> 2.0.0)
|
http_accept_language (~> 2.0.0)
|
||||||
i18n-js (>= 3.0.0)
|
i18n-js (>= 3.0.0)
|
||||||
|
@ -502,6 +501,7 @@ DEPENDENCIES
|
||||||
libxml-ruby (>= 2.0.5)
|
libxml-ruby (>= 2.0.5)
|
||||||
listen
|
listen
|
||||||
logstasher
|
logstasher
|
||||||
|
maxminddb
|
||||||
mimemagic
|
mimemagic
|
||||||
mini_magick
|
mini_magick
|
||||||
minitest (~> 5.1)
|
minitest (~> 5.1)
|
||||||
|
|
|
@ -49,8 +49,8 @@ max_messages_per_hour: 60
|
||||||
#messages_domain: "messages.openstreetmap.org"
|
#messages_domain: "messages.openstreetmap.org"
|
||||||
# Geonames authentication details
|
# Geonames authentication details
|
||||||
#geonames_username: ""
|
#geonames_username: ""
|
||||||
# GeoIP database
|
# MaxMind GeoIPv2 database
|
||||||
#geoip_database: ""
|
#maxmind_database: ""
|
||||||
# Users to show as being nearby
|
# Users to show as being nearby
|
||||||
nearby_users: 30
|
nearby_users: 30
|
||||||
# Max radius, in km, for nearby users
|
# Max radius, in km, for nearby users
|
||||||
|
|
12
lib/osm.rb
12
lib/osm.rb
|
@ -511,10 +511,10 @@ module OSM
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ip_to_country(ip_address)
|
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
|
if ipinfo.found?
|
||||||
country = ipinfo.country_code2
|
country = ipinfo.country.iso_code
|
||||||
else
|
else
|
||||||
country = http_client.get("https://api.hostip.info/country.php?ip=#{ip_address}").body
|
country = http_client.get("https://api.hostip.info/country.php?ip=#{ip_address}").body
|
||||||
country = "GB" if country == "UK"
|
country = "GB" if country == "UK"
|
||||||
|
@ -575,8 +575,8 @@ module OSM
|
||||||
@http_client ||= Faraday.new
|
@http_client ||= Faraday.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the GeoIP database handle
|
# Return the MaxMindDB database handle
|
||||||
def self.geoip_database
|
def self.maxmind_database
|
||||||
@geoip_database ||= GeoIP.new(Settings.geoip_database) if Settings.key?(:geoip_database)
|
@maxmind_database ||= MaxMindDB.new(Settings.maxmind_database) if Settings.key?(:maxmind_database)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue