package WebGUI::Macro::GeoIP; # CVS Info: # $Author: mike $ # $Date: 2005/04/05 00:43:24 $ # $Revision: 1.1 $ # # add an entry in the appropriate webgui.conf file in the macro section: # GeoIP => GeoIP, \ # # if you have subscribed to MaxMind City data, add a line to the webgui.conf # defining the location of the data file # GeoIPCity='/usr/local/share/GeoIP/GeoIPCity-532.dat' # # * calling the macro without params will use the country db and will only # return the country code. # * calling the macro with one param will return that one param if a match # is found in the GeoIPCity db. # - country_code - ISO 3166 country code # - country_code3 - ISO 3166 3 letter country code # - country_name - returns the country name # - region - returns the region - State/Prov for USA/Canada # - city - returns the city name # - postal_code - returns the ZIP/Postal Code # - latitude - returns the latitude # - longitude - returns the longitude # - dma_code - returns the Nielsen DMA code for USA # - area_code - returns the phone number area code for USA use strict; use WebGUI::Macro; use WebGUI::Session; use Geo::IP; #------------------------------------------------------------------- sub process { my $mode = lc( shift ); my $ip = $session{var}{lastIP}; my $db = $session{'config'}{'GeoIPCity'}; if ( ! $mode ) { # lets do basic country code only my $gi = Geo::IP->new(GEOIP_STANDARD); # TODO move this to preload return $gi->country_code_by_addr($ip); } elsif ( -e $db ) { # lets get a city record and return the requested data my $gi2 = Geo::IP->open($db,GEOIP_STANDARD); # TODO move this to preload my $record = $gi2->record_by_addr($ip); if ( $mode =~ m/country_code|country_code3|country_name|region|city|postal_code|latitude|longitude|dma_code|area_code/i ) { return $record->$mode; } } } 1;