First change for future geoip module.
This commit is contained in:
parent
50553633e7
commit
0facaf4fc9
@ -17,6 +17,7 @@ FPDF 1.53 Public domain Yes PDF gene
|
||||
FPDF_TPL 1.1.2 Apache Software License 2.0 No GPL3 only PDF templates management
|
||||
FPDI 1.2.1 Apache Software License 2.0 No GPL3 only PDF templates management
|
||||
FPDI_Protection 1.0.2 Apache Software License 2.0 No GPL3 only PDF encryption (8 files)
|
||||
GeoIP x.x Yes GeoIP Maxmind conversion
|
||||
MagPieRss 0.72 GPL 2.0 Yes Load RSS
|
||||
NuSoap 0.6.5 LGPL 2.1 Yes Interfaces with third tools
|
||||
PHP_WriteExcel 0.3.0 LGPL 2.1 Yes Excel files generation
|
||||
|
||||
@ -176,6 +176,7 @@ For developers:
|
||||
- Rewrite clone feature for supplier invoice to work like other clone features.
|
||||
- First change to manage a future feature "stock PMP value".
|
||||
- A module can add a new tab in third party view tabs.
|
||||
- First change for future geoip module.
|
||||
|
||||
|
||||
***** Changelog for 2.5 compared to 2.4 *****
|
||||
|
||||
@ -130,6 +130,7 @@ if ($result)
|
||||
print '<input class="flat" type="text" size="10" name="search_code" value="'.$_GET["search_code"].'">';
|
||||
print '</td>';
|
||||
|
||||
// IP
|
||||
print '<td align="left" class="liste_titre">';
|
||||
print '<input class="flat" type="text" size="10" name="search_ip" value="'.$_GET["search_ip"].'">';
|
||||
print '</td>';
|
||||
@ -166,7 +167,30 @@ if ($result)
|
||||
print '<td>'.$obj->type.'</td>';
|
||||
|
||||
// IP
|
||||
print '<td>'.$obj->ip.'</td>';
|
||||
print '<td>';
|
||||
print $obj->ip;
|
||||
|
||||
if (! empty($conf->geoip_maxmind->enabled))
|
||||
{
|
||||
$datafile=$conf->global->GEOIP_MAXMIND_COUNTRY_DATAFILE;
|
||||
$ip=$obj->ip;
|
||||
|
||||
$ip='24.24.24.24';
|
||||
$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';
|
||||
|
||||
include_once(DOL_DOCUMENT_ROOT.'/lib/dolgeoip.class.php');
|
||||
$geoip=new DolGeoIP('country',$datafile);
|
||||
$countrycode=$geoip->getCountryCodeFromIP($ip);
|
||||
if ($countrycode) // If success, countrycode is us, fr, ...
|
||||
{
|
||||
if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png'))
|
||||
{
|
||||
print ' '.img_picto($langs->trans("AccordingToGeoIPDatabase"),DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png','',1);
|
||||
}
|
||||
else print ' ('.$countrycode.')';
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Login
|
||||
print '<td>';
|
||||
|
||||
@ -570,9 +570,9 @@ if ($step == 3 && $datatoimport)
|
||||
print '</a>';
|
||||
print '</td>';
|
||||
// Affiche taille fichier
|
||||
print '<td align="right">'.dol_print_size(dol_filesize($newdir.'/'.$newfile)).'</td>';
|
||||
print '<td align="right">'.dol_print_size(dol_filesize($dir.'/'.$file)).'</td>';
|
||||
// Affiche date fichier
|
||||
print '<td align="right">'.dol_print_date(dol_filemtime($newdir.'/'.$newfile),'dayhour').'</td>';
|
||||
print '<td align="right">'.dol_print_date(dol_filemtime($dir.'/'.$file),'dayhour').'</td>';
|
||||
// Del button
|
||||
print '<td align="right"><a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&step=3&format='.$format.'&modulepart='.$modulepart.'&file='.urlencode($relativepath);
|
||||
print '&urlsource='.urlencode($urlsource);
|
||||
@ -1069,7 +1069,9 @@ if ($step == 5 && $datatoimport)
|
||||
$obj->import_close_file();
|
||||
}
|
||||
|
||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
|
||||
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
|
||||
|
||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
||||
|
||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||
|
||||
@ -1140,7 +1142,6 @@ if ($step == 5 && $datatoimport)
|
||||
print '<tr><td>';
|
||||
print $langs->trans("NbOfSourceLines");
|
||||
print '</td><td>';
|
||||
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
|
||||
print $nboflines;
|
||||
print '</td></tr>';
|
||||
|
||||
@ -1275,7 +1276,9 @@ if ($step == 6 && $datatoimport)
|
||||
$obj->import_close_file();
|
||||
}
|
||||
|
||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
|
||||
$nboflines=(! empty($_GET["nboflines"])?$_GET["nboflines"]:dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport));
|
||||
|
||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
||||
|
||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||
|
||||
@ -1318,7 +1321,7 @@ if ($step == 6 && $datatoimport)
|
||||
print '</td></tr>';
|
||||
|
||||
// Lot de donnees a importer
|
||||
print '<tr><td width="25%">'.$langs->trans("DatasetToImport").'</td>';
|
||||
print '<tr><td>'.$langs->trans("DatasetToImport").'</td>';
|
||||
print '<td>';
|
||||
print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' ';
|
||||
print $objimport->array_import_label[0];
|
||||
@ -1330,7 +1333,7 @@ if ($step == 6 && $datatoimport)
|
||||
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
|
||||
|
||||
// Source file format
|
||||
print '<tr><td width="40%">'.$langs->trans("SourceFileFormat").'</td>';
|
||||
print '<tr><td width="25%">'.$langs->trans("SourceFileFormat").'</td>';
|
||||
print '<td>';
|
||||
$text=$objmodelimport->getDriverDesc($format);
|
||||
print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text);
|
||||
@ -1350,7 +1353,6 @@ if ($step == 6 && $datatoimport)
|
||||
print '<tr><td>';
|
||||
print $langs->trans("NbOfSourceLines");
|
||||
print '</td><td>';
|
||||
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
|
||||
print $nboflines;
|
||||
print '</td></tr>';
|
||||
|
||||
@ -1367,7 +1369,7 @@ if ($step == 6 && $datatoimport)
|
||||
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnTargetTables").'</b></td></tr>';
|
||||
|
||||
// Tables imported
|
||||
print '<tr><td width="40%">';
|
||||
print '<tr><td width="25%">';
|
||||
print $langs->trans("TablesTarget");
|
||||
print '</td><td>';
|
||||
$listtables=array();
|
||||
@ -1434,11 +1436,13 @@ if ($step == 6 && $datatoimport)
|
||||
$maxnbofwarnings=empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS)?100:$conf->global->IMPORT_MAX_NB_OF_WARNINGS;
|
||||
$nboferrors=0;
|
||||
$nbofwarnings=0;
|
||||
|
||||
|
||||
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S');
|
||||
|
||||
$db->begin();
|
||||
|
||||
//var_dump($array_match_file_to_database);
|
||||
|
||||
|
||||
// Open input file
|
||||
$pathfile=$conf->import->dir_temp.'/'.$filetoimport;
|
||||
$result=$obj->import_open_file($pathfile,$langs);
|
||||
@ -1449,14 +1453,14 @@ if ($step == 6 && $datatoimport)
|
||||
while ($arrayrecord=$obj->import_read_record())
|
||||
{
|
||||
$sourcelinenb++;
|
||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource));
|
||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource),$importid);
|
||||
if (sizeof($obj->errors))
|
||||
{
|
||||
$arrayoferrors[$sourcelinenb]=$obj->errors;
|
||||
$arrayoferrors[$sourcelinenb]=$obj->errors;
|
||||
}
|
||||
if (sizeof($obj->warnings))
|
||||
{
|
||||
$arrayofwarnings[$sourcelinenb]=$obj->warnings;
|
||||
$arrayofwarnings[$sourcelinenb]=$obj->warnings;
|
||||
}
|
||||
}
|
||||
// Close file
|
||||
|
||||
43
htdocs/includes/geoip/README.txt
Normal file
43
htdocs/includes/geoip/README.txt
Normal file
@ -0,0 +1,43 @@
|
||||
Requirements
|
||||
|
||||
None (only the 'GeoIP.dat' file is needed). To download a free GeoIP Standard Country
|
||||
database, go to
|
||||
http://maxmind.com/download/geoip/database/
|
||||
|
||||
Install
|
||||
|
||||
Just place the 'geoip.inc' file somewhere according to the 'include_path' directive of
|
||||
your 'php.ini' file, or just place it in the same directory as your PHP scripts.
|
||||
|
||||
Usage
|
||||
|
||||
Gets country name by hostname :
|
||||
|
||||
include("geoip.inc");
|
||||
|
||||
$gi = geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);
|
||||
|
||||
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
|
||||
geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
|
||||
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
|
||||
geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
|
||||
|
||||
geoip_close($gi);
|
||||
|
||||
Memory Caching:
|
||||
To enable memory caching, pass GEOIP_SHARED_MEMORY or
|
||||
GEOIP_MEMORY_CACHE to the second argument of geoip_open
|
||||
|
||||
For GEOIP_SHARED_MEMORY, requires php >= 4.0.4,
|
||||
and --enable-shmop passed at configure time, see
|
||||
http://us2.php.net/manual/en/ref.shmop.php
|
||||
In addition, you should call geoip_load_shared_mem
|
||||
before calling geoip_open. See sample_city.php for an
|
||||
example of shared memory caching.
|
||||
|
||||
Working with PHP5.
|
||||
geoip_country_code_by_addr should work
|
||||
with PHP. For help with the other
|
||||
routines, please contact support@maxmind.com
|
||||
|
||||
Thanks to Jim Winstead.
|
||||
501
htdocs/includes/geoip/geoip.inc
Normal file
501
htdocs/includes/geoip/geoip.inc
Normal file
@ -0,0 +1,501 @@
|
||||
<?php
|
||||
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* geoip.inc
|
||||
*
|
||||
* Copyright (C) 2007 MaxMind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* 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.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* 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 Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
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,
|
||||
"AZ" => 18, "BA" => 19, "BB" => 20, "BD" => 21, "BE" => 22, "BF" => 23,
|
||||
"BG" => 24, "BH" => 25, "BI" => 26, "BJ" => 27, "BM" => 28, "BN" => 29,
|
||||
"BO" => 30, "BR" => 31, "BS" => 32, "BT" => 33, "BV" => 34, "BW" => 35,
|
||||
"BY" => 36, "BZ" => 37, "CA" => 38, "CC" => 39, "CD" => 40, "CF" => 41,
|
||||
"CG" => 42, "CH" => 43, "CI" => 44, "CK" => 45, "CL" => 46, "CM" => 47,
|
||||
"CN" => 48, "CO" => 49, "CR" => 50, "CU" => 51, "CV" => 52, "CX" => 53,
|
||||
"CY" => 54, "CZ" => 55, "DE" => 56, "DJ" => 57, "DK" => 58, "DM" => 59,
|
||||
"DO" => 60, "DZ" => 61, "EC" => 62, "EE" => 63, "EG" => 64, "EH" => 65,
|
||||
"ER" => 66, "ES" => 67, "ET" => 68, "FI" => 69, "FJ" => 70, "FK" => 71,
|
||||
"FM" => 72, "FO" => 73, "FR" => 74, "FX" => 75, "GA" => 76, "GB" => 77,
|
||||
"GD" => 78, "GE" => 79, "GF" => 80, "GH" => 81, "GI" => 82, "GL" => 83,
|
||||
"GM" => 84, "GN" => 85, "GP" => 86, "GQ" => 87, "GR" => 88, "GS" => 89,
|
||||
"GT" => 90, "GU" => 91, "GW" => 92, "GY" => 93, "HK" => 94, "HM" => 95,
|
||||
"HN" => 96, "HR" => 97, "HT" => 98, "HU" => 99, "ID" => 100, "IE" => 101,
|
||||
"IL" => 102, "IN" => 103, "IO" => 104, "IQ" => 105, "IR" => 106, "IS" => 107,
|
||||
"IT" => 108, "JM" => 109, "JO" => 110, "JP" => 111, "KE" => 112, "KG" => 113,
|
||||
"KH" => 114, "KI" => 115, "KM" => 116, "KN" => 117, "KP" => 118, "KR" => 119,
|
||||
"KW" => 120, "KY" => 121, "KZ" => 122, "LA" => 123, "LB" => 124, "LC" => 125,
|
||||
"LI" => 126, "LK" => 127, "LR" => 128, "LS" => 129, "LT" => 130, "LU" => 131,
|
||||
"LV" => 132, "LY" => 133, "MA" => 134, "MC" => 135, "MD" => 136, "MG" => 137,
|
||||
"MH" => 138, "MK" => 139, "ML" => 140, "MM" => 141, "MN" => 142, "MO" => 143,
|
||||
"MP" => 144, "MQ" => 145, "MR" => 146, "MS" => 147, "MT" => 148, "MU" => 149,
|
||||
"MV" => 150, "MW" => 151, "MX" => 152, "MY" => 153, "MZ" => 154, "NA" => 155,
|
||||
"NC" => 156, "NE" => 157, "NF" => 158, "NG" => 159, "NI" => 160, "NL" => 161,
|
||||
"NO" => 162, "NP" => 163, "NR" => 164, "NU" => 165, "NZ" => 166, "OM" => 167,
|
||||
"PA" => 168, "PE" => 169, "PF" => 170, "PG" => 171, "PH" => 172, "PK" => 173,
|
||||
"PL" => 174, "PM" => 175, "PN" => 176, "PR" => 177, "PS" => 178, "PT" => 179,
|
||||
"PW" => 180, "PY" => 181, "QA" => 182, "RE" => 183, "RO" => 184, "RU" => 185,
|
||||
"RW" => 186, "SA" => 187, "SB" => 188, "SC" => 189, "SD" => 190, "SE" => 191,
|
||||
"SG" => 192, "SH" => 193, "SI" => 194, "SJ" => 195, "SK" => 196, "SL" => 197,
|
||||
"SM" => 198, "SN" => 199, "SO" => 200, "SR" => 201, "ST" => 202, "SV" => 203,
|
||||
"SY" => 204, "SZ" => 205, "TC" => 206, "TD" => 207, "TF" => 208, "TG" => 209,
|
||||
"TH" => 210, "TJ" => 211, "TK" => 212, "TM" => 213, "TN" => 214, "TO" => 215,
|
||||
"TL" => 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, "RS" => 239,
|
||||
"ZA" => 240, "ZM" => 241, "ME" => 242, "ZW" => 243, "A1" => 244, "A2" => 245,
|
||||
"O1" => 246, "AX" => 247, "GG" => 248, "IM" => 249, "JE" => 250, "BL" => 251,
|
||||
"MF" => 252
|
||||
);
|
||||
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",
|
||||
"CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
|
||||
"CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
|
||||
"EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB",
|
||||
"GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT",
|
||||
"GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN",
|
||||
"IO", "IQ", "IR", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
|
||||
"KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS",
|
||||
"LT", "LU", "LV", "LY", "MA", "MC", "MD", "MG", "MH", "MK", "ML", "MM", "MN",
|
||||
"MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA",
|
||||
"NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA",
|
||||
"PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
|
||||
"QA", "RE", "RO", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI",
|
||||
"SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD",
|
||||
"TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TL", "TR", "TT", "TV", "TW",
|
||||
"TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN",
|
||||
"VU", "WF", "WS", "YE", "YT", "RS", "ZA", "ZM", "ME", "ZW", "A1", "A2", "O1",
|
||||
"AX", "GG", "IM", "JE", "BL", "MF"
|
||||
);
|
||||
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",
|
||||
"COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV",
|
||||
"CX","CYP","CZE","DEU","DJI","DNK","DMA","DOM","DZA","ECU","EST","EGY","ESH",
|
||||
"ERI","ESP","ETH","FIN","FJI","FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD",
|
||||
"GEO","GUF","GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","GS","GTM","GUM",
|
||||
"GNB","GUY","HKG","HM","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IO",
|
||||
"IRQ","IRN","ISL","ITA","JAM","JOR","JPN","KEN","KGZ","KHM","KIR","COM","KNA",
|
||||
"PRK","KOR","KWT","CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU",
|
||||
"LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI","MMR","MNG","MAC",
|
||||
"MNP","MTQ","MRT","MSR","MLT","MUS","MDV","MWI","MEX","MYS","MOZ","NAM","NCL",
|
||||
"NER","NFK","NGA","NIC","NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER",
|
||||
"PYF","PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW","PRY","QAT",
|
||||
"REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN","SWE","SGP","SHN","SVN","SJM",
|
||||
"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","SRB","ZAF","ZMB","MNE","ZWE","A1","A2","O1",
|
||||
"ALA","GGY","IMN","JEY","BLM","MAF"
|
||||
);
|
||||
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",
|
||||
"Austria", "Australia", "Aruba", "Azerbaijan", "Bosnia and Herzegovina",
|
||||
"Barbados", "Bangladesh", "Belgium", "Burkina Faso", "Bulgaria", "Bahrain",
|
||||
"Burundi", "Benin", "Bermuda", "Brunei Darussalam", "Bolivia", "Brazil",
|
||||
"Bahamas", "Bhutan", "Bouvet Island", "Botswana", "Belarus", "Belize",
|
||||
"Canada", "Cocos (Keeling) Islands", "Congo, The Democratic Republic of the",
|
||||
"Central African Republic", "Congo", "Switzerland", "Cote D'Ivoire", "Cook Islands",
|
||||
"Chile", "Cameroon", "China", "Colombia", "Costa Rica", "Cuba", "Cape Verde",
|
||||
"Christmas Island", "Cyprus", "Czech Republic", "Germany", "Djibouti",
|
||||
"Denmark", "Dominica", "Dominican Republic", "Algeria", "Ecuador", "Estonia",
|
||||
"Egypt", "Western Sahara", "Eritrea", "Spain", "Ethiopia", "Finland", "Fiji",
|
||||
"Falkland Islands (Malvinas)", "Micronesia, Federated States of", "Faroe Islands",
|
||||
"France", "France, Metropolitan", "Gabon", "United Kingdom",
|
||||
"Grenada", "Georgia", "French Guiana", "Ghana", "Gibraltar", "Greenland",
|
||||
"Gambia", "Guinea", "Guadeloupe", "Equatorial Guinea", "Greece", "South Georgia and the South Sandwich Islands",
|
||||
"Guatemala", "Guam", "Guinea-Bissau",
|
||||
"Guyana", "Hong Kong", "Heard Island and McDonald Islands", "Honduras",
|
||||
"Croatia", "Haiti", "Hungary", "Indonesia", "Ireland", "Israel", "India",
|
||||
"British Indian Ocean Territory", "Iraq", "Iran, Islamic Republic of",
|
||||
"Iceland", "Italy", "Jamaica", "Jordan", "Japan", "Kenya", "Kyrgyzstan",
|
||||
"Cambodia", "Kiribati", "Comoros", "Saint Kitts and Nevis", "Korea, Democratic People's Republic of",
|
||||
"Korea, Republic of", "Kuwait", "Cayman Islands",
|
||||
"Kazakhstan", "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",
|
||||
"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 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",
|
||||
"Somalia", "Suriname", "Sao Tome and Principe", "El Salvador", "Syrian Arab Republic",
|
||||
"Swaziland", "Turks and Caicos Islands", "Chad", "French Southern Territories",
|
||||
"Togo", "Thailand", "Tajikistan", "Tokelau", "Turkmenistan",
|
||||
"Tunisia", "Tonga", "Timor-Leste", "Turkey", "Trinidad and Tobago", "Tuvalu",
|
||||
"Taiwan", "Tanzania, United Republic of", "Ukraine",
|
||||
"Uganda", "United States Minor Outlying Islands", "United States", "Uruguay",
|
||||
"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",
|
||||
"Serbia", "South Africa", "Zambia", "Montenegro", "Zimbabwe",
|
||||
"Anonymous Proxy","Satellite Provider","Other",
|
||||
"Aland Islands","Guernsey","Isle of Man","Jersey","Saint Barthelemy","Saint Martin"
|
||||
);
|
||||
}
|
||||
function geoip_load_shared_mem ($file) {
|
||||
|
||||
$fp = fopen($file, "rb");
|
||||
if (!$fp) {
|
||||
print "error opening $file: $php_errormsg\n";
|
||||
exit;
|
||||
}
|
||||
$s_array = fstat($fp);
|
||||
$size = $s_array['size'];
|
||||
if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) {
|
||||
shmop_delete ($shmid);
|
||||
shmop_close ($shmid);
|
||||
}
|
||||
$shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size);
|
||||
shmop_write ($shmid, fread($fp, $size), 0);
|
||||
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;
|
||||
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
||||
$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));
|
||||
$offset++;
|
||||
|
||||
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)||
|
||||
($gi->databaseType == GEOIP_CITY_EDITION_REV1)
|
||||
|| ($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);
|
||||
for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
|
||||
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
||||
}
|
||||
if (($gi->databaseType == GEOIP_ORG_EDITION)||
|
||||
($gi->databaseType == GEOIP_ISP_EDITION)) {
|
||||
$gi->record_length = ORG_RECORD_LENGTH;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
$offset -= 4;
|
||||
}
|
||||
}
|
||||
if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
|
||||
($gi->databaseType == GEOIP_PROXY_EDITION)||
|
||||
($gi->databaseType == GEOIP_NETSPEED_EDITION)){
|
||||
$gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
} else {
|
||||
$filepos = ftell($gi->filehandle);
|
||||
fseek($gi->filehandle, -3, SEEK_END);
|
||||
for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
|
||||
$delim = fread($gi->filehandle,3);
|
||||
if ($delim == (chr(255).chr(255).chr(255))){
|
||||
$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) ||
|
||||
($gi->databaseType == GEOIP_CITY_EDITION_REV1) ||
|
||||
($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++){
|
||||
$gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
|
||||
}
|
||||
if ($gi->databaseType == GEOIP_ORG_EDITION ||
|
||||
$gi->databaseType == GEOIP_ISP_EDITION) {
|
||||
$gi->record_length = ORG_RECORD_LENGTH;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
fseek($gi->filehandle, -4, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
return $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->filehandle = fopen($filename,"rb") or die( "Can not open $filename\n" );
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
$s_array = fstat($gi->filehandle);
|
||||
$gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
|
||||
}
|
||||
}
|
||||
|
||||
$gi = _setup_segments($gi);
|
||||
return $gi;
|
||||
}
|
||||
|
||||
function geoip_close($gi) {
|
||||
if ($gi->flags & GEOIP_SHARED_MEMORY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return fclose($gi->filehandle);
|
||||
}
|
||||
|
||||
function geoip_country_id_by_name($gi, $name) {
|
||||
$addr = gethostbyname($name);
|
||||
if (!$addr || $addr == $name) {
|
||||
return false;
|
||||
}
|
||||
return geoip_country_id_by_addr($gi, $addr);
|
||||
}
|
||||
|
||||
function geoip_country_code_by_name($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_country_name_by_name($gi, $name) {
|
||||
$country_id = geoip_country_id_by_name($gi,$name);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_country_id_by_addr($gi, $addr) {
|
||||
$ipnum = ip2long($addr);
|
||||
return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
|
||||
}
|
||||
|
||||
function geoip_country_code_by_addr($gi, $addr) {
|
||||
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
||||
$record = geoip_record_by_addr($gi,$addr);
|
||||
if ( $record !== false ) {
|
||||
return $record->country_code;
|
||||
}
|
||||
} else {
|
||||
$country_id = geoip_country_id_by_addr($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_CODES[$country_id];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_country_name_by_addr($gi, $addr) {
|
||||
if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
|
||||
$record = geoip_record_by_addr($gi,$addr);
|
||||
return $record->country_name;
|
||||
} else {
|
||||
$country_id = geoip_country_id_by_addr($gi,$addr);
|
||||
if ($country_id !== false) {
|
||||
return $gi->GEOIP_COUNTRY_NAMES[$country_id];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _geoip_seek_country($gi, $ipnum) {
|
||||
$offset = 0;
|
||||
for ($depth = 31; $depth >= 0; --$depth) {
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
$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,
|
||||
2 * $gi->record_length * $offset,
|
||||
2 * $gi->record_length );
|
||||
} else {
|
||||
fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
|
||||
or die("fseek failed");
|
||||
$buf = fread($gi->filehandle, 2 * $gi->record_length);
|
||||
}
|
||||
$x = array(0,0);
|
||||
for ($i = 0; $i < 2; ++$i) {
|
||||
for ($j = 0; $j < $gi->record_length; ++$j) {
|
||||
$x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
|
||||
}
|
||||
}
|
||||
if ($ipnum & (1 << $depth)) {
|
||||
if ($x[1] >= $gi->databaseSegments) {
|
||||
return $x[1];
|
||||
}
|
||||
$offset = $x[1];
|
||||
} 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;
|
||||
}
|
||||
|
||||
function _get_org($gi,$ipnum){
|
||||
$seek_org = _geoip_seek_country($gi,$ipnum);
|
||||
if ($seek_org == $gi->databaseSegments) {
|
||||
return NULL;
|
||||
}
|
||||
$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 {
|
||||
fseek($gi->filehandle, $record_pointer, SEEK_SET);
|
||||
$org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH);
|
||||
}
|
||||
$org_buf = substr($org_buf, 0, strpos($org_buf, 0));
|
||||
return $org_buf;
|
||||
}
|
||||
|
||||
function geoip_org_by_addr ($gi,$addr) {
|
||||
if ($addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
$ipnum = ip2long($addr);
|
||||
return _get_org($gi, $ipnum);
|
||||
}
|
||||
|
||||
function _get_region($gi,$ipnum){
|
||||
if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
|
||||
$seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0;
|
||||
if ($seek_region >= 1000){
|
||||
$country_code = "US";
|
||||
$region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65);
|
||||
} else {
|
||||
$country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
|
||||
$region = "";
|
||||
}
|
||||
return array ($country_code,$region);
|
||||
} 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) {
|
||||
$country_code = "US";
|
||||
$region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65);
|
||||
} 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 = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
|
||||
$region = "";
|
||||
}
|
||||
return array ($country_code,$region);
|
||||
}
|
||||
}
|
||||
|
||||
function geoip_region_by_addr ($gi,$addr) {
|
||||
if ($addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
$ipnum = ip2long($addr);
|
||||
return _get_region($gi, $ipnum);
|
||||
}
|
||||
|
||||
function getdnsattributes ($l,$ip){
|
||||
$r = new Net_DNS_Resolver();
|
||||
$r->nameservers = array("ws1.maxmind.com");
|
||||
$p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN");
|
||||
$str = is_object($p->answer[0])?$p->answer[0]->string():'';
|
||||
ereg("\"(.*)\"",$str,$regs);
|
||||
$str = $regs[1];
|
||||
return $str;
|
||||
}
|
||||
|
||||
?>
|
||||
208
htdocs/includes/geoip/geoipcity.inc
Normal file
208
htdocs/includes/geoip/geoipcity.inc
Normal file
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/* geoipcity.inc
|
||||
*
|
||||
* Copyright (C) 2004 Maxmind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* 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.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* 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 Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Changelog:
|
||||
*
|
||||
* 2005-01-13 Andrew Hill, Awarez Ltd. (http://www.awarez.net)
|
||||
* Formatted file according to PEAR library standards.
|
||||
* Changed inclusion of geoip.inc file to require_once, so that
|
||||
* this library can be used in the same script as geoip.inc.
|
||||
*/
|
||||
|
||||
define("FULL_RECORD_LENGTH",50);
|
||||
|
||||
require_once 'geoip.inc';
|
||||
require_once 'geoipregionvars.php';
|
||||
|
||||
class geoiprecord {
|
||||
var $country_code;
|
||||
var $country_code3;
|
||||
var $country_name;
|
||||
var $region;
|
||||
var $city;
|
||||
var $postal_code;
|
||||
var $latitude;
|
||||
var $longitude;
|
||||
var $area_code;
|
||||
var $dma_code; # metro and dma code are the same. use metro_code
|
||||
var $metro_code;
|
||||
}
|
||||
|
||||
class geoipdnsrecord {
|
||||
var $country_code;
|
||||
var $country_code3;
|
||||
var $country_name;
|
||||
var $region;
|
||||
var $regionname;
|
||||
var $city;
|
||||
var $postal_code;
|
||||
var $latitude;
|
||||
var $longitude;
|
||||
var $areacode;
|
||||
var $dmacode;
|
||||
var $isp;
|
||||
var $org;
|
||||
var $metrocode;
|
||||
}
|
||||
|
||||
function getrecordwithdnsservice($str){
|
||||
$record = new geoipdnsrecord;
|
||||
$keyvalue = split(";",$str);
|
||||
foreach ($keyvalue as $keyvalue2){
|
||||
list($key,$value) = split("=",$keyvalue2);
|
||||
if ($key == "co"){
|
||||
$record->country_code = $value;
|
||||
}
|
||||
if ($key == "ci"){
|
||||
$record->city = $value;
|
||||
}
|
||||
if ($key == "re"){
|
||||
$record->region = $value;
|
||||
}
|
||||
if ($key == "ac"){
|
||||
$record->areacode = $value;
|
||||
}
|
||||
if ($key == "dm" || $key == "me" ){
|
||||
$record->dmacode = $value;
|
||||
$record->metrocode = $value;
|
||||
}
|
||||
if ($key == "is"){
|
||||
$record->isp = $value;
|
||||
}
|
||||
if ($key == "or"){
|
||||
$record->org = $value;
|
||||
}
|
||||
if ($key == "zi"){
|
||||
$record->postal_code = $value;
|
||||
}
|
||||
if ($key == "la"){
|
||||
$record->latitude = $value;
|
||||
}
|
||||
if ($key == "lo"){
|
||||
$record->longitude = $value;
|
||||
}
|
||||
}
|
||||
$number = $GLOBALS['GEOIP_COUNTRY_CODE_TO_NUMBER'][$record->country_code];
|
||||
$record->country_code3 = $GLOBALS['GEOIP_COUNTRY_CODES3'][$number];
|
||||
$record->country_name = $GLOBALS['GEOIP_COUNTRY_NAMES'][$number];
|
||||
if ($record->region != "") {
|
||||
if (($record->country_code == "US") || ($record->country_code == "CA")){
|
||||
$record->regionname = $GLOBALS['ISO'][$record->country_code][$record->region];
|
||||
} else {
|
||||
$record->regionname = $GLOBALS['FIPS'][$record->country_code][$record->region];
|
||||
}
|
||||
}
|
||||
return $record;
|
||||
}
|
||||
|
||||
function _get_record($gi,$ipnum){
|
||||
$seek_country = _geoip_seek_country($gi,$ipnum);
|
||||
if ($seek_country == $gi->databaseSegments) {
|
||||
return NULL;
|
||||
}
|
||||
$record_pointer = $seek_country + (2 * $gi->record_length - 1) * $gi->databaseSegments;
|
||||
|
||||
if ($gi->flags & GEOIP_MEMORY_CACHE) {
|
||||
$record_buf = substr($gi->memory_buffer,$record_pointer,FULL_RECORD_LENGTH);
|
||||
} elseif ($gi->flags & GEOIP_SHARED_MEMORY){
|
||||
$record_buf = @shmop_read($gi->shmid,$record_pointer,FULL_RECORD_LENGTH);
|
||||
} else {
|
||||
fseek($gi->filehandle, $record_pointer, SEEK_SET);
|
||||
$record_buf = fread($gi->filehandle,FULL_RECORD_LENGTH);
|
||||
}
|
||||
$record = new geoiprecord;
|
||||
$record_buf_pos = 0;
|
||||
$char = ord(substr($record_buf,$record_buf_pos,1));
|
||||
$record->country_code = $gi->GEOIP_COUNTRY_CODES[$char];
|
||||
$record->country_code3 = $gi->GEOIP_COUNTRY_CODES3[$char];
|
||||
$record->country_name = $gi->GEOIP_COUNTRY_NAMES[$char];
|
||||
$record_buf_pos++;
|
||||
$str_length = 0;
|
||||
// Get region
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
while ($char != 0){
|
||||
$str_length++;
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
}
|
||||
if ($str_length > 0){
|
||||
$record->region = substr($record_buf,$record_buf_pos,$str_length);
|
||||
}
|
||||
$record_buf_pos += $str_length + 1;
|
||||
$str_length = 0;
|
||||
// Get city
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
while ($char != 0){
|
||||
$str_length++;
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
}
|
||||
if ($str_length > 0){
|
||||
$record->city = substr($record_buf,$record_buf_pos,$str_length);
|
||||
}
|
||||
$record_buf_pos += $str_length + 1;
|
||||
$str_length = 0;
|
||||
// Get postal code
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
while ($char != 0){
|
||||
$str_length++;
|
||||
$char = ord(substr($record_buf,$record_buf_pos+$str_length,1));
|
||||
}
|
||||
if ($str_length > 0){
|
||||
$record->postal_code = substr($record_buf,$record_buf_pos,$str_length);
|
||||
}
|
||||
$record_buf_pos += $str_length + 1;
|
||||
$str_length = 0;
|
||||
// Get latitude and longitude
|
||||
$latitude = 0;
|
||||
$longitude = 0;
|
||||
for ($j = 0;$j < 3; ++$j){
|
||||
$char = ord(substr($record_buf,$record_buf_pos++,1));
|
||||
$latitude += ($char << ($j * 8));
|
||||
}
|
||||
$record->latitude = ($latitude/10000) - 180;
|
||||
for ($j = 0;$j < 3; ++$j){
|
||||
$char = ord(substr($record_buf,$record_buf_pos++,1));
|
||||
$longitude += ($char << ($j * 8));
|
||||
}
|
||||
$record->longitude = ($longitude/10000) - 180;
|
||||
if (GEOIP_CITY_EDITION_REV1 == $gi->databaseType){
|
||||
$metroarea_combo = 0;
|
||||
if ($record->country_code == "US"){
|
||||
for ($j = 0;$j < 3;++$j){
|
||||
$char = ord(substr($record_buf,$record_buf_pos++,1));
|
||||
$metroarea_combo += ($char << ($j * 8));
|
||||
}
|
||||
$record->metro_code = $record->dma_code = floor($metroarea_combo/1000);
|
||||
$record->area_code = $metroarea_combo%1000;
|
||||
}
|
||||
}
|
||||
return $record;
|
||||
}
|
||||
|
||||
function GeoIP_record_by_addr ($gi,$addr){
|
||||
if ($addr == NULL){
|
||||
return 0;
|
||||
}
|
||||
$ipnum = ip2long($addr);
|
||||
return _get_record($gi, $ipnum);
|
||||
}
|
||||
|
||||
?>
|
||||
4456
htdocs/includes/geoip/geoipregionvars.php
Normal file
4456
htdocs/includes/geoip/geoipregionvars.php
Normal file
File diff suppressed because it is too large
Load Diff
20
htdocs/includes/geoip/sample.php
Normal file
20
htdocs/includes/geoip/sample.php
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
// This code demonstrates how to lookup the country by IP Address
|
||||
|
||||
include("geoip.inc");
|
||||
|
||||
// Uncomment if querying against GeoIP/Lite City.
|
||||
// include("geoipcity.inc");
|
||||
|
||||
$gi = geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);
|
||||
|
||||
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
|
||||
geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
|
||||
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
|
||||
geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
|
||||
|
||||
geoip_close($gi);
|
||||
|
||||
?>
|
||||
32
htdocs/includes/geoip/sample_city.php
Normal file
32
htdocs/includes/geoip/sample_city.php
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
// This code demonstrates how to lookup the country, region, city,
|
||||
// postal code, latitude, and longitude by IP Address.
|
||||
// It is designed to work with GeoIP/GeoLite City
|
||||
|
||||
// Note that you must download the New Format of GeoIP City (GEO-133).
|
||||
// The old format (GEO-132) will not work.
|
||||
|
||||
include("geoipcity.inc");
|
||||
include("geoipregionvars.php");
|
||||
|
||||
// uncomment for Shared Memory support
|
||||
// geoip_load_shared_mem("/usr/local/share/GeoIP/GeoIPCity.dat");
|
||||
// $gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_SHARED_MEMORY);
|
||||
|
||||
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_STANDARD);
|
||||
|
||||
$record = geoip_record_by_addr($gi,"24.24.24.24");
|
||||
print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
|
||||
print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
|
||||
print $record->city . "\n";
|
||||
print $record->postal_code . "\n";
|
||||
print $record->latitude . "\n";
|
||||
print $record->longitude . "\n";
|
||||
print $record->metro_code . "\n";
|
||||
print $record->area_code . "\n";
|
||||
|
||||
geoip_close($gi);
|
||||
|
||||
?>
|
||||
31
htdocs/includes/geoip/sample_distributed.php
Normal file
31
htdocs/includes/geoip/sample_distributed.php
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
include("geoipcity.inc");
|
||||
include("Net/DNS.php");
|
||||
|
||||
# replace LICENSE_KEY_HERE with your license key
|
||||
$l = "LICENSE_KEY_HERE";
|
||||
$ip = "24.24.24.24";
|
||||
|
||||
if ($l == "LICENSE_KEY_HERE") {
|
||||
print "Error, must edit sample_distributed.php to replace LICENSE_KEY_HERE\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$str = getdnsattributes($l,$ip);
|
||||
$r = getrecordwithdnsservice($str);
|
||||
print "country code: " . $r->country_code . "\n";
|
||||
print "country code3: " . $r->country_code3 . "\n";
|
||||
print "country name: " . $r->country_name . "\n";
|
||||
print "city: " . $r->city . "\n";
|
||||
print "region: " . $r->region . "\n";
|
||||
print "region name: " . $r->regionname . "\n";
|
||||
print "postal_code: " . $r->postal_code . "\n";
|
||||
print "latitude: " . $r->latitude . "\n";
|
||||
print "longitude: " . $r->longitude . "\n";
|
||||
print "area code: " . $r->areacode . "\n";
|
||||
print "dma code: " . $r->dmacode . "\n";
|
||||
print "isp: " . $r->isp . "\n";
|
||||
print "org: " . $r->org . "\n";
|
||||
?>
|
||||
23
htdocs/includes/geoip/sample_netspeed.php
Normal file
23
htdocs/includes/geoip/sample_netspeed.php
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
include("geoip.inc");
|
||||
|
||||
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPNetSpeed.dat",GEOIP_STANDARD);
|
||||
|
||||
$netspeed = geoip_country_id_by_addr($gi,"24.24.24.24");
|
||||
|
||||
//print $n . "\n";
|
||||
if ($netspeed == GEOIP_UNKNOWN_SPEED){
|
||||
print "Unknown\n";
|
||||
}else if ($netspeed == GEOIP_DIALUP_SPEED){
|
||||
print "Dailup\n";
|
||||
}else if ($netspeed == GEOIP_CABLEDSL_SPEED){
|
||||
print "Cable/DSL\n";
|
||||
}else if ($netspeed == GEOIP_CORPORATE_SPEED){
|
||||
print "Corporate\n";
|
||||
}
|
||||
|
||||
geoip_close($gi);
|
||||
|
||||
?>
|
||||
23
htdocs/includes/geoip/sample_org.php
Normal file
23
htdocs/includes/geoip/sample_org.php
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
// This code demonstrates how to lookup the country and region by IP Address
|
||||
// It is designed to work with GeoIP Organization or GeoIP ISP available from MaxMind
|
||||
|
||||
include("geoip.inc");
|
||||
|
||||
$giorg = geoip_open("/usr/local/share/GeoIP/GeoIPOrg.dat",GEOIP_STANDARD);
|
||||
|
||||
$org = geoip_org_by_addr($giorg,"80.24.24.24");
|
||||
print "80.24.24.24 belongs to " . $org . "\n";
|
||||
|
||||
$giisp = geoip_open("/usr/local/share/GeoIP/GeoIPISP.dat",GEOIP_STANDARD);
|
||||
|
||||
$isp = geoip_org_by_addr($giisp,"80.24.24.24");
|
||||
print "80.24.24.24 has isp " . $isp . "\n";
|
||||
|
||||
geoip_close($giorg);
|
||||
geoip_close($giisp);
|
||||
|
||||
?>
|
||||
|
||||
20
htdocs/includes/geoip/sample_region.php
Normal file
20
htdocs/includes/geoip/sample_region.php
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
// This code demonstrates how to lookup the country and region by IP Address
|
||||
// It is designed to work with GeoIP Region available from MaxMind
|
||||
|
||||
include("geoip.inc");
|
||||
include("geoipregionvars.php");
|
||||
|
||||
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPRegion.dat",GEOIP_STANDARD);
|
||||
|
||||
list ($countrycode,$region) = geoip_region_by_addr($gi,"24.24.24.24");
|
||||
print $countrycode . " " . $region . " " . $GEOIP_REGION_NAME[$countrycode][$region] . "\n";
|
||||
list ($countrycode,$region) = geoip_region_by_addr($gi,"80.24.24.24");
|
||||
print $countrycode . " " . $region . " " . $GEOIP_REGION_NAME[$countrycode][$region] . "\n";
|
||||
list ($countrycode,$region) = geoip_region_by_addr($gi,"199.243.137.184");
|
||||
print $countrycode . " " . $region . " " . $GEOIP_REGION_NAME[$countrycode][$region] . "\n";
|
||||
geoip_close($gi);
|
||||
|
||||
?>
|
||||
@ -37,7 +37,7 @@ class ImportCsv extends ModeleImports
|
||||
var $id;
|
||||
var $error;
|
||||
var $errors=array();
|
||||
|
||||
|
||||
var $label;
|
||||
var $extension;
|
||||
var $version;
|
||||
@ -220,7 +220,7 @@ class ImportCsv extends ModeleImports
|
||||
{
|
||||
if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset
|
||||
{
|
||||
if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
|
||||
if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
|
||||
{
|
||||
$newarrayres[$key]['val']=$val;
|
||||
$newarrayres[$key]['type']=1;
|
||||
@ -233,12 +233,12 @@ class ImportCsv extends ModeleImports
|
||||
}
|
||||
else // Autodetect format (UTF8 or ISO)
|
||||
{
|
||||
if (utf8_check($val))
|
||||
if (utf8_check($val))
|
||||
{
|
||||
$newarrayres[$key]['val']=$val;
|
||||
$newarrayres[$key]['type']=1;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$newarrayres[$key]['val']=utf8_encode($val);
|
||||
$newarrayres[$key]['type']=1;
|
||||
@ -270,18 +270,17 @@ class ImportCsv extends ModeleImports
|
||||
* @param maxfields Max number of fiels to use
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields)
|
||||
function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid)
|
||||
{
|
||||
$error=0;
|
||||
$warning=0;
|
||||
$this->errors=array();
|
||||
$this->warnings=array();
|
||||
|
||||
dol_syslog("import_csv.modules maxfields=".$maxfields);
|
||||
//print "X".$maxfields;
|
||||
|
||||
var_dump($array_match_file_to_database);
|
||||
var_dump($arrayrecord);
|
||||
|
||||
//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
|
||||
|
||||
//var_dump($array_match_file_to_database);
|
||||
//var_dump($arrayrecord);
|
||||
$sort_array_match_file_to_database=$array_match_file_to_database;
|
||||
ksort($sort_array_match_file_to_database);
|
||||
//var_dump($sort_array_match_file_to_database);
|
||||
@ -290,7 +289,7 @@ class ImportCsv extends ModeleImports
|
||||
(sizeof($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
|
||||
{
|
||||
print 'W';
|
||||
$this->warnings[$warning]['lib']='Empty line';
|
||||
$this->warnings[$warning]['lib']='Empty line';
|
||||
$this->warnings[$warning]['type']='EMPTY';
|
||||
$warning++;
|
||||
}
|
||||
@ -305,6 +304,7 @@ class ImportCsv extends ModeleImports
|
||||
$listvalues='';
|
||||
$i=0;
|
||||
$errorforthistable=0;
|
||||
// Loop on each fields in the match array
|
||||
foreach($sort_array_match_file_to_database as $key => $val)
|
||||
{
|
||||
if ($key <= $maxfields)
|
||||
@ -325,22 +325,23 @@ class ImportCsv extends ModeleImports
|
||||
$newval=$arrayrecord[($key-1)]['val'];
|
||||
$listvalues.="'".$arrayrecord[($key-1)]['val']."'";
|
||||
}
|
||||
|
||||
|
||||
// Make some tests
|
||||
|
||||
|
||||
// Required field is ok
|
||||
if (eregi('\*',$objimport->array_import_fields[0][$val]) && empty($newval))
|
||||
{
|
||||
$this->errors[$error]['lib']='ErrorMissingMandatoryValue field nb '.$key.' target='.$val;
|
||||
$this->errors[$error]['lib']='ErrorMissingMandatoryValue field nb '.$key.' target='.$val;
|
||||
$this->errors[$error]['type']='NOTNULL';
|
||||
$errorforthistable++;
|
||||
$error++;
|
||||
}
|
||||
// Test format
|
||||
|
||||
// TODO
|
||||
|
||||
// Other tests
|
||||
// ...
|
||||
|
||||
// TODO...
|
||||
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@ -350,11 +351,11 @@ class ImportCsv extends ModeleImports
|
||||
{
|
||||
$sql='INSERT INTO '.$tablename.'('.$listfields.') VALUES('.$listvalues.')';
|
||||
dol_syslog("import_csv.modules sql=".$sql);
|
||||
|
||||
|
||||
//print '> '.join(',',$arrayrecord);
|
||||
//print 'sql='.$sql;
|
||||
//print '<br>'."\n";
|
||||
|
||||
|
||||
// Run insert request
|
||||
if ($sql)
|
||||
{
|
||||
@ -366,7 +367,7 @@ class ImportCsv extends ModeleImports
|
||||
else
|
||||
{
|
||||
print 'E';
|
||||
$this->errors[$error]['lib']='ErrorSQL '.$this->db->lasterror();
|
||||
$this->errors[$error]['lib']='ErrorSQL '.$this->db->lasterror();
|
||||
$this->errors[$error]['type']='SQL';
|
||||
$error++;
|
||||
}
|
||||
@ -379,7 +380,7 @@ class ImportCsv extends ModeleImports
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -19,14 +19,14 @@
|
||||
|
||||
/**
|
||||
* \file htdocs/lib/doleditor.class.php
|
||||
* \brief Classe permettant de gérer FCKEditor
|
||||
* \brief Classe permettant de g<EFBFBD>rer FCKEditor
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* \class DolEditor
|
||||
* \brief Classe de gestion de FCKEditor
|
||||
* \remarks Usage:
|
||||
* \class DolEditor
|
||||
* \brief Classe de gestion de FCKEditor
|
||||
* \remarks Usage:
|
||||
* \remarks $doleditor=new DolEditor('body',$message,320,'toolbar_mailing');
|
||||
* \remarks $doleditor->Create();
|
||||
*/
|
||||
@ -38,13 +38,13 @@ class DolEditor
|
||||
/**
|
||||
\brief DolEditor
|
||||
\param htmlname Nom formulaire html WYSIWIG
|
||||
\param content Contenu édition WYSIWIG
|
||||
\param height Hauteur en pixel de la zone édition
|
||||
\param toolbarname Nom barre de menu éditeur
|
||||
\param content Contenu <EFBFBD>dition WYSIWIG
|
||||
\param height Hauteur en pixel de la zone <EFBFBD>dition
|
||||
\param toolbarname Nom barre de menu <EFBFBD>diteur
|
||||
\param toolbarlocation Emplacement de la barre de menu :
|
||||
'In' chaque fenêtre d'édition a ça propre barre d'outils
|
||||
'Out:nom' partage de la barre d'outils où 'nom' est le nom du DIV qui affiche la barre
|
||||
\param toolbarstartexpanded visible ou non au démarrage
|
||||
'In' chaque fen<EFBFBD>tre d'<27>dition a <20>a propre barre d'outils
|
||||
'Out:nom' partage de la barre d'outils o<EFBFBD> 'nom' est le nom du DIV qui affiche la barre
|
||||
\param toolbarstartexpanded visible ou non au d<EFBFBD>marrage
|
||||
\param modulepart modulepart pour protection wrapper download viewimage
|
||||
*/
|
||||
function DolEditor($htmlname,$content,$height=200,$toolbarname='Basic',$toolbarlocation='In',$toolbarstartexpanded=false,$uselocalbrowser=true)
|
||||
|
||||
100
htdocs/lib/dolgeoip.class.php
Normal file
100
htdocs/lib/dolgeoip.class.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/lib/dolgeoip.class.php
|
||||
* \ingroup geoip
|
||||
* \brief Library for managing module geoip
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \class DolGeoIp
|
||||
* \brief Classe to manage GeoIP
|
||||
* \remarks Usage:
|
||||
* \remarks $geoip=new GeoIP('country',$datfile);
|
||||
* \remarks $geoip->getCountryCodeFromIP($ip);
|
||||
* \remarks $geoip->close();
|
||||
*/
|
||||
class DolGeoIP
|
||||
{
|
||||
var $gi;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $type 'country' or 'city'
|
||||
* @param $datfile Data file
|
||||
* @return GeoIP
|
||||
*/
|
||||
function DolGeoIP($type,$datfile)
|
||||
{
|
||||
if ($type == 'country') require_once(DOL_DOCUMENT_ROOT."/includes/geoip/geoip.inc");
|
||||
else if ($type == 'city') require_once(DOL_DOCUMENT_ROOT."/includes/geoip/geoipcity.inc");
|
||||
else { print 'ErrorBadParameterInConstructor'; return 0; }
|
||||
|
||||
if (empty($type) || empty($datfile))
|
||||
{
|
||||
dol_syslog("DolGeoIP::DolGeoIP parameter datafile not defined", LOG_ERR);
|
||||
dol_print_error('DolGeoIP constructor was called with no datafile parameter');
|
||||
return 0;
|
||||
}
|
||||
if (! file_exists($datfile))
|
||||
{
|
||||
dol_syslog("DolGeoIP::DolGeoIP datafile ".$datfile." can not be read", LOG_ERR);
|
||||
$this->error='ErrorGeoIPClassNotInitialized';
|
||||
$this->errorlabel="Datafile ".$datfile." not found";
|
||||
print $this->errorlabel;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->gi = geoip_open($datfile,GEOIP_STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return in lower cas the country code
|
||||
* @param $ip IP to scan
|
||||
* @return string Country code (two letters)
|
||||
*/
|
||||
function getCountryCodeFromIP($ip)
|
||||
{
|
||||
if (empty($this->gi))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return strtolower(geoip_country_code_by_addr($this->gi, $ip));
|
||||
}
|
||||
|
||||
function getCountryCodeFromName($ip)
|
||||
{
|
||||
if (empty($this->gi))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return geoip_country_code_by_name($this->gi, $ip);
|
||||
}
|
||||
|
||||
function close()
|
||||
{
|
||||
geoip_close($this->gi);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -256,7 +256,7 @@ function dol_count_nb_of_line($file)
|
||||
function dol_filesize($pathoffile)
|
||||
{
|
||||
$newpathoffile=utf8_check($pathoffile)?utf8_decode($pathoffile):$pathoffile;
|
||||
return filesize($pathoffile);
|
||||
return filesize($newpathoffile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user