mirror of https://github.com/BOINC/boinc.git
- updated GeoIP stuff
svn path=/trunk/boinc/; revision=14951
This commit is contained in:
parent
b7e7e1cf1e
commit
9de3ad8a9a
|
@ -2573,3 +2573,10 @@ Charlie Mar 20 2008
|
|||
boinc.xcodeproj/
|
||||
project.pbxproj
|
||||
buildWxMac.sh
|
||||
|
||||
David Mar 20 2008
|
||||
- updated GeoIP stuff
|
||||
|
||||
html/inc/
|
||||
GeoIP.dat
|
||||
geoip.inc
|
||||
|
|
Binary file not shown.
|
@ -1,15 +1,12 @@
|
|||
<?php
|
||||
|
||||
/* based on php version of the geoip library written in may 2002
|
||||
by jim winstead <jimw@apache.org> */
|
||||
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* geoip.inc
|
||||
*
|
||||
* Copyright (C) 2003 MaxMind LLC
|
||||
* Copyright (C) 2004 MaxMind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
|
@ -18,12 +15,64 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
$GEOIP_COUNTRY_CODE_TO_NUMBER = array(
|
||||
/*
|
||||
* Changelog:
|
||||
*
|
||||
* 2005-01-13 Andrew Hill, Awarez Ltd. (http://www.awarez.net)
|
||||
* Formatted file according to PEAR library standards.
|
||||
* Moved $GEOIP_COUNTRY_CODE_TO_NUMBER, $GEOIP_COUNTRY_CODES,
|
||||
* $GEOIP_COUNTRY_CODES3 and $GEOIP_COUNTRY_NAMES into the
|
||||
* GeoIP class, so that library will still work even when
|
||||
* not included in the $GLOBAL context.
|
||||
*/
|
||||
|
||||
define("GEOIP_COUNTRY_BEGIN", 16776960);
|
||||
define("GEOIP_STATE_BEGIN_REV0", 16700000);
|
||||
define("GEOIP_STATE_BEGIN_REV1", 16000000);
|
||||
define("GEOIP_STANDARD", 0);
|
||||
define("GEOIP_MEMORY_CACHE", 1);
|
||||
define("GEOIP_SHARED_MEMORY", 2);
|
||||
define("STRUCTURE_INFO_MAX_SIZE", 20);
|
||||
define("DATABASE_INFO_MAX_SIZE", 100);
|
||||
define("GEOIP_COUNTRY_EDITION", 106);
|
||||
define("GEOIP_PROXY_EDITION", 8);
|
||||
define("GEOIP_ASNUM_EDITION", 9);
|
||||
define("GEOIP_NETSPEED_EDITION", 10);
|
||||
define("GEOIP_REGION_EDITION_REV0", 112);
|
||||
define("GEOIP_REGION_EDITION_REV1", 3);
|
||||
define("GEOIP_CITY_EDITION_REV0", 111);
|
||||
define("GEOIP_CITY_EDITION_REV1", 2);
|
||||
define("GEOIP_ORG_EDITION", 110);
|
||||
define("GEOIP_ISP_EDITION", 4);
|
||||
define("SEGMENT_RECORD_LENGTH", 3);
|
||||
define("STANDARD_RECORD_LENGTH", 3);
|
||||
define("ORG_RECORD_LENGTH", 4);
|
||||
define("MAX_RECORD_LENGTH", 4);
|
||||
define("MAX_ORG_RECORD_LENGTH", 300);
|
||||
define("GEOIP_SHM_KEY", 0x4f415401);
|
||||
define("US_OFFSET", 1);
|
||||
define("CANADA_OFFSET", 677);
|
||||
define("WORLD_OFFSET", 1353);
|
||||
define("FIPS_RANGE", 360);
|
||||
define("GEOIP_UNKNOWN_SPEED", 0);
|
||||
define("GEOIP_DIALUP_SPEED", 1);
|
||||
define("GEOIP_CABLEDSL_SPEED", 2);
|
||||
define("GEOIP_CORPORATE_SPEED", 3);
|
||||
|
||||
class GeoIP {
|
||||
var $flags;
|
||||
var $filehandle;
|
||||
var $memory_buffer;
|
||||
var $databaseType;
|
||||
var $databaseSegments;
|
||||
var $record_length;
|
||||
var $shmid;
|
||||
var $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
|
||||
"" => 0, "AP" => 1, "EU" => 2, "AD" => 3, "AE" => 4, "AF" => 5,
|
||||
"AG" => 6, "AI" => 7, "AL" => 8, "AM" => 9, "AN" => 10, "AO" => 11,
|
||||
"AQ" => 12, "AR" => 13, "AS" => 14, "AT" => 15, "AU" => 16, "AW" => 17,
|
||||
|
@ -63,11 +112,11 @@ $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
|
|||
"TP" => 216, "TR" => 217, "TT" => 218, "TV" => 219, "TW" => 220, "TZ" => 221,
|
||||
"UA" => 222, "UG" => 223, "UM" => 224, "US" => 225, "UY" => 226, "UZ" => 227,
|
||||
"VA" => 228, "VC" => 229, "VE" => 230, "VG" => 231, "VI" => 232, "VN" => 233,
|
||||
"VU" => 234, "WF" => 235, "WS" => 236, "YE" => 237, "YT" => 238, "YU" => 239,
|
||||
"VU" => 234, "WF" => 235, "WS" => 236, "YE" => 237, "YT" => 238, "CS" => 239,
|
||||
"ZA" => 240, "ZM" => 241, "ZR" => 242, "ZW" => 243, "A1" => 244, "A2" => 245,
|
||||
"O1" => 246
|
||||
);
|
||||
$GEOIP_COUNTRY_CODES = array(
|
||||
var $GEOIP_COUNTRY_CODES = array(
|
||||
"", "AP", "EU", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ",
|
||||
"AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH",
|
||||
"BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
|
||||
|
@ -86,10 +135,9 @@ $GEOIP_COUNTRY_CODES = array(
|
|||
"SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD",
|
||||
"TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TP", "TR", "TT", "TV", "TW",
|
||||
"TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN",
|
||||
"VU", "WF", "WS", "YE", "YT", "YU", "ZA", "ZM", "ZR", "ZW", "A1", "A2", "O1"
|
||||
"VU", "WF", "WS", "YE", "YT", "CS", "ZA", "ZM", "ZR", "ZW", "A1", "A2", "O1"
|
||||
);
|
||||
|
||||
$GEOIP_COUNTRY_CODES3 = array (
|
||||
var $GEOIP_COUNTRY_CODES3 = array(
|
||||
"","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","AQ","ARG",
|
||||
"ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI",
|
||||
"BEN","BMU","BRN","BOL","BRA","BHS","BTN","BV","BWA","BLR","BLZ","CAN","CC",
|
||||
|
@ -108,9 +156,9 @@ $GEOIP_COUNTRY_CODES3 = array (
|
|||
"SVK","SLE","SMR","SEN","SOM","SUR","STP","SLV","SYR","SWZ","TCA","TCD","TF",
|
||||
"TGO","THA","TJK","TKL","TLS","TKM","TUN","TON","TUR","TTO","TUV","TWN","TZA",
|
||||
"UKR","UGA","UM","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT",
|
||||
"WLF","WSM","YEM","YT","YUG","ZAF","ZMB","ZR","ZWE","A1","A2","O1");
|
||||
|
||||
$GEOIP_COUNTRY_NAMES = array(
|
||||
"WLF","WSM","YEM","YT","SCG","ZAF","ZMB","ZR","ZWE","A1","A2","O1"
|
||||
);
|
||||
var $GEOIP_COUNTRY_NAMES = array(
|
||||
"", "Asia/Pacific Region", "Europe", "Andorra", "United Arab Emirates",
|
||||
"Afghanistan", "Antigua and Barbuda", "Anguilla", "Albania", "Armenia",
|
||||
"Netherlands Antilles", "Angola", "Antarctica", "Argentina", "American Samoa",
|
||||
|
@ -138,15 +186,15 @@ People's Republic of", "Korea, Republic of", "Kuwait", "Cayman Islands",
|
|||
"Kazakstan", "Lao People's Democratic Republic", "Lebanon", "Saint Lucia",
|
||||
"Liechtenstein", "Sri Lanka", "Liberia", "Lesotho", "Lithuania", "Luxembourg",
|
||||
"Latvia", "Libyan Arab Jamahiriya", "Morocco", "Monaco", "Moldova, Republic
|
||||
of", "Madagascar", "Marshall Islands", "Macedonia, the Former Yugoslav Republic
|
||||
of", "Mali", "Myanmar", "Mongolia", "Macau", "Northern Mariana Islands",
|
||||
of", "Madagascar", "Marshall Islands", "Macedonia",
|
||||
"Mali", "Myanmar", "Mongolia", "Macau", "Northern Mariana Islands",
|
||||
"Martinique", "Mauritania", "Montserrat", "Malta", "Mauritius", "Maldives",
|
||||
"Malawi", "Mexico", "Malaysia", "Mozambique", "Namibia", "New Caledonia",
|
||||
"Niger", "Norfolk Island", "Nigeria", "Nicaragua", "Netherlands", "Norway",
|
||||
"Nepal", "Nauru", "Niue", "New Zealand", "Oman", "Panama", "Peru", "French
|
||||
Polynesia", "Papua New Guinea", "Philippines", "Pakistan", "Poland", "Saint
|
||||
Pierre and Miquelon", "Pitcairn", "Puerto Rico", "Palestinian Territory,
|
||||
Occupied", "Portugal", "Palau", "Paraguay", "Qatar", "Reunion", "Romania",
|
||||
Pierre and Miquelon", "Pitcairn Islands", "Puerto Rico", "Palestinian Territory",
|
||||
"Portugal", "Palau", "Paraguay", "Qatar", "Reunion", "Romania",
|
||||
"Russian Federation", "Rwanda", "Saudi Arabia", "Solomon Islands",
|
||||
"Seychelles", "Sudan", "Sweden", "Singapore", "Saint Helena", "Slovenia",
|
||||
"Svalbard and Jan Mayen", "Slovakia", "Sierra Leone", "San Marino", "Senegal",
|
||||
|
@ -159,43 +207,9 @@ Territories", "Togo", "Thailand", "Tajikistan", "Tokelau", "Turkmenistan",
|
|||
"Uzbekistan", "Holy See (Vatican City State)", "Saint Vincent and the
|
||||
Grenadines", "Venezuela", "Virgin Islands, British", "Virgin Islands, U.S.",
|
||||
"Vietnam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte",
|
||||
"Yugoslavia", "South Africa", "Zambia", "Zaire", "Zimbabwe",
|
||||
"Serbia and Montenegro", "South Africa", "Zambia", "Zaire", "Zimbabwe",
|
||||
"Anonymous Proxy","Satellite Provider","Other"
|
||||
);
|
||||
|
||||
define("GEOIP_COUNTRY_BEGIN", 16776960);
|
||||
define("GEOIP_STATE_BEGIN_REV0", 16700000);
|
||||
define("GEOIP_STATE_BEGIN_REV1", 16000000);
|
||||
define("GEOIP_STANDARD", 0);
|
||||
define("GEOIP_MEMORY_CACHE", 1);
|
||||
define("GEOIP_SHARED_MEMORY", 2);
|
||||
define("STRUCTURE_INFO_MAX_SIZE",20);
|
||||
define("DATABASE_INFO_MAX_SIZE",100);
|
||||
define("GEOIP_COUNTRY_EDITION",106);
|
||||
define("GEOIP_REGION_EDITION_REV0",112);
|
||||
define("GEOIP_REGION_EDITION_REV1",3);
|
||||
define("GEOIP_CITY_EDITION_REV0",111);
|
||||
define("GEOIP_CITY_EDITION_REV1",2);
|
||||
define("GEOIP_ORG_EDITION",110);
|
||||
define("SEGMENT_RECORD_LENGTH",3);
|
||||
define("STANDARD_RECORD_LENGTH",3);
|
||||
define("ORG_RECORD_LENGTH",4);
|
||||
define("MAX_RECORD_LENGTH",4);
|
||||
define("MAX_ORG_RECORD_LENGTH",300);
|
||||
define("GEOIP_SHM_KEY", 0x4f415401);
|
||||
define("US_OFFSET",1);
|
||||
define("CANADA_OFFSET",677);
|
||||
define("WORLD_OFFSET",1353);
|
||||
define("FIPS_RANGE",360);
|
||||
|
||||
class GeoIP {
|
||||
var $flags;
|
||||
var $filehandle;
|
||||
var $memory_buffer;
|
||||
var $databaseType;
|
||||
var $databaseSegments;
|
||||
var $record_length;
|
||||
var $shmid;
|
||||
}
|
||||
function geoip_load_shared_mem ($file) {
|
||||
|
||||
|
@ -206,8 +220,7 @@ function geoip_load_shared_mem ($file) {
|
|||
}
|
||||
$s_array = fstat($fp);
|
||||
$size = $s_array['size'];
|
||||
|
||||
if ($shmid = shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) {
|
||||
if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) {
|
||||
shmop_delete ($shmid);
|
||||
shmop_close ($shmid);
|
||||
}
|
||||
|
@ -216,50 +229,48 @@ function geoip_load_shared_mem ($file) {
|
|||
shmop_close ($shmid);
|
||||
}
|
||||
|
||||
|
||||
function _setup_segments($gi){
|
||||
$gi->databaseType = GEOIP_COUNTRY_EDITION;
|
||||
$gi->record_length = STANDARD_RECORD_LENGTH;
|
||||
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$offset = shmop_size ($gi->shmid) - 3;
|
||||
$offset = @shmop_size ($gi->shmid) - 3;
|
||||
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
||||
$delim = shmop_read ($gi->shmid, $offset, 3);
|
||||
$delim = @shmop_read ($gi->shmid, $offset, 3);
|
||||
$offset += 3;
|
||||
if ($delim == (chr(255).chr(255).chr(255))) {
|
||||
$gi->databaseType = ord(shmop_read ($gi->shmid, $offset, 1));
|
||||
$gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1));
|
||||
$offset++;
|
||||
|
||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
|
||||
}
|
||||
else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
|
||||
} else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
|
||||
}
|
||||
else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)||
|
||||
} else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)||
|
||||
($gi->databaseType == GEOIP_CITY_EDITION_REV1)
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION)){
|
||||
|| ($gi->databaseType == GEOIP_ORG_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ISP_EDITION)
|
||||
|| ($gi->databaseType == GEOIP_ASNUM_EDITION)){
|
||||
$gi->databaseSegments = 0;
|
||||
$buf = shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
|
||||
$buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
|
||||
for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
|
||||
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
||||
}
|
||||
if ($gi->databaseType == GEOIP_ORG_EDITION) {
|
||||
if (($gi->databaseType == GEOIP_ORG_EDITION)||
|
||||
($gi->databaseType == GEOIP_ISP_EDITION)) {
|
||||
$gi->record_length = ORG_RECORD_LENGTH;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$offset -= 4;
|
||||
}
|
||||
}
|
||||
if ($gi->databaseType == GEOIP_COUNTRY_EDITION){
|
||||
if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
|
||||
($gi->databaseType == GEOIP_PROXY_EDITION)||
|
||||
($gi->databaseType == GEOIP_NETSPEED_EDITION)){
|
||||
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
$filepos = ftell($gi->filehandle);
|
||||
fseek($gi->filehandle, -3, SEEK_END);
|
||||
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
||||
|
@ -268,13 +279,14 @@ function _setup_segments($gi){
|
|||
$gi->databaseType = ord(fread($gi->filehandle,1));
|
||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
|
||||
}
|
||||
}
|
||||
else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
|
||||
$gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
|
||||
}
|
||||
else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) ||
|
||||
} else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) ||
|
||||
($gi->databaseType == GEOIP_CITY_EDITION_REV1) ||
|
||||
($gi->databaseType == GEOIP_ORG_EDITION)){
|
||||
($gi->databaseType == GEOIP_ORG_EDITION) ||
|
||||
($gi->databaseType == GEOIP_ISP_EDITION) ||
|
||||
($gi->databaseType == GEOIP_ASNUM_EDITION)){
|
||||
$gi->databaseSegments = 0;
|
||||
$buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH);
|
||||
for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
|
||||
|
@ -289,8 +301,10 @@ function _setup_segments($gi){
|
|||
fseek($gi->filehandle, -4, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
if ($gi->databaseType == GEOIP_COUNTRY_EDITION){
|
||||
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
||||
if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
|
||||
($gi->databaseType == GEOIP_PROXY_EDITION)||
|
||||
($gi->databaseType == GEOIP_NETSPEED_EDITION)){
|
||||
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
fseek($gi->filehandle,$filepos,SEEK_SET);
|
||||
}
|
||||
|
@ -300,13 +314,10 @@ function _setup_segments($gi){
|
|||
function geoip_open($filename, $flags) {
|
||||
$gi = new GeoIP;
|
||||
$gi->flags = $flags;
|
||||
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$gi->shmid = shmop_open (GEOIP_SHM_KEY, "a", 0, 0);
|
||||
}
|
||||
else {
|
||||
$gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0);
|
||||
} else {
|
||||
$gi->filehandle = fopen($filename,"rb");
|
||||
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
$s_array = fstat($gi->filehandle);
|
||||
$gi->memory_buffer = fread($gi->filehandle, $s_array[size]);
|
||||
|
@ -318,6 +329,10 @@ function geoip_open($filename, $flags) {
|
|||
}
|
||||
|
||||
function geoip_close($gi) {
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return fclose($gi->filehandle);
|
||||
}
|
||||
|
||||
|
@ -332,7 +347,7 @@ function geoip_country_id_by_name($gi, $name) {
|
|||
function geoip_country_code_by_name($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $GLOBALS['GEOIP_COUNTRY_CODES'][$country_id];
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -340,7 +355,7 @@ function geoip_country_code_by_name($gi, $name) {
|
|||
function geoip_country_name_by_name($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $GLOBALS['GEOIP_COUNTRY_NAMES'][$country_id];
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -353,7 +368,7 @@ function geoip_country_id_by_addr($gi, $addr) {
|
|||
function geoip_country_code_by_addr($gi, $addr) {
|
||||
$country_id = geoip_country_id_by_addr($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $GLOBALS['GEOIP_COUNTRY_CODES'][$country_id];
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -361,7 +376,7 @@ function geoip_country_code_by_addr($gi, $addr) {
|
|||
function geoip_country_name_by_addr($gi, $addr) {
|
||||
$country_id = geoip_country_id_by_addr($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $GLOBALS['GEOIP_COUNTRY_NAMES'][$country_id];
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -373,13 +388,11 @@ function _geoip_seek_country($gi, $ipnum) {
|
|||
$buf = substr($gi->memory_buffer,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length);
|
||||
}
|
||||
elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$buf = shmop_read ($gi->shmid,
|
||||
} elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$buf = @shmop_read ($gi->shmid,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length );
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
|
||||
or die("fseek failed");
|
||||
$buf = fread($gi->filehandle, 2 * $gi->record_length);
|
||||
|
@ -395,15 +408,13 @@ function _geoip_seek_country($gi, $ipnum) {
|
|||
return $x[1];
|
||||
}
|
||||
$offset = $x[1];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($x[0] >= $gi->databaseSegments) {
|
||||
return $x[0];
|
||||
}
|
||||
$offset = $x[0];
|
||||
}
|
||||
}
|
||||
|
||||
trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
@ -415,9 +426,8 @@ function _get_org($gi,$ipnum){
|
|||
}
|
||||
$record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
$org_buf = shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
|
||||
}
|
||||
else {
|
||||
$org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
|
||||
} else {
|
||||
fseek($gi->filehandle, $record_pointer, SEEK_SET);
|
||||
$org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH);
|
||||
}
|
||||
|
@ -440,27 +450,24 @@ function _get_region($gi,$ipnum){
|
|||
$country_code = "US";
|
||||
$region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65);
|
||||
} else {
|
||||
$country_code = $GLOBALS['GEOIP_COUNTRY_CODES'][$seek_region];
|
||||
$country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
|
||||
$region = "";
|
||||
}
|
||||
return array ($country_code,$region);
|
||||
}
|
||||
else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
|
||||
} else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
||||
$seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1;
|
||||
//print $seek_region;
|
||||
if ($seek_region < US_OFFSET){
|
||||
$country_code = "";
|
||||
$region = "";
|
||||
}
|
||||
else if ($seek_region < CANADA_OFFSET){
|
||||
} else if ($seek_region < CANADA_OFFSET) {
|
||||
$country_code = "US";
|
||||
$region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65);
|
||||
}
|
||||
else if ($seek_region < WORLD_OFFSET){
|
||||
} else if ($seek_region < WORLD_OFFSET) {
|
||||
$country_code = "CA";
|
||||
$region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65);
|
||||
} else {
|
||||
$country_code = $GLOBALS['GEOIP_COUNTRY_CODES'][($seek_region - WORLD_OFFSET) / FIPS_RANGE];
|
||||
$country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
|
||||
$region = "";
|
||||
}
|
||||
return array ($country_code,$region);
|
||||
|
@ -484,4 +491,5 @@ function getdnsattributes ($l,$ip){
|
|||
$str = $regs[1];
|
||||
return $str;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue