2013-08-17 21:48:48 +00:00
|
|
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2014-05-03 12:34:36 +00:00
|
|
|
class GeoIp
|
|
|
|
include ApplicationLib
|
2013-08-15 20:40:22 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
lookup location based on ip or hostname
|
|
|
|
|
|
|
|
result = GeoIp.location( '172.0.0.1' )
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = {
|
|
|
|
"ip" => "172.0.0.1"
|
|
|
|
"country_code" => "DE",
|
|
|
|
"country_name" => "Germany",
|
|
|
|
"region_code" => "05",
|
|
|
|
"region_name" => "Hessen",
|
|
|
|
"city" => "Frankfurt Am Main"
|
|
|
|
"zipcode" => "12345",
|
|
|
|
"latitude" => 50.1167,
|
|
|
|
"longitude" => 8.6833,
|
|
|
|
"metro_code" => "",
|
|
|
|
"areacode" => ""
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.location(address)
|
|
|
|
|
|
|
|
# load backend
|
2015-05-07 12:10:38 +00:00
|
|
|
backend = load_adapter_by_setting( 'geo_ip_backend' )
|
2013-08-15 20:40:22 +00:00
|
|
|
return if !backend
|
|
|
|
|
|
|
|
# db lookup
|
|
|
|
backend.location(address)
|
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|