Fix: geoip works with debian geoip package
This commit is contained in:
parent
301c66210a
commit
f75329faef
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.org>
|
/* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.org>
|
||||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -129,20 +129,27 @@ print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" targe
|
|||||||
if ($geoip)
|
if ($geoip)
|
||||||
{
|
{
|
||||||
print '<br><br>';
|
print '<br><br>';
|
||||||
print '<br>';
|
print '<br>'.$langs->trans("TestGeoIPResult",$ip).':';
|
||||||
|
|
||||||
$ip='24.24.24.24';
|
$ip='24.24.24.24';
|
||||||
print $langs->trans("TestGeoIPResult",$ip).':<br>';
|
print '<br>'.$ip.' -> ';
|
||||||
print $ip.' -> ';
|
|
||||||
$result=dol_print_ip($ip,1);
|
$result=dol_print_ip($ip,1);
|
||||||
if ($result) print $result;
|
if ($result) print $result;
|
||||||
else print $langs->trans("Error");
|
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.' -> ';
|
||||||
|
$result=dol_print_ip($ip,1);
|
||||||
|
if ($result) print $result;
|
||||||
|
else print $langs->trans("Error");
|
||||||
|
*/
|
||||||
$geoip->close();
|
$geoip->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_htmloutput_mesg($mesg);
|
dol_htmloutput_mesg($mesg);
|
||||||
|
|
||||||
$db->close();
|
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
|
|
||||||
|
$db->close();
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
/* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,17 +19,17 @@
|
|||||||
/**
|
/**
|
||||||
* \file htdocs/core/class/dolgeoip.class.php
|
* \file htdocs/core/class/dolgeoip.class.php
|
||||||
* \ingroup geoip
|
* \ingroup geoip
|
||||||
* \brief Library for managing module geoip
|
* \brief File of class to manage module geoip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class DolGeoIP
|
* \class DolGeoIP
|
||||||
* \brief Classe to manage GeoIP
|
* \brief Classe to manage GeoIP
|
||||||
* \remarks Usage:
|
* Usage:
|
||||||
* \remarks $geoip=new GeoIP('country',$datfile);
|
* $geoip=new GeoIP('country',$datfile);
|
||||||
* \remarks $geoip->getCountryCodeFromIP($ip);
|
* $geoip->getCountryCodeFromIP($ip);
|
||||||
* \remarks $geoip->close();
|
* $geoip->close();
|
||||||
*/
|
*/
|
||||||
class DolGeoIP
|
class DolGeoIP
|
||||||
{
|
{
|
||||||
@ -56,6 +56,7 @@ class DolGeoIP
|
|||||||
}
|
}
|
||||||
else { print 'ErrorBadParameterInConstructor'; return 0; }
|
else { print 'ErrorBadParameterInConstructor'; return 0; }
|
||||||
|
|
||||||
|
// Here, function exists (embedded into PHP or exists because we made include)
|
||||||
if (empty($type) || empty($datfile))
|
if (empty($type) || empty($datfile))
|
||||||
{
|
{
|
||||||
//dol_syslog("DolGeoIP::DolGeoIP parameter datafile not defined", LOG_ERR);
|
//dol_syslog("DolGeoIP::DolGeoIP parameter datafile not defined", LOG_ERR);
|
||||||
@ -73,7 +74,16 @@ class DolGeoIP
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->gi = geoip_open($datfile,GEOIP_STANDARD);
|
if (function_exists('geoip_open'))
|
||||||
|
{
|
||||||
|
$this->gi = geoip_open($datfile,GEOIP_STANDARD);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->gi = 'NOGI'; // We are using embedded php geoip functions
|
||||||
|
//print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name');
|
||||||
|
//print geoip_database_info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,7 +98,16 @@ class DolGeoIP
|
|||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return strtolower(geoip_country_code_by_addr($this->gi, $ip));
|
if ($this->gi == 'NOGI')
|
||||||
|
{
|
||||||
|
// geoip_country_code_by_addr does not exists
|
||||||
|
return strtolower(geoip_country_code_by_name($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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,6 +132,7 @@ class DolGeoIP
|
|||||||
*/
|
*/
|
||||||
function getVersion()
|
function getVersion()
|
||||||
{
|
{
|
||||||
|
if ($this->gi == 'NOGI') return geoip_database_info();
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -195,7 +195,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get entity to use
|
* Get entity to use
|
||||||
*
|
*
|
||||||
* @param string $element Current element
|
* @param string $element Current element
|
||||||
* @param int $shared 1=Return shared entities
|
* @param int $shared 1=Return shared entities
|
||||||
* @return mixed Entity id(s) to use
|
* @return mixed Entity id(s) to use
|
||||||
@ -203,7 +203,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
|
|||||||
function getEntity($element=false, $shared=false)
|
function getEntity($element=false, $shared=false)
|
||||||
{
|
{
|
||||||
global $conf, $mc;
|
global $conf, $mc;
|
||||||
|
|
||||||
if (is_object($mc))
|
if (is_object($mc))
|
||||||
{
|
{
|
||||||
return $mc->getEntity($element, $shared);
|
return $mc->getEntity($element, $shared);
|
||||||
@ -211,12 +211,12 @@ function getEntity($element=false, $shared=false)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$out='';
|
$out='';
|
||||||
|
|
||||||
$addzero = array('user', 'usergroup');
|
$addzero = array('user', 'usergroup');
|
||||||
if (in_array($element, $addzero)) $out.= '0,';
|
if (in_array($element, $addzero)) $out.= '0,';
|
||||||
|
|
||||||
$out.= $conf->entity;
|
$out.= $conf->entity;
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1334,7 +1334,7 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ=
|
|||||||
* Return an IP formated to be shown on screen
|
* Return an IP formated to be shown on screen
|
||||||
*
|
*
|
||||||
* @param string $ip IP
|
* @param string $ip IP
|
||||||
* @param int $mode 1=return only country/flag,2=return only IP
|
* @param int $mode 0=return IP + country/flag, 1=return only country/flag, 2=return only IP
|
||||||
* @return string Formated IP, with country if GeoIP module is enabled
|
* @return string Formated IP, with country if GeoIP module is enabled
|
||||||
*/
|
*/
|
||||||
function dol_print_ip($ip,$mode=0)
|
function dol_print_ip($ip,$mode=0)
|
||||||
@ -2223,7 +2223,7 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename=''
|
|||||||
|
|
||||||
// More features to check
|
// More features to check
|
||||||
$features = explode("&",$features);
|
$features = explode("&",$features);
|
||||||
|
|
||||||
// More parameters
|
// More parameters
|
||||||
list($dbtablename, $sharedelement) = explode('&', $dbtablename);
|
list($dbtablename, $sharedelement) = explode('&', $dbtablename);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user