geo_ip.rb 772 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
  2. class GeoIp < ApplicationLib
  3. =begin
  4. lookup location based on ip or hostname
  5. result = GeoIp.location( '172.0.0.1' )
  6. returns
  7. result = {
  8. "ip" => "172.0.0.1"
  9. "country_code" => "DE",
  10. "country_name" => "Germany",
  11. "region_code" => "05",
  12. "region_name" => "Hessen",
  13. "city" => "Frankfurt Am Main"
  14. "zipcode" => "12345",
  15. "latitude" => 50.1167,
  16. "longitude" => 8.6833,
  17. "metro_code" => "",
  18. "areacode" => ""
  19. }
  20. =end
  21. def self.location(address)
  22. # load backend
  23. backend = self.load_adapter_by_setting( 'geo_ip_backend' )
  24. return if !backend
  25. # db lookup
  26. backend.location(address)
  27. end
  28. end