// Fix #PSCFV-4190
This commit is contained in:
+143
-62
@@ -20,43 +20,85 @@
|
|||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define("GEOIP_COUNTRY_BEGIN", 16776960);
|
/* PrestaShop
|
||||||
define("GEOIP_STATE_BEGIN_REV0", 16700000);
|
Test if functions and defines are already defined
|
||||||
define("GEOIP_STATE_BEGIN_REV1", 16000000);
|
END
|
||||||
define("GEOIP_STANDARD", 0);
|
*/
|
||||||
define("GEOIP_MEMORY_CACHE", 1);
|
|
||||||
define("GEOIP_SHARED_MEMORY", 2);
|
if (!defined('GEOIP_COUNTRY_BEGIN'))
|
||||||
define("STRUCTURE_INFO_MAX_SIZE", 20);
|
define("GEOIP_COUNTRY_BEGIN", 16776960);
|
||||||
define("DATABASE_INFO_MAX_SIZE", 100);
|
if (!defined('GEOIP_STATE_BEGIN_REV0'))
|
||||||
define("GEOIP_COUNTRY_EDITION", 106);
|
define("GEOIP_STATE_BEGIN_REV0", 16700000);
|
||||||
define("GEOIP_PROXY_EDITION", 8);
|
if (!defined('GEOIP_STATE_BEGIN_REV1'))
|
||||||
define("GEOIP_ASNUM_EDITION", 9);
|
define("GEOIP_STATE_BEGIN_REV1", 16000000);
|
||||||
define("GEOIP_NETSPEED_EDITION", 10);
|
if (!defined('GEOIP_STANDARD'))
|
||||||
define("GEOIP_REGION_EDITION_REV0", 112);
|
define("GEOIP_STANDARD", 0);
|
||||||
define("GEOIP_REGION_EDITION_REV1", 3);
|
if (!defined('GEOIP_MEMORY_CACHE'))
|
||||||
define("GEOIP_CITY_EDITION_REV0", 111);
|
define("GEOIP_MEMORY_CACHE", 1);
|
||||||
define("GEOIP_CITY_EDITION_REV1", 2);
|
if (!defined('GEOIP_SHARED_MEMORY'))
|
||||||
define("GEOIP_ORG_EDITION", 110);
|
define("GEOIP_SHARED_MEMORY", 2);
|
||||||
define("GEOIP_ISP_EDITION", 4);
|
if (!defined('STRUCTURE_INFO_MAX_SIZE'))
|
||||||
define("SEGMENT_RECORD_LENGTH", 3);
|
define("STRUCTURE_INFO_MAX_SIZE", 20);
|
||||||
define("STANDARD_RECORD_LENGTH", 3);
|
if (!defined('DATABASE_INFO_MAX_SIZE'))
|
||||||
define("ORG_RECORD_LENGTH", 4);
|
define("DATABASE_INFO_MAX_SIZE", 100);
|
||||||
define("MAX_RECORD_LENGTH", 4);
|
if (!defined('GEOIP_COUNTRY_EDITION'))
|
||||||
define("MAX_ORG_RECORD_LENGTH", 300);
|
define("GEOIP_COUNTRY_EDITION", 106);
|
||||||
define("GEOIP_SHM_KEY", 0x4f415401);
|
if (!defined('GEOIP_PROXY_EDITION'))
|
||||||
define("US_OFFSET", 1);
|
define("GEOIP_PROXY_EDITION", 8);
|
||||||
define("CANADA_OFFSET", 677);
|
if (!defined('GEOIP_ASNUM_EDITION'))
|
||||||
define("WORLD_OFFSET", 1353);
|
define("GEOIP_ASNUM_EDITION", 9);
|
||||||
define("FIPS_RANGE", 360);
|
if (!defined('GEOIP_NETSPEED_EDITION'))
|
||||||
define("GEOIP_UNKNOWN_SPEED", 0);
|
define("GEOIP_NETSPEED_EDITION", 10);
|
||||||
define("GEOIP_DIALUP_SPEED", 1);
|
if (!defined('GEOIP_REGION_EDITION_REV0'))
|
||||||
define("GEOIP_CABLEDSL_SPEED", 2);
|
define("GEOIP_REGION_EDITION_REV0", 112);
|
||||||
define("GEOIP_CORPORATE_SPEED", 3);
|
if (!defined('GEOIP_REGION_EDITION_REV1'))
|
||||||
define("GEOIP_DOMAIN_EDITION", 11);
|
define("GEOIP_REGION_EDITION_REV1", 3);
|
||||||
define("GEOIP_LOCATIONA_EDITION", 13);
|
if (!defined('GEOIP_CITY_EDITION_REV0'))
|
||||||
define("GEOIP_ACCURACYRADIUS_EDITION", 14);
|
define("GEOIP_CITY_EDITION_REV0", 111);
|
||||||
define("GEOIP_CITYCOMBINED_EDITION", 15);
|
if (!defined('GEOIP_CITY_EDITION_REV1'))
|
||||||
define("CITYCOMBINED_FIXED_RECORD", 7 );
|
define("GEOIP_CITY_EDITION_REV1", 2);
|
||||||
|
if (!defined('GEOIP_ORG_EDITION'))
|
||||||
|
define("GEOIP_ORG_EDITION", 110);
|
||||||
|
if (!defined('GEOIP_ISP_EDITION'))
|
||||||
|
define("GEOIP_ISP_EDITION", 4);
|
||||||
|
if (!defined('SEGMENT_RECORD_LENGTH'))
|
||||||
|
define("SEGMENT_RECORD_LENGTH", 3);
|
||||||
|
if (!defined('STANDARD_RECORD_LENGTH'))
|
||||||
|
define("STANDARD_RECORD_LENGTH", 3);
|
||||||
|
if (!defined('ORG_RECORD_LENGTH'))
|
||||||
|
define("ORG_RECORD_LENGTH", 4);
|
||||||
|
if (!defined('MAX_RECORD_LENGTH'))
|
||||||
|
define("MAX_RECORD_LENGTH", 4);
|
||||||
|
if (!defined('MAX_ORG_RECORD_LENGTH'))
|
||||||
|
define("MAX_ORG_RECORD_LENGTH", 300);
|
||||||
|
if (!defined('GEOIP_SHM_KEY'))
|
||||||
|
define("GEOIP_SHM_KEY", 0x4f415401);
|
||||||
|
if (!defined('US_OFFSET'))
|
||||||
|
define("US_OFFSET", 1);
|
||||||
|
if (!defined('CANADA_OFFSET'))
|
||||||
|
define("CANADA_OFFSET", 677);
|
||||||
|
if (!defined('WORLD_OFFSET'))
|
||||||
|
define("WORLD_OFFSET", 1353);
|
||||||
|
if (!defined('FIPS_RANGE'))
|
||||||
|
define("FIPS_RANGE", 360);
|
||||||
|
if (!defined('GEOIP_UNKNOWN_SPEED'))
|
||||||
|
define("GEOIP_UNKNOWN_SPEED", 0);
|
||||||
|
if (!defined('GEOIP_DIALUP_SPEED'))
|
||||||
|
define("GEOIP_DIALUP_SPEED", 1);
|
||||||
|
if (!defined('GEOIP_CABLEDSL_SPEED'))
|
||||||
|
define("GEOIP_CABLEDSL_SPEED", 2);
|
||||||
|
if (!defined('GEOIP_CORPORATE_SPEED'))
|
||||||
|
define("GEOIP_CORPORATE_SPEED", 3);
|
||||||
|
if (!defined('GEOIP_DOMAIN_EDITION'))
|
||||||
|
define("GEOIP_DOMAIN_EDITION", 11);
|
||||||
|
if (!defined('GEOIP_LOCATIONA_EDITION'))
|
||||||
|
define("GEOIP_LOCATIONA_EDITION", 13);
|
||||||
|
if (!defined('GEOIP_ACCURACYRADIUS_EDITION'))
|
||||||
|
define("GEOIP_ACCURACYRADIUS_EDITION", 14);
|
||||||
|
if (!defined('GEOIP_CITYCOMBINED_EDITION'))
|
||||||
|
define("GEOIP_CITYCOMBINED_EDITION", 15);
|
||||||
|
if (!defined('CITYCOMBINED_FIXED_RECORD'))
|
||||||
|
define("CITYCOMBINED_FIXED_RECORD", 7 );
|
||||||
|
|
||||||
class GeoIP {
|
class GeoIP {
|
||||||
var $flags;
|
var $flags;
|
||||||
@@ -239,7 +281,9 @@ class GeoIP {
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
function geoip_load_shared_mem ($file) {
|
if (!function_exists('geoip_load_shared_mem'))
|
||||||
|
{
|
||||||
|
function geoip_load_shared_mem ($file) {
|
||||||
|
|
||||||
$fp = fopen($file, "rb");
|
$fp = fopen($file, "rb");
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
@@ -255,9 +299,11 @@ function geoip_load_shared_mem ($file) {
|
|||||||
$shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size);
|
$shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size);
|
||||||
shmop_write ($shmid, fread($fp, $size), 0);
|
shmop_write ($shmid, fread($fp, $size), 0);
|
||||||
shmop_close ($shmid);
|
shmop_close ($shmid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('_setup_segments'))
|
||||||
function _setup_segments($gi){
|
{
|
||||||
|
function _setup_segments($gi){
|
||||||
$gi->databaseType = GEOIP_COUNTRY_EDITION;
|
$gi->databaseType = GEOIP_COUNTRY_EDITION;
|
||||||
$gi->record_length = STANDARD_RECORD_LENGTH;
|
$gi->record_length = STANDARD_RECORD_LENGTH;
|
||||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||||
@@ -346,9 +392,12 @@ function _setup_segments($gi){
|
|||||||
fseek($gi->filehandle,$filepos,SEEK_SET);
|
fseek($gi->filehandle,$filepos,SEEK_SET);
|
||||||
}
|
}
|
||||||
return $gi;
|
return $gi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function geoip_open($filename, $flags) {
|
if (!function_exists('geoip_open'))
|
||||||
|
{
|
||||||
|
function geoip_open($filename, $flags) {
|
||||||
$gi = new GeoIP;
|
$gi = new GeoIP;
|
||||||
$gi->flags = $flags;
|
$gi->flags = $flags;
|
||||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||||
@@ -363,46 +412,60 @@ function geoip_open($filename, $flags) {
|
|||||||
|
|
||||||
$gi = _setup_segments($gi);
|
$gi = _setup_segments($gi);
|
||||||
return $gi;
|
return $gi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('geoip_close'))
|
||||||
function geoip_close($gi) {
|
{
|
||||||
|
function geoip_close($gi) {
|
||||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fclose($gi->filehandle);
|
return fclose($gi->filehandle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('geoip_country_id_by_name'))
|
||||||
function geoip_country_id_by_name($gi, $name) {
|
{
|
||||||
|
function geoip_country_id_by_name($gi, $name) {
|
||||||
$addr = gethostbyname($name);
|
$addr = gethostbyname($name);
|
||||||
if (!$addr || $addr == $name) {
|
if (!$addr || $addr == $name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return geoip_country_id_by_addr($gi, $addr);
|
return geoip_country_id_by_addr($gi, $addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('geoip_country_code_by_name'))
|
||||||
function geoip_country_code_by_name($gi, $name) {
|
{
|
||||||
|
function geoip_country_code_by_name($gi, $name) {
|
||||||
$country_id = geoip_country_id_by_name($gi,$name);
|
$country_id = geoip_country_id_by_name($gi,$name);
|
||||||
if ($country_id !== false) {
|
if ($country_id !== false) {
|
||||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function geoip_country_name_by_name($gi, $name) {
|
if (!function_exists('geoip_country_name_by_name'))
|
||||||
|
{
|
||||||
|
function geoip_country_name_by_name($gi, $name) {
|
||||||
$country_id = geoip_country_id_by_name($gi,$name);
|
$country_id = geoip_country_id_by_name($gi,$name);
|
||||||
if ($country_id !== false) {
|
if ($country_id !== false) {
|
||||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('geoip_country_id_by_addr'))
|
||||||
function geoip_country_id_by_addr($gi, $addr) {
|
{
|
||||||
|
function geoip_country_id_by_addr($gi, $addr) {
|
||||||
$ipnum = ip2long($addr);
|
$ipnum = ip2long($addr);
|
||||||
return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function geoip_country_code_by_addr($gi, $addr) {
|
if (!function_exists('geoip_country_code_by_addr'))
|
||||||
|
{
|
||||||
|
function geoip_country_code_by_addr($gi, $addr) {
|
||||||
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
||||||
$record = geoip_record_by_addr($gi,$addr);
|
$record = geoip_record_by_addr($gi,$addr);
|
||||||
if ( $record !== false ) {
|
if ( $record !== false ) {
|
||||||
@@ -415,9 +478,11 @@ function geoip_country_code_by_addr($gi, $addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('geoip_country_name_by_addr'))
|
||||||
function geoip_country_name_by_addr($gi, $addr) {
|
{
|
||||||
|
function geoip_country_name_by_addr($gi, $addr) {
|
||||||
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
||||||
$record = geoip_record_by_addr($gi,$addr);
|
$record = geoip_record_by_addr($gi,$addr);
|
||||||
return $record->country_name;
|
return $record->country_name;
|
||||||
@@ -428,9 +493,11 @@ function geoip_country_name_by_addr($gi, $addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('_geoip_seek_country'))
|
||||||
function _geoip_seek_country($gi, $ipnum) {
|
{
|
||||||
|
function _geoip_seek_country($gi, $ipnum) {
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
for ($depth = 31; $depth >= 0; --$depth) {
|
for ($depth = 31; $depth >= 0; --$depth) {
|
||||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||||
@@ -473,9 +540,11 @@ function _geoip_seek_country($gi, $ipnum) {
|
|||||||
}
|
}
|
||||||
trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('_get_org'))
|
||||||
function _get_org($gi,$ipnum){
|
{
|
||||||
|
function _get_org($gi,$ipnum){
|
||||||
$seek_org = _geoip_seek_country($gi,$ipnum);
|
$seek_org = _geoip_seek_country($gi,$ipnum);
|
||||||
if ($seek_org == $gi->databaseSegments) {
|
if ($seek_org == $gi->databaseSegments) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -494,17 +563,23 @@ function _get_org($gi,$ipnum){
|
|||||||
$org_buf = substr($org_buf, 0, strpos($org_buf, "\0"));
|
$org_buf = substr($org_buf, 0, strpos($org_buf, "\0"));
|
||||||
mb_internal_encoding($enc);
|
mb_internal_encoding($enc);
|
||||||
return $org_buf;
|
return $org_buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function geoip_org_by_addr ($gi,$addr) {
|
if (!function_exists('geoip_org_by_addr'))
|
||||||
|
{
|
||||||
|
function geoip_org_by_addr ($gi,$addr) {
|
||||||
if ($addr == NULL) {
|
if ($addr == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$ipnum = ip2long($addr);
|
$ipnum = ip2long($addr);
|
||||||
return _get_org($gi, $ipnum);
|
return _get_org($gi, $ipnum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _get_region($gi,$ipnum){
|
if (!function_exists('_get_region'))
|
||||||
|
{
|
||||||
|
function _get_region($gi,$ipnum){
|
||||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||||
$seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0;
|
$seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0;
|
||||||
if ($seek_region >= 1000){
|
if ($seek_region >= 1000){
|
||||||
@@ -533,17 +608,23 @@ function _get_region($gi,$ipnum){
|
|||||||
}
|
}
|
||||||
return array ($country_code,$region);
|
return array ($country_code,$region);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function geoip_region_by_addr ($gi,$addr) {
|
if (!function_exists('geoip_region_by_addr'))
|
||||||
|
{
|
||||||
|
function geoip_region_by_addr ($gi,$addr) {
|
||||||
if ($addr == NULL) {
|
if ($addr == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$ipnum = ip2long($addr);
|
$ipnum = ip2long($addr);
|
||||||
return _get_region($gi, $ipnum);
|
return _get_region($gi, $ipnum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getdnsattributes ($l,$ip){
|
if (!function_exists('getdnsattributes'))
|
||||||
|
{
|
||||||
|
function getdnsattributes ($l,$ip){
|
||||||
$r = new Net_DNS_Resolver();
|
$r = new Net_DNS_Resolver();
|
||||||
$r->nameservers = array("ws1.maxmind.com");
|
$r->nameservers = array("ws1.maxmind.com");
|
||||||
$p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN");
|
$p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN");
|
||||||
@@ -551,6 +632,6 @@ function getdnsattributes ($l,$ip){
|
|||||||
ereg("\"(.*)\"",$str,$regs);
|
ereg("\"(.*)\"",$str,$regs);
|
||||||
$str = $regs[1];
|
$str = $regs[1];
|
||||||
return $str;
|
return $str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user