Skip to content

Commit

Permalink
Update geoip v1
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 21, 2019
1 parent 689aa49 commit bfbabbf
Show file tree
Hide file tree
Showing 7 changed files with 8,840 additions and 5,052 deletions.
7 changes: 7 additions & 0 deletions htdocs/admin/geoipmaxmind.php
Expand Up @@ -144,6 +144,13 @@
if ($result) print $result;
else print $langs->trans("Error");

$ip='2a01:e0a:7e:4a60:429a:23ff:f7b8:dc8a'; // should be France
print '<br>'.$ip.' -> ';
$result=dol_print_ip($ip, 1);
if ($result) print $result;
else print $langs->trans("Error");


/* We disable this test because dol_print_ip need an ip as input
$ip='www.google.com';
print '<br>'.$ip.' -> ';
Expand Down
17 changes: 14 additions & 3 deletions htdocs/core/class/dolgeoip.class.php
Expand Up @@ -46,7 +46,10 @@ public function __construct($type, $datfile)
if ($type == 'country')
{
// geoip may have been already included with PEAR
if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc';
if (! function_exists('geoip_country_code_by_name'))
{
$res=include_once GEOIP_PATH.'geoip.inc';
}
}
elseif ($type == 'city')
{
Expand Down Expand Up @@ -101,8 +104,16 @@ public function getCountryCodeFromIP($ip)
}
else
{
if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
return strtolower(geoip_country_code_by_addr($this->gi, $ip));
if (preg_match('/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip))
{
if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
return strtolower(geoip_country_code_by_addr($this->gi, $ip));
}
else
{
if (! function_exists('geoip_country_code_by_addr_v6')) return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));
return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -2692,12 +2692,10 @@ function dolGetCountryCodeFromIp($ip)
{
$datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
//$ip='24.24.24.24';
//$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat'; Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)

//$datafile='/usr/share/GeoIP/GeoIP.dat'; Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
$geoip=new DolGeoIP('country', $datafile);
//print 'ip='.$ip.' databaseType='.$geoip->gi->databaseType." GEOIP_CITY_EDITION_REV1=".GEOIP_CITY_EDITION_REV1."\n";
//print "geoip_country_id_by_addr=".geoip_country_id_by_addr($geoip->gi,$ip)."\n";
$countrycode=$geoip->getCountryCodeFromIP($ip);
}

Expand Down

0 comments on commit bfbabbf

Please sign in to comment.