geo_ip.rb 821 B

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