From 2bf6b3a82e642168314c881b9b7755d011185a04 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Thu, 13 Dec 2012 13:35:17 +0100 Subject: [PATCH 001/802] // Cleaned modules call --- .../template/controllers/modules/js.tpl | 27 --------- classes/controller/AdminController.php | 24 ++++++-- controllers/admin/AdminModulesController.php | 56 +------------------ 3 files changed, 20 insertions(+), 87 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/modules/js.tpl b/admin-dev/themes/default/template/controllers/modules/js.tpl index e3d073c01..ac370fd49 100644 --- a/admin-dev/themes/default/template/controllers/modules/js.tpl +++ b/admin-dev/themes/default/template/controllers/modules/js.tpl @@ -66,10 +66,6 @@ if (anchor != '') $.scrollTo('#'+anchor, 1200, {offset: -100}); - // If a list of modules is set, install request has been called - if (installed_modules !== false) - wsModuleCall(installed_modules); - // AutoComplete Search $('input[name="filtername"]').autocomplete(moduleList, { minChars: 0, @@ -340,28 +336,5 @@ }); }); - function wsModuleCall(modules_list) - { - $.ajax({ - type : 'POST', - url : ajaxCurrentIndex, - data : { - 'modules_list' : modules_list, - 'controller' : 'AdminModules', - 'action' : 'wsModuleCall', - 'token' : token - }, - dataType: 'json', - success: function(json) - { - //console.log(json); - }, - error: function(xhr, ajaxOptions, thrownError) - { - //jAlert("TECHNICAL ERROR"+xhr); - } - }); - } - {/literal} \ No newline at end of file diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 650aa0648..8721f794c 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -2733,30 +2733,42 @@ class AdminControllerCore extends Controller public function addonsRequest($request, $params = array()) { + $postData = ''; + $postDataArray = array( + 'version' => _PS_VERSION_, + 'iso_lang' => strtolower(Context::getContext()->language->iso_code), + 'iso_code' => strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))), + 'shop_url' => urlencode(Tools::getShopDomain()), + 'mail' => urlencode(Configuration::get('PS_SHOP_EMAIL')) + ); + foreach ($postDataArray as $postDataKey => $postDataValue) + $postData .= '&'.$postDataKey.'='.$postDataValue; + $postData = ltrim($postData, '&'); + // Config for each request if ($request == 'native') { // Define protocol accepted and post data values for this request $protocolsList = array('https://' => 443, 'http://' => 80); - $postData = 'version='._PS_VERSION_.'&method=listing&action=native&iso_code='.strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))).'&iso_lang='.strtolower(Context::getContext()->language->iso_code); + $postData .= '&method=listing&action=native'; } if ($request == 'must-have') { // Define protocol accepted and post data values for this request $protocolsList = array('https://' => 443, 'http://' => 80); - $postData = 'version='._PS_VERSION_.'&method=listing&action=must-have&iso_code='.strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))).'&iso_lang='.strtolower(Context::getContext()->language->iso_code); + $postData .= '&method=listing&action=must-have'; } if ($request == 'customer') { // Define protocol accepted and post data values for this request $protocolsList = array('https://' => 443); - $postData = 'version='._PS_VERSION_.'&method=listing&action=customer&username='.pSQL(trim($this->context->cookie->username_addons)).'&password='.pSQL(trim($this->context->cookie->password_addons)).'&iso_lang='.strtolower(Context::getContext()->language->iso_code); + $postData .= '&method=listing&action=customer&username='.urlencode(trim($this->context->cookie->username_addons)).'&password='.urlencode(trim($this->context->cookie->password_addons)); } if ($request == 'check_customer') { // Define protocol accepted and post data values for this request $protocolsList = array('https://' => 443); - $postData = 'version='._PS_VERSION_.'&method=check_customer&username='.pSQL($params['username_addons']).'&password='.pSQL($params['password_addons']); + $postData .= '&method=check_customer&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']); } if ($request == 'module') { @@ -2764,12 +2776,12 @@ class AdminControllerCore extends Controller if (isset($params['username_addons']) && isset($params['password_addons'])) { $protocolsList = array('https://' => 443); - $postData = 'version='._PS_VERSION_.'&method=module&id_module='.pSQL($params['id_module']).'&username='.pSQL($params['username_addons']).'&password='.pSQL($params['password_addons']); + $postData .= '&method=module&id_module='.urlencode($params['id_module']).'&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']); } else { $protocolsList = array('https://' => 443, 'http://' => 80); - $postData = 'version='._PS_VERSION_.'&method=module&id_module='.pSQL($params['id_module']); + $postData .= '&method=module&id_module='.urlencode($params['id_module']); } } diff --git a/controllers/admin/AdminModulesController.php b/controllers/admin/AdminModulesController.php index c06f15944..bfa960926 100644 --- a/controllers/admin/AdminModulesController.php +++ b/controllers/admin/AdminModulesController.php @@ -262,66 +262,13 @@ class AdminModulesControllerCore extends AdminController } die('OK'); } - - - private function sendStatisticRequest($object_key) - { - $post_data = http_build_query(array( - 'key' => urlencode($object_key), - 'url' => urlencode(Tools::getShopDomain()), - 'mail' => urlencode(Configuration::get('PS_SHOP_EMAIL')), - 'version' => urlencode(_PS_VERSION_), - 'method' => 'product_key' - )); - - $opts = array( - 'http' => array( - 'method' => 'POST', - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'content' => $post_data - ) - ); - - $context = stream_context_create($opts); - file_get_contents('http://api.addons.prestashop.com/', false, $context); - } - - /** - * Ajax call for statistic - * - * @result : die the request - */ - public function ajaxProcessWsModuleCall() - { - if (($list = Tools::getValue('modules_list')) && is_array($list)) - foreach ($list as $id) - if (($obj = Module::getInstanceById($id)) && (isset($obj->module_key))) - $this->sendStatisticRequest($obj->module_key); - die(); - } - - /** - * Ajax call for statistic - * - * @result : die the request - */ - public function ajaxProcessWsThemeCall() - { - // Theme list contains just the key for each theme - if (($list = Tools::getValue('theme_list')) && is_array($list)) - foreach ($list as $theme_key) - if (!empty($theme_key)) - $this->sendStatisticRequest($theme_key); - die(); - } - + /* ** Get current URL ** ** @param array $remove List of keys to remove from URL ** @return string */ - protected function getCurrentUrl($remove = array()) { $url = $_SERVER['REQUEST_URI']; @@ -605,6 +552,7 @@ class AdminModulesControllerCore extends AdminController } } + // Check potential error if (!($module = Module::getInstanceByName(urldecode($name)))) $this->errors[] = $this->l('module not found'); From 630b41ec717021caf191fcb806e2f8f77a17ba50 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 10:13:28 +0100 Subject: [PATCH 002/802] [-] BO : added check on a key in the helper list #PSCFV-6137 --- .../template/helpers/list/list_content.tpl | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/admin-dev/themes/default/template/helpers/list/list_content.tpl b/admin-dev/themes/default/template/helpers/list/list_content.tpl index c7555753d..e9367f842 100644 --- a/admin-dev/themes/default/template/helpers/list/list_content.tpl +++ b/admin-dev/themes/default/template/helpers/list/list_content.tpl @@ -61,49 +61,48 @@ {if isset($params.color) && isset($tr[$params.color])} {/if} + {if isset($tr.$key)} + {if isset($params.active)} + {$tr.$key} + {elseif isset($params.activeVisu)} + {if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if} + {elseif isset($params.position)} + {if $order_by == 'position' && $order_way != 'DESC'} + + {l s='Down'} + - {if isset($params.active)} - {$tr.$key} - {elseif isset($params.activeVisu)} - {if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if} - {elseif isset($params.position)} - {if $order_by == 'position' && $order_way != 'DESC'} - - {l s='Down'} - - - - {l s='Up'} - - {else} - {$tr.$key.position + 1} - {/if} - {elseif isset($params.image)} - {$tr.$key} - {elseif isset($params.icon)} - {$tr[$key]['alt']} - {elseif isset($params.price)} - {$tr.$key} - {elseif isset($params.float)} - {$tr.$key} - {elseif isset($params.type) && $params.type == 'date'} - {$tr.$key} - {elseif isset($params.type) && $params.type == 'datetime'} - {$tr.$key} - {elseif isset($params.type) && $params.type == 'decimal'} - {$tr.$key|string_format:"%.2f"} - {elseif isset($params.type) && $params.type == 'percent'} - {$tr.$key} {l s='%'} - {* If type is 'editable', an input is created *} - {elseif isset($params.type) && $params.type == 'editable' && isset($tr.id)} - - {elseif isset($params.callback)} - {$tr.$key} - {elseif isset($tr.$key) && $key == 'color'} -
- {elseif isset($tr.$key)} - {if isset($params.maxlength) && Tools::strlen($tr.$key) > $params.maxlength} + + {l s='Up'} + + {else} + {$tr.$key.position + 1} + {/if} + {elseif isset($params.image)} + {$tr.$key} + {elseif isset($params.icon)} + {$tr[$key]['alt']} + {elseif isset($params.price)} + {$tr.$key} + {elseif isset($params.float)} + {$tr.$key} + {elseif isset($params.type) && $params.type == 'date'} + {$tr.$key} + {elseif isset($params.type) && $params.type == 'datetime'} + {$tr.$key} + {elseif isset($params.type) && $params.type == 'decimal'} + {$tr.$key|string_format:"%.2f"} + {elseif isset($params.type) && $params.type == 'percent'} + {$tr.$key} {l s='%'} + {* If type is 'editable', an input is created *} + {elseif isset($params.type) && $params.type == 'editable' && isset($tr.id)} + + {elseif isset($params.callback)} + {$tr.$key} + {elseif $key == 'color'} +
+ {elseif isset($params.maxlength) && Tools::strlen($tr.$key) > $params.maxlength} {$tr.$key|truncate:$params.maxlength:'...'|escape:'htmlall':'UTF-8'} {else} {$tr.$key|escape:'htmlall':'UTF-8'} From 3c2ae9efa7e90f433521a8065e79c5241585cd1f Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 10:30:13 +0100 Subject: [PATCH 003/802] [-] FO : fixed default order by manufacturer #PSCFV-6105 --- classes/Manufacturer.php | 7 ++++++- classes/Supplier.php | 6 ++++++ controllers/front/ManufacturerController.php | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/classes/Manufacturer.php b/classes/Manufacturer.php index 5a688a0c6..93f8c4741 100644 --- a/classes/Manufacturer.php +++ b/classes/Manufacturer.php @@ -316,6 +316,11 @@ class ManufacturerCore extends ObjectModel $alias = 'product_shop.'; elseif ($order_by == 'name') $alias = 'pl.'; + elseif ($order_by == 'manufacturer_name') + { + $order_by = 'name'; + $alias = 'm.'; + } elseif ($order_by == 'quantity') $alias = 'stock.'; else @@ -358,7 +363,7 @@ class ManufacturerCore extends ObjectModel WHERE cg.`id_group` '.$sql_groups.' ) AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) - ORDER BY '.$alias.pSQL($order_by).' '.pSQL($order_way).' + ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); diff --git a/classes/Supplier.php b/classes/Supplier.php index 466c911e4..8c0fe7e1c 100644 --- a/classes/Supplier.php +++ b/classes/Supplier.php @@ -243,6 +243,12 @@ class SupplierCore extends ObjectModel $alias = 'product_shop.'; elseif ($order_by == 'id_product') $alias = 'p.'; + elseif ($order_by == 'manufacturer_name') + { + $order_by = 'name'; + $alias = 'm.'; + } + $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, diff --git a/controllers/front/ManufacturerController.php b/controllers/front/ManufacturerController.php index 494356a89..2511c9fc5 100644 --- a/controllers/front/ManufacturerController.php +++ b/controllers/front/ManufacturerController.php @@ -99,8 +99,8 @@ class ManufacturerControllerCore extends FrontController 'products' => $this->manufacturer->getProducts($this->manufacturer->id, $this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), 'path' => ($this->manufacturer->active ? Tools::safeOutput($this->manufacturer->name) : ''), 'manufacturer' => $this->manufacturer, - 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')) - ); + 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM') + )); } /** From c3c29e3abde3502f46527c071a8a528bd978f2b1 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 14:28:33 +0100 Subject: [PATCH 004/802] [-] Core : cannot throw an exception in the autoload #PSCFV-6018 --- classes/Autoload.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/Autoload.php b/classes/Autoload.php index 4b6e74ac6..8464f3bff 100644 --- a/classes/Autoload.php +++ b/classes/Autoload.php @@ -129,7 +129,10 @@ class Autoload // Write classes index on disc to cache it $filename = $this->root_dir.Autoload::INDEX_FILE; if ((file_exists($filename) && !is_writable($filename)) || !is_writable(dirname($filename))) - throw new PrestaShopException($filename.' is not writable, please give write permissions (chmod 666) on this file.'); + { + header('HTTP/1.1 503 temporarily overloaded'); + die('/cache/class_index.php is not writable, please give write permissions (chmod 666) on this file.'); + } else { // Let's write index content in cache file From 1abfedbf5e7cea6b55b4c2c78358407299cad67a Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 14:53:14 +0100 Subject: [PATCH 005/802] // Fixed confirmation message display in some modules --- modules/blockcontact/blockcontact.php | 2 +- modules/blockcontactinfos/blockcontactinfos.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/blockcontact/blockcontact.php b/modules/blockcontact/blockcontact.php index ac8f6418f..da33315e8 100644 --- a/modules/blockcontact/blockcontact.php +++ b/modules/blockcontact/blockcontact.php @@ -64,7 +64,7 @@ class Blockcontact extends Module { Configuration::updateValue('blockcontact_telnumber', Tools::getValue('telnumber')); Configuration::updateValue('blockcontact_email', Tools::getValue('email')); - $html .= '
'.$this->l('Configuration updated').'
'; + $html .= '
'.$this->l('Configuration updated').'
'; } $html .= ' diff --git a/modules/blockcontactinfos/blockcontactinfos.php b/modules/blockcontactinfos/blockcontactinfos.php index c190ed355..90b0734e7 100644 --- a/modules/blockcontactinfos/blockcontactinfos.php +++ b/modules/blockcontactinfos/blockcontactinfos.php @@ -72,7 +72,7 @@ class Blockcontactinfos extends Module Configuration::updateValue('blockcontactinfos_phone', ((isset($_POST['phone']) && $_POST['phone'] != '') ? $_POST['phone'] : '')); Configuration::updateValue('blockcontactinfos_email', ((isset($_POST['email']) && $_POST['email'] != '') ? $_POST['email'] : Configuration::get('PS_SHOP_EMAIL'))); - $html .= '
'.$this->l('Configuration updated').'
'; + $html .= '
'.$this->l('Configuration updated').'
'; } $html .= ' From 2b06e54e78ce2546afe2a862101b36c58268a0bd Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 14:58:35 +0100 Subject: [PATCH 006/802] [-] MO : fixed override deployment from module #PSCFV-5999 --- classes/module/Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/module/Module.php b/classes/module/Module.php index c1090d82c..c96ef30fb 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -1891,7 +1891,7 @@ abstract class ModuleCore // Check if override file is writable $override_path = _PS_ROOT_DIR_.'/'.Autoload::getInstance()->getClassPath($classname); - if (!is_writable($override_path)) + if ((!file_exists($override_path) && !is_writable(dirname($override_path))) || (file_exists($override_path) && !is_writable($override_path))) throw new Exception(sprintf(Tools::displayError('file (%s) not writable'), $override_path)); // Make a reflection of the override class and the module override class From 3fd4fd6f707c78b2c2a45fada553ddd37bdc8b1e Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 15:29:35 +0100 Subject: [PATCH 007/802] [-] Core : maxmind geoip API was outdated #PSCFV-5941 --- tools/geoip/geoip.inc | 1247 ++++++++++++++++++------------- tools/geoip/geoipcity.inc | 30 +- tools/geoip/geoipregionvars.php | 55 +- 3 files changed, 768 insertions(+), 564 deletions(-) diff --git a/tools/geoip/geoip.inc b/tools/geoip/geoip.inc index f04686374..d2aea2e09 100755 --- a/tools/geoip/geoip.inc +++ b/tools/geoip/geoip.inc @@ -19,85 +19,107 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* PrestaShop - Test if functions and defines are already defined - END -*/ -if (!defined('GEOIP_COUNTRY_BEGIN')) + /* + * Hack PrestaShop because some users may use mod_geoip with this lib and it will cause a crash + */ + +if (!defined("GEOIP_COUNTRY_BEGIN")) define("GEOIP_COUNTRY_BEGIN", 16776960); -if (!defined('GEOIP_STATE_BEGIN_REV0')) +if (!defined("GEOIP_STATE_BEGIN_REV0")) define("GEOIP_STATE_BEGIN_REV0", 16700000); -if (!defined('GEOIP_STATE_BEGIN_REV1')) +if (!defined("GEOIP_STATE_BEGIN_REV1")) define("GEOIP_STATE_BEGIN_REV1", 16000000); -if (!defined('GEOIP_STANDARD')) +if (!defined("GEOIP_STANDARD")) define("GEOIP_STANDARD", 0); -if (!defined('GEOIP_MEMORY_CACHE')) +if (!defined("GEOIP_MEMORY_CACHE")) define("GEOIP_MEMORY_CACHE", 1); -if (!defined('GEOIP_SHARED_MEMORY')) +if (!defined("GEOIP_SHARED_MEMORY")) define("GEOIP_SHARED_MEMORY", 2); -if (!defined('STRUCTURE_INFO_MAX_SIZE')) +if (!defined("STRUCTURE_INFO_MAX_SIZE")) define("STRUCTURE_INFO_MAX_SIZE", 20); -if (!defined('DATABASE_INFO_MAX_SIZE')) +if (!defined("DATABASE_INFO_MAX_SIZE")) define("DATABASE_INFO_MAX_SIZE", 100); -if (!defined('GEOIP_COUNTRY_EDITION')) +if (!defined("GEOIP_COUNTRY_EDITION")) define("GEOIP_COUNTRY_EDITION", 106); -if (!defined('GEOIP_PROXY_EDITION')) +if (!defined("GEOIP_PROXY_EDITION")) define("GEOIP_PROXY_EDITION", 8); -if (!defined('GEOIP_ASNUM_EDITION')) +if (!defined("GEOIP_ASNUM_EDITION")) define("GEOIP_ASNUM_EDITION", 9); -if (!defined('GEOIP_NETSPEED_EDITION')) +if (!defined("GEOIP_NETSPEED_EDITION")) define("GEOIP_NETSPEED_EDITION", 10); -if (!defined('GEOIP_REGION_EDITION_REV0')) +if (!defined("GEOIP_REGION_EDITION_REV0")) define("GEOIP_REGION_EDITION_REV0", 112); -if (!defined('GEOIP_REGION_EDITION_REV1')) +if (!defined("GEOIP_REGION_EDITION_REV1")) define("GEOIP_REGION_EDITION_REV1", 3); -if (!defined('GEOIP_CITY_EDITION_REV0')) +if (!defined("GEOIP_CITY_EDITION_REV0")) define("GEOIP_CITY_EDITION_REV0", 111); -if (!defined('GEOIP_CITY_EDITION_REV1')) +if (!defined("GEOIP_CITY_EDITION_REV1")) define("GEOIP_CITY_EDITION_REV1", 2); -if (!defined('GEOIP_ORG_EDITION')) +if (!defined("GEOIP_ORG_EDITION")) define("GEOIP_ORG_EDITION", 110); -if (!defined('GEOIP_ISP_EDITION')) +if (!defined("GEOIP_ISP_EDITION")) define("GEOIP_ISP_EDITION", 4); -if (!defined('SEGMENT_RECORD_LENGTH')) +if (!defined("SEGMENT_RECORD_LENGTH")) define("SEGMENT_RECORD_LENGTH", 3); -if (!defined('STANDARD_RECORD_LENGTH')) +if (!defined("STANDARD_RECORD_LENGTH")) define("STANDARD_RECORD_LENGTH", 3); -if (!defined('ORG_RECORD_LENGTH')) +if (!defined("ORG_RECORD_LENGTH")) define("ORG_RECORD_LENGTH", 4); -if (!defined('MAX_RECORD_LENGTH')) +if (!defined("MAX_RECORD_LENGTH")) define("MAX_RECORD_LENGTH", 4); -if (!defined('MAX_ORG_RECORD_LENGTH')) +if (!defined("MAX_ORG_RECORD_LENGTH")) define("MAX_ORG_RECORD_LENGTH", 300); -if (!defined('GEOIP_SHM_KEY')) +if (!defined("GEOIP_SHM_KEY")) define("GEOIP_SHM_KEY", 0x4f415401); -if (!defined('US_OFFSET')) +if (!defined("US_OFFSET")) define("US_OFFSET", 1); -if (!defined('CANADA_OFFSET')) +if (!defined("CANADA_OFFSET")) define("CANADA_OFFSET", 677); -if (!defined('WORLD_OFFSET')) +if (!defined("WORLD_OFFSET")) define("WORLD_OFFSET", 1353); -if (!defined('FIPS_RANGE')) +if (!defined("FIPS_RANGE")) define("FIPS_RANGE", 360); -if (!defined('GEOIP_UNKNOWN_SPEED')) +if (!defined("GEOIP_UNKNOWN_SPEED")) define("GEOIP_UNKNOWN_SPEED", 0); -if (!defined('GEOIP_DIALUP_SPEED')) +if (!defined("GEOIP_DIALUP_SPEED")) define("GEOIP_DIALUP_SPEED", 1); -if (!defined('GEOIP_CABLEDSL_SPEED')) +if (!defined("GEOIP_CABLEDSL_SPEED")) define("GEOIP_CABLEDSL_SPEED", 2); -if (!defined('GEOIP_CORPORATE_SPEED')) +if (!defined("GEOIP_CORPORATE_SPEED")) define("GEOIP_CORPORATE_SPEED", 3); -if (!defined('GEOIP_DOMAIN_EDITION')) +if (!defined("GEOIP_DOMAIN_EDITION")) define("GEOIP_DOMAIN_EDITION", 11); -if (!defined('GEOIP_LOCATIONA_EDITION')) +if (!defined("GEOIP_COUNTRY_EDITION_V6")) + define("GEOIP_COUNTRY_EDITION_V6", 12); +if (!defined("GEOIP_LOCATIONA_EDITION")) define("GEOIP_LOCATIONA_EDITION", 13); -if (!defined('GEOIP_ACCURACYRADIUS_EDITION')) +if (!defined("GEOIP_ACCURACYRADIUS_EDITION")) define("GEOIP_ACCURACYRADIUS_EDITION", 14); -if (!defined('GEOIP_CITYCOMBINED_EDITION')) +if (!defined("GEOIP_CITYCOMBINED_EDITION")) define("GEOIP_CITYCOMBINED_EDITION", 15); -if (!defined('CITYCOMBINED_FIXED_RECORD')) +if (!defined("GEOIP_CITY_EDITION_REV1_V6")) + define("GEOIP_CITY_EDITION_REV1_V6", 30); +if (!defined("GEOIP_CITY_EDITION_REV0_V6")) + define("GEOIP_CITY_EDITION_REV0_V6",31); +if (!defined("GEOIP_NETSPEED_EDITION_REV1")) + define("GEOIP_NETSPEED_EDITION_REV1",32); +if (!defined("GEOIP_NETSPEED_EDITION_REV1_V6")) + define("GEOIP_NETSPEED_EDITION_REV1_V6",33); +if (!defined("GEOIP_USERTYPE_EDITION")) + define("GEOIP_USERTYPE_EDITION",28); +if (!defined("GEOIP_USERTYPE_EDITION_V6")) + define("GEOIP_USERTYPE_EDITION_V6",29); +if (!defined("GEOIP_ASNUM_EDITION_V6")) + define("GEOIP_ASNUM_EDITION_V6",21); +if (!defined("GEOIP_ISP_EDITION_V6")) + define("GEOIP_ISP_EDITION_V6",22); +if (!defined("GEOIP_ORG_EDITION_V6")) + define("GEOIP_ORG_EDITION_V6",23); +if (!defined("GEOIP_DOMAIN_EDITION_V6")) + define("GEOIP_DOMAIN_EDITION_V6",24); + +if (!defined("CITYCOMBINED_FIXED_RECORD")) define("CITYCOMBINED_FIXED_RECORD", 7 ); class GeoIP { @@ -109,529 +131,690 @@ class GeoIP { 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, +"" => 0, "AP" => 1, "EU" => 2, "AD" => 3, "AE" => 4, "AF" => 5, +"AG" => 6, "AI" => 7, "AL" => 8, "AM" => 9, "CW" => 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, "SX" => 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, +"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, +"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 +"MF" => 252, "BQ" => 253, ); 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" -); + "","AP","EU","AD","AE","AF","AG","AI","AL","AM","CW", + "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","SX","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", "BQ"); var $GEOIP_COUNTRY_CODES3 = array( -"","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","ATA","ARG", -"ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI", -"BEN","BMU","BRN","BOL","BRA","BHS","BTN","BVT","BWA","BLR","BLZ","CAN","CCK", -"COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV", -"CXR","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","SGS","GTM","GUM", -"GNB","GUY","HKG","HMD","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IOT", -"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","ATF", -"TGO","THA","TJK","TKL","TLS","TKM","TUN","TON","TUR","TTO","TUV","TWN","TZA", -"UKR","UGA","UMI","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT", -"WLF","WSM","YEM","MYT","SRB","ZAF","ZMB","MNE","ZWE","A1","A2","O1", -"ALA","GGY","IMN","JEY","BLM","MAF" - ); + "","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","CUW", + "AGO","ATA","ARG","ASM","AUT","AUS","ABW","AZE","BIH","BRB", + "BGD","BEL","BFA","BGR","BHR","BDI","BEN","BMU","BRN","BOL", + "BRA","BHS","BTN","BVT","BWA","BLR","BLZ","CAN","CCK","COD", + "CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI", + "CUB","CPV","CXR","CYP","CZE","DEU","DJI","DNK","DMA","DOM", + "DZA","ECU","EST","EGY","ESH","ERI","ESP","ETH","FIN","FJI", + "FLK","FSM","FRO","FRA","SXM","GAB","GBR","GRD","GEO","GUF", + "GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","SGS","GTM", + "GUM","GNB","GUY","HKG","HMD","HND","HRV","HTI","HUN","IDN", + "IRL","ISR","IND","IOT","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","ATF","TGO","THA", + "TJK","TKL","TKM","TUN","TON","TLS","TUR","TTO","TUV","TWN", + "TZA","UKR","UGA","UMI","USA","URY","UZB","VAT","VCT","VEN", + "VGB","VIR","VNM","VUT","WLF","WSM","YEM","MYT","SRB","ZAF", + "ZMB","MNE","ZWE","A1","A2","O1","ALA","GGY","IMN","JEY", + "BLM","MAF", "BES" + ); 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" + "","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Curacao", + "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","Sint Maarten (Dutch part)","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","Libya","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", "Bonaire, Saint Eustatius and Saba" ); var $GEOIP_CONTINENT_CODES = array( - "--", "AS", "EU", "EU", "AS", "AS", "NA", "NA", "EU", "AS", - "NA", "AF", "AN", "SA", "OC", "EU", "OC", "NA", "AS", "EU", - "NA", "AS", "EU", "AF", "EU", "AS", "AF", "AF", "NA", "AS", - "SA", "SA", "NA", "AS", "AN", "AF", "EU", "NA", "NA", "AS", - "AF", "AF", "AF", "EU", "AF", "OC", "SA", "AF", "AS", "SA", - "NA", "NA", "AF", "AS", "AS", "EU", "EU", "AF", "EU", "NA", - "NA", "AF", "SA", "EU", "AF", "AF", "AF", "EU", "AF", "EU", - "OC", "SA", "OC", "EU", "EU", "EU", "AF", "EU", "NA", "AS", - "SA", "AF", "EU", "NA", "AF", "AF", "NA", "AF", "EU", "AN", - "NA", "OC", "AF", "SA", "AS", "AN", "NA", "EU", "NA", "EU", - "AS", "EU", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "NA", - "AS", "AS", "AF", "AS", "AS", "OC", "AF", "NA", "AS", "AS", - "AS", "NA", "AS", "AS", "AS", "NA", "EU", "AS", "AF", "AF", - "EU", "EU", "EU", "AF", "AF", "EU", "EU", "AF", "OC", "EU", - "AF", "AS", "AS", "AS", "OC", "NA", "AF", "NA", "EU", "AF", - "AS", "AF", "NA", "AS", "AF", "AF", "OC", "AF", "OC", "AF", - "NA", "EU", "EU", "AS", "OC", "OC", "OC", "AS", "NA", "SA", - "OC", "OC", "AS", "AS", "EU", "NA", "OC", "NA", "AS", "EU", - "OC", "SA", "AS", "AF", "EU", "EU", "AF", "AS", "OC", "AF", - "AF", "EU", "AS", "AF", "EU", "EU", "EU", "AF", "EU", "AF", - "AF", "SA", "AF", "NA", "AS", "AF", "NA", "AF", "AN", "AF", - "AS", "AS", "OC", "AS", "AF", "OC", "AS", "EU", "NA", "OC", - "AS", "AF", "EU", "AF", "OC", "NA", "SA", "AS", "EU", "NA", - "SA", "NA", "NA", "AS", "OC", "OC", "OC", "AS", "AF", "EU", - "AF", "AF", "EU", "AF", "--", "--", "--", "EU", "EU", "EU", - "EU", "NA", "NA" + "--", "AS","EU","EU","AS","AS","NA","NA","EU","AS","NA", + "AF","AN","SA","OC","EU","OC","NA","AS","EU","NA", + "AS","EU","AF","EU","AS","AF","AF","NA","AS","SA", + "SA","NA","AS","AN","AF","EU","NA","NA","AS","AF", + "AF","AF","EU","AF","OC","SA","AF","AS","SA","NA", + "NA","AF","AS","AS","EU","EU","AF","EU","NA","NA", + "AF","SA","EU","AF","AF","AF","EU","AF","EU","OC", + "SA","OC","EU","EU","NA","AF","EU","NA","AS","SA", + "AF","EU","NA","AF","AF","NA","AF","EU","AN","NA", + "OC","AF","SA","AS","AN","NA","EU","NA","EU","AS", + "EU","AS","AS","AS","AS","AS","EU","EU","NA","AS", + "AS","AF","AS","AS","OC","AF","NA","AS","AS","AS", + "NA","AS","AS","AS","NA","EU","AS","AF","AF","EU", + "EU","EU","AF","AF","EU","EU","AF","OC","EU","AF", + "AS","AS","AS","OC","NA","AF","NA","EU","AF","AS", + "AF","NA","AS","AF","AF","OC","AF","OC","AF","NA", + "EU","EU","AS","OC","OC","OC","AS","NA","SA","OC", + "OC","AS","AS","EU","NA","OC","NA","AS","EU","OC", + "SA","AS","AF","EU","EU","AF","AS","OC","AF","AF", + "EU","AS","AF","EU","EU","EU","AF","EU","AF","AF", + "SA","AF","NA","AS","AF","NA","AF","AN","AF","AS", + "AS","OC","AS","AF","OC","AS","EU","NA","OC","AS", + "AF","EU","AF","OC","NA","SA","AS","EU","NA","SA", + "NA","NA","AS","OC","OC","OC","AS","AF","EU","AF", + "AF","EU","AF","--","--","--","EU","EU","EU","EU", + "NA","NA","NA" ); } -if (!function_exists('geoip_load_shared_mem')) -{ - 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); - } +if (!function_exists('geoip_load_shared_mem ')){ +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); } -if (!function_exists('_setup_segments')) -{ - 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_DOMAIN_EDITION) - || ($gi->databaseType == GEOIP_ISP_EDITION) - || ($gi->databaseType == GEOIP_LOCATIONA_EDITION) - || ($gi->databaseType == GEOIP_ACCURACYRADIUS_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_DOMAIN_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_DOMAIN_EDITION) - || ($gi->databaseType == GEOIP_ISP_EDITION) - || ($gi->databaseType == GEOIP_LOCATIONA_EDITION) - || ($gi->databaseType == GEOIP_ACCURACYRADIUS_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_DOMAIN_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; - } } -if (!function_exists('geoip_open')) -{ - 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']); - } - } +if (!function_exists('_setup_segments')){ +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++; - $gi = _setup_segments($gi); - return $gi; - } + 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_ORG_EDITION_V6) + || ($gi->databaseType == GEOIP_DOMAIN_EDITION) + || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6) + || ($gi->databaseType == GEOIP_ISP_EDITION) + || ($gi->databaseType == GEOIP_ISP_EDITION_V6) + || ($gi->databaseType == GEOIP_USERTYPE_EDITION) + || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6) + || ($gi->databaseType == GEOIP_LOCATIONA_EDITION) + || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION) + || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6) + || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6) + || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1) + || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6) + || ($gi->databaseType == GEOIP_ASNUM_EDITION) + || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)){ + $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_ORG_EDITION_V6) + || ($gi->databaseType == GEOIP_DOMAIN_EDITION) + || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6) + || ($gi->databaseType == GEOIP_ISP_EDITION) + || ($gi->databaseType == GEOIP_ISP_EDITION_V6)) { + $gi->record_length = ORG_RECORD_LENGTH; + } + } + break; + } else { + $offset -= 4; + } + } + if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| + ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6)|| + ($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_CITY_EDITION_REV0_V6) + || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6) + || ($gi->databaseType == GEOIP_ORG_EDITION) + || ($gi->databaseType == GEOIP_DOMAIN_EDITION) + || ($gi->databaseType == GEOIP_ISP_EDITION) + || ($gi->databaseType == GEOIP_ORG_EDITION_V6) + || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6) + || ($gi->databaseType == GEOIP_ISP_EDITION_V6) + || ($gi->databaseType == GEOIP_LOCATIONA_EDITION) + || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION) + || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6) + || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6) + || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1) + || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6) + || ($gi->databaseType == GEOIP_USERTYPE_EDITION) + || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6) + || ($gi->databaseType == GEOIP_ASNUM_EDITION) + || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)){ + $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_DOMAIN_EDITION ) + || ( $gi->databaseType == GEOIP_ISP_EDITION ) + || ( $gi->databaseType == GEOIP_ORG_EDITION_V6 ) + || ( $gi->databaseType == GEOIP_DOMAIN_EDITION_V6 ) + || ( $gi->databaseType == GEOIP_ISP_EDITION_V6 )) { + $gi->record_length = ORG_RECORD_LENGTH; + } + } + break; + } else { + fseek($gi->filehandle, -4, SEEK_CUR); + } + } + if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| + ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6)|| + ($gi->databaseType == GEOIP_PROXY_EDITION)|| + ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ + $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; + } + fseek($gi->filehandle,$filepos,SEEK_SET); + } + return $gi; } -if (!function_exists('geoip_close')) -{ - function geoip_close($gi) { - if ($gi->flags & GEOIP_SHARED_MEMORY) { - return true; - } - - return fclose($gi->filehandle); - } -} -if (!function_exists('geoip_country_id_by_name')) -{ - 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); - } -} -if (!function_exists('geoip_country_code_by_name')) -{ - 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; - } } -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); - if ($country_id !== false) { - return $gi->GEOIP_COUNTRY_NAMES[$country_id]; - } - return false; - } +if (!function_exists('geoip_open')){ +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; } -if (!function_exists('geoip_country_id_by_addr')) -{ - function geoip_country_id_by_addr($gi, $addr) { - $ipnum = ip2long($addr); - return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; - } } -if (!function_exists('geoip_country_code_by_addr')) -{ - 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; - } -} -if (!function_exists('geoip_country_name_by_addr')) -{ - 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; - } -} -if (!function_exists('_geoip_seek_country')) -{ - function _geoip_seek_country($gi, $ipnum) { - $offset = 0; - for ($depth = 31; $depth >= 0; --$depth) { - if ($gi->flags & GEOIP_MEMORY_CACHE) { - // workaround php's broken substr, strpos, etc handling with - // mbstring.func_overload and mbstring.internal_encoding - $enc = mb_internal_encoding(); - mb_internal_encoding('ISO-8859-1'); +if (!function_exists('geoip_close')){ +function geoip_close($gi) { + if ($gi->flags & GEOIP_SHARED_MEMORY) { + return true; + } - $buf = substr($gi->memory_buffer, - 2 * $gi->record_length * $offset, - 2 * $gi->record_length); - - mb_internal_encoding($enc); - } 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; - } + return fclose($gi->filehandle); } -if (!function_exists('_get_org')) -{ - 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); - } - // workaround php's broken substr, strpos, etc handling with - // mbstring.func_overload and mbstring.internal_encoding - $enc = mb_internal_encoding(); - mb_internal_encoding('ISO-8859-1'); - $org_buf = substr($org_buf, 0, strpos($org_buf, "\0")); - mb_internal_encoding($enc); - return $org_buf; - } } -if (!function_exists('geoip_org_by_addr')) -{ - function geoip_org_by_addr ($gi,$addr) { - if ($addr == NULL) { - return 0; - } - $ipnum = ip2long($addr); - return _get_org($gi, $ipnum); - } +if (!function_exists('geoip_country_id_by_name_v6')){ +function geoip_country_id_by_name_v6($gi, $name) { + $rec = dns_get_record($name, DNS_AAAA); + if ( !$rec ) { + return false; + } + $addr = $rec[0]["ipv6"]; + if (!$addr || $addr == $name) { + return false; + } + return geoip_country_id_by_addr_v6($gi, $addr); +} } -if (!function_exists('_get_region')) -{ - 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); - } - } +if (!function_exists('geoip_country_id_by_name')){ +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); +} } -if (!function_exists('geoip_region_by_addr')) -{ - function geoip_region_by_addr ($gi,$addr) { - if ($addr == NULL) { - return 0; - } - $ipnum = ip2long($addr); - return _get_region($gi, $ipnum); - } +if (!function_exists('geoip_country_code_by_name_v6')){ +function geoip_country_code_by_name_v6($gi, $name) { + $country_id = geoip_country_id_by_name_v6($gi,$name); + if ($country_id !== false) { + return $gi->GEOIP_COUNTRY_CODES[$country_id]; + } + return false; +} } -if (!function_exists('getdnsattributes')) -{ - 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; - } +if (!function_exists('geoip_country_code_by_name')){ +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; } +} + +if (!function_exists('geoip_country_name_by_name_v6')){ +function geoip_country_name_by_name_v6($gi, $name) { + $country_id = geoip_country_id_by_name_v6($gi,$name); + if ($country_id !== false) { + return $gi->GEOIP_COUNTRY_NAMES[$country_id]; + } + return false; +} +} + +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); + if ($country_id !== false) { + return $gi->GEOIP_COUNTRY_NAMES[$country_id]; + } + return false; +} +} + +if (!function_exists('geoip_country_id_by_addr_v6')){ +function geoip_country_id_by_addr_v6($gi, $addr) { + $ipnum = inet_pton($addr); + return _geoip_seek_country_v6($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; +} +} + +if (!function_exists('geoip_country_id_by_addr')){ +function geoip_country_id_by_addr($gi, $addr) { + $ipnum = ip2long($addr); + return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; +} +} + +if (!function_exists('geoip_country_code_by_addr_v6')){ +function geoip_country_code_by_addr_v6($gi, $addr) { + $country_id = geoip_country_id_by_addr_v6($gi,$addr); + if ($country_id !== false) { + return $gi->GEOIP_COUNTRY_CODES[$country_id]; + } + return false; +} +} + +if (!function_exists('geoip_country_code_by_addr')){ +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; +} +} + +if (!function_exists('geoip_country_name_by_addr_v6')){ +function geoip_country_name_by_addr_v6($gi, $addr) { + $country_id = geoip_country_id_by_addr_v6($gi,$addr); + if ($country_id !== false) { + return $gi->GEOIP_COUNTRY_NAMES[$country_id]; + } + return false; +} +} + +if (!function_exists('geoip_country_name_by_addr')){ +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; +} +} + +if (!function_exists('_geoip_seek_country_v6')){ +function _geoip_seek_country_v6($gi, $ipnum) { + + # arrays from unpack start with offset 1 + # yet another php mystery. array_merge work around + # this broken behaviour + $v6vec = array_merge(unpack( "C16", $ipnum)); + + $offset = 0; + for ($depth = 127; $depth >= 0; --$depth) { + if ($gi->flags & GEOIP_MEMORY_CACHE) { + // workaround php's broken substr, strpos, etc handling with + // mbstring.func_overload and mbstring.internal_encoding + $enc = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); + + $buf = substr($gi->memory_buffer, + 2 * $gi->record_length * $offset, + 2 * $gi->record_length); + + mb_internal_encoding($enc); + } 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); + } + } + + $bnum = 127 - $depth; + $idx = $bnum >> 3; + $b_mask = 1 << ( $bnum & 7 ^ 7 ); + if (($v6vec[$idx] & $b_mask) > 0) { + 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; +} +} + +if (!function_exists('_geoip_seek_country')){ +function _geoip_seek_country($gi, $ipnum) { + $offset = 0; + for ($depth = 31; $depth >= 0; --$depth) { + if ($gi->flags & GEOIP_MEMORY_CACHE) { + // workaround php's broken substr, strpos, etc handling with + // mbstring.func_overload and mbstring.internal_encoding + $enc = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); + + $buf = substr($gi->memory_buffer, + 2 * $gi->record_length * $offset, + 2 * $gi->record_length); + + mb_internal_encoding($enc); + } 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; +} +} + +if (!function_exists('_common_get_org')){ +function _common_get_org($gi, $seek_org){ + $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); + } + // workaround php's broken substr, strpos, etc handling with + // mbstring.func_overload and mbstring.internal_encoding + $enc = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); + $org_buf = substr($org_buf, 0, strpos($org_buf, "\0")); + mb_internal_encoding($enc); + return $org_buf; +} +} + +if (!function_exists('_get_org_v6')){ +function _get_org_v6($gi,$ipnum){ + $seek_org = _geoip_seek_country_v6($gi,$ipnum); + if ($seek_org == $gi->databaseSegments) { + return NULL; + } + return _common_get_org($gi, $seek_org); +} +} + +if (!function_exists('_get_org')){ +function _get_org($gi,$ipnum){ + $seek_org = _geoip_seek_country($gi,$ipnum); + if ($seek_org == $gi->databaseSegments) { + return NULL; + } + return _common_get_org($gi, $seek_org); +} +} + + + +if (!function_exists('geoip_name_by_addr_v6 ')){ +function geoip_name_by_addr_v6 ($gi,$addr) { + if ($addr == NULL) { + return 0; + } + $ipnum = inet_pton($addr); + return _get_org_v6($gi, $ipnum); +} +} + +if (!function_exists('geoip_name_by_addr ')){ +function geoip_name_by_addr ($gi,$addr) { + if ($addr == NULL) { + return 0; + } + $ipnum = ip2long($addr); + return _get_org($gi, $ipnum); +} +} + +if (!function_exists('geoip_org_by_addr ')){ +function geoip_org_by_addr ($gi,$addr) { + return geoip_name_by_addr($gi, $addr); +} +} + +if (!function_exists('_get_region')){ +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); + } +} +} + +if (!function_exists('geoip_region_by_addr ')){ +function geoip_region_by_addr ($gi,$addr) { + if ($addr == NULL) { + return 0; + } + $ipnum = ip2long($addr); + return _get_region($gi, $ipnum); +} +} + +if (!function_exists('getdnsattributes ')){ +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():''; + $str = substr( $str, 1, -1 ); + return $str; +} +} + ?> diff --git a/tools/geoip/geoipcity.inc b/tools/geoip/geoipcity.inc index 08efe52d9..a93c3d35d 100755 --- a/tools/geoip/geoipcity.inc +++ b/tools/geoip/geoipcity.inc @@ -67,9 +67,9 @@ class geoipdnsrecord { function getrecordwithdnsservice($str){ $record = new geoipdnsrecord; - $keyvalue = split(";",$str); + $keyvalue = explode(";",$str); foreach ($keyvalue as $keyvalue2){ - list($key,$value) = split("=",$keyvalue2); + list($key,$value) = explode("=",$keyvalue2); if ($key == "co"){ $record->country_code = $value; } @@ -115,12 +115,16 @@ function getrecordwithdnsservice($str){ return $record; } -function _get_record($gi,$ipnum){ - $seek_country = _geoip_seek_country($gi,$ipnum); + +function _get_record_v6($gi,$ipnum){ + $seek_country = _geoip_seek_country_v6($gi,$ipnum); if ($seek_country == $gi->databaseSegments) { return NULL; } - + return _common_get_record($gi, $seek_country); +} + +function _common_get_record($gi, $seek_country){ // workaround php's broken substr, strpos, etc handling with // mbstring.func_overload and mbstring.internal_encoding $enc = mb_internal_encoding(); @@ -206,6 +210,22 @@ function _get_record($gi,$ipnum){ return $record; } +function GeoIP_record_by_addr_v6 ($gi,$addr){ + if ($addr == NULL){ + return 0; + } + $ipnum = inet_pton($addr); + return _get_record_v6($gi, $ipnum); +} + +function _get_record($gi,$ipnum){ + $seek_country = _geoip_seek_country($gi,$ipnum); + if ($seek_country == $gi->databaseSegments) { + return NULL; + } + return _common_get_record($gi, $seek_country); +} + function GeoIP_record_by_addr ($gi,$addr){ if ($addr == NULL){ return 0; diff --git a/tools/geoip/geoipregionvars.php b/tools/geoip/geoipregionvars.php index 4f34d2fd1..c18a4aff8 100755 --- a/tools/geoip/geoipregionvars.php +++ b/tools/geoip/geoipregionvars.php @@ -1,5 +1,5 @@ array( "02" => "Canillo", @@ -254,7 +254,9 @@ $GEOIP_REGION_NAME = array( "09" => "West-Vlaanderen", "10" => "Brabant Wallon", "11" => "Brussels Hoofdstedelijk Gewest", - "12" => "Vlaams-Brabant"), + "12" => "Vlaams-Brabant", + "13" => "Flanders", + "14" => "Wallonia"), "BF" => array( "15" => "Bam", "19" => "Boulkiemde", @@ -675,9 +677,6 @@ $GEOIP_REGION_NAME = array( "02" => "Antioquia", "03" => "Arauca", "04" => "Atlantico", - "05" => "Bolivar Department", - "06" => "Boyaca Department", - "07" => "Caldas Department", "08" => "Caqueta", "09" => "Cauca", "10" => "Cesar", @@ -687,7 +686,6 @@ $GEOIP_REGION_NAME = array( "15" => "Guainia", "16" => "Huila", "17" => "La Guajira", - "18" => "Magdalena Department", "19" => "Meta", "20" => "Narino", "21" => "Norte de Santander", @@ -1621,26 +1619,19 @@ $GEOIP_REGION_NAME = array( "03" => "Bengkulu", "04" => "Jakarta Raya", "05" => "Jambi", - "06" => "Jawa Barat", "07" => "Jawa Tengah", "08" => "Jawa Timur", - "09" => "Papua", "10" => "Yogyakarta", "11" => "Kalimantan Barat", "12" => "Kalimantan Selatan", "13" => "Kalimantan Tengah", "14" => "Kalimantan Timur", "15" => "Lampung", - "16" => "Maluku", "17" => "Nusa Tenggara Barat", "18" => "Nusa Tenggara Timur", - "19" => "Riau", - "20" => "Sulawesi Selatan", "21" => "Sulawesi Tengah", "22" => "Sulawesi Tenggara", - "23" => "Sulawesi Utara", "24" => "Sumatera Barat", - "25" => "Sumatera Selatan", "26" => "Sumatera Utara", "28" => "Maluku", "29" => "Maluku Utara", @@ -1850,14 +1841,17 @@ $GEOIP_REGION_NAME = array( "17" => "Kingston"), "JO" => array( "02" => "Al Balqa'", - "07" => "Ma", "09" => "Al Karak", - "10" => "Al Mafraq", - "11" => "Amman Governorate", "12" => "At Tafilah", - "13" => "Az Zarqa", - "14" => "Irbid", - "16" => "Amman"), + "15" => "Al Mafraq", + "16" => "Amman", + "17" => "Az Zaraqa", + "18" => "Irbid", + "19" => "Ma'an", + "20" => "Ajlun", + "21" => "Al Aqabah", + "22" => "Jarash", + "23" => "Madaba"), "JP" => array( "01" => "Aichi", "02" => "Akita", @@ -2272,6 +2266,7 @@ $GEOIP_REGION_NAME = array( "79" => "Leova", "80" => "Nisporeni", "81" => "Ocnita", + "82" => "Orhei", "83" => "Rezina", "84" => "Riscani", "85" => "Singerei", @@ -2721,7 +2716,6 @@ $GEOIP_REGION_NAME = array( "05" => "Limburg", "06" => "Noord-Brabant", "07" => "Noord-Holland", - "08" => "Overijssel", "09" => "Utrecht", "10" => "Zeeland", "11" => "Zuid-Holland", @@ -3217,7 +3211,8 @@ $GEOIP_REGION_NAME = array( "89" => "Yevrey", "90" => "Permskiy Kray", "91" => "Krasnoyarskiy Kray", - "CI" => "Chechnya Republic"), + "92" => "Kamchatskiy Kray", + "93" => "Zabaykal'skiy Kray"), "RW" => array( "01" => "Butare", "06" => "Gitarama", @@ -3230,12 +3225,11 @@ $GEOIP_REGION_NAME = array( "15" => "Sud"), "SA" => array( "02" => "Al Bahah", - "03" => "Al Jawf", "05" => "Al Madinah", "06" => "Ash Sharqiyah", "08" => "Al Qasim", - "09" => "Al Qurayyat", "10" => "Ar Riyad", + "11" => "Asir Province", "13" => "Ha'il", "14" => "Makkah", "15" => "Al Hudud ash Shamaliyah", @@ -4142,19 +4136,26 @@ $GEOIP_REGION_NAME = array( "03" => "Al Mahrah", "04" => "Hadramawt", "05" => "Shabwah", - "06" => "Al Ghaydah", + "06" => "Lahij", + "07" => "Al Bayda'", "08" => "Al Hudaydah", + "09" => "Al Jawf", "10" => "Al Mahwit", "11" => "Dhamar", + "12" => "Hajjah", + "13" => "Ibb", "14" => "Ma'rib", - "15" => "Sa", - "16" => "San", + "15" => "Sa'dah", + "16" => "San'a'", + "17" => "Taizz", + "18" => "Ad Dali", + "19" => "Amran", "20" => "Al Bayda'", "21" => "Al Jawf", "22" => "Hajjah", "23" => "Ibb", "24" => "Lahij", - "25" => "Ta"), + "25" => "Taizz"), "ZA" => array( "01" => "North-Western Province", "02" => "KwaZulu-Natal", From 770be469f67fecdb76e721a67462974aed56027c Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 15:31:25 +0100 Subject: [PATCH 008/802] [-] Core : removed outdated file that may interfere with override #PSCFV-5911 --- override/classes/PDF.php | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 override/classes/PDF.php diff --git a/override/classes/PDF.php b/override/classes/PDF.php deleted file mode 100644 index d65c45807..000000000 --- a/override/classes/PDF.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Fri, 14 Dec 2012 15:51:45 +0100 Subject: [PATCH 009/802] [-] MO : pagesnotfound module fixed #PSCFV-5949 --- modules/pagesnotfound/pagesnotfound.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/pagesnotfound/pagesnotfound.php b/modules/pagesnotfound/pagesnotfound.php index b8a0e40ec..020e970e2 100644 --- a/modules/pagesnotfound/pagesnotfound.php +++ b/modules/pagesnotfound/pagesnotfound.php @@ -35,7 +35,7 @@ class Pagesnotfound extends Module { $this->name = 'pagesnotfound'; $this->tab = 'analytics_stats'; - $this->version = 1.0; + $this->version = 1.1; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -167,14 +167,17 @@ class Pagesnotfound extends Module $_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_URL']; if (!Validate::isUrl($request_uri = $_SERVER['REQUEST_URI']) || strstr($_SERVER['REQUEST_URI'], '-admin404')) return; - if (strstr($_SERVER['PHP_SELF'], '404.php') && !strstr($_SERVER['REQUEST_URI'], '404.php')) + + if (get_class(Context::getContext()->controller) == 'PageNotFoundController') { $http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if (empty($http_referer) || Validate::isAbsoluteUrl($http_referer)) + { Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_shop_group`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.(int)$this->context->shop->id.', '.(int)$this->context->shop->id_shop_group.') '); + } } } } From 1e7963ec125769a337734d61c026f6c7ff9c7b42 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 14 Dec 2012 17:14:01 +0100 Subject: [PATCH 010/802] // Typo in the name of an image --- admin-dev/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin-dev/functions.php b/admin-dev/functions.php index a79749b62..28e9486b8 100644 --- a/admin-dev/functions.php +++ b/admin-dev/functions.php @@ -431,7 +431,7 @@ function runAdminTab($tab, $ajaxMode = false) $bread = ''; foreach ($tabs AS $key => $item) { - $bread .= ' >'; + $bread .= ' >'; if (count($tabs) - 1 > $key) $bread .= ''; From 3d1663279af813dafd19f128569c7c8fa4b34dea Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Mon, 17 Dec 2012 15:45:40 +0100 Subject: [PATCH 011/802] [-] BO : fixed image upload (except with OVH firewall) #PSCFV-6152 #PSCFV-6157 #PSCFV-5862 #PSCFV-5756 #PSCFV-6074 #PSCFV-5459 --- classes/FileUploader.php | 11 +++++------ controllers/admin/AdminImportController.php | 18 +++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/classes/FileUploader.php b/classes/FileUploader.php index 326eb9ef3..8958cec67 100755 --- a/classes/FileUploader.php +++ b/classes/FileUploader.php @@ -162,14 +162,13 @@ class QqUploadedFileXhr public function upload($path) { $input = fopen('php://input', 'r'); - $temp = tmpfile(); - $realSize = stream_copy_to_stream($input, $temp); - fclose($input); + $target = fopen($path, 'w'); + + $realSize = stream_copy_to_stream($input, $target); if ($realSize != $this->getSize()) return false; - $target = fopen($path, 'w'); - fseek($temp, 0, SEEK_SET); - stream_copy_to_stream($temp, $target); + + fclose($input); fclose($target); return true; diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index a6c0ddcf1..f3b3fb68d 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -638,20 +638,20 @@ class AdminImportControllerCore extends AdminController if (empty($field)) return array(); - if (is_null(Tools::getValue('multiple_value_separator')) || trim(Tools::getValue('multiple_value_separator')) == '') + $separator = Tools::getValue('multiple_value_separator'); + if (is_null($separator) || trim($separator) == '') $separator = ','; - else - $separator = Tools::getValue('multiple_value_separator'); - $temp = tmpfile(); - fwrite($temp, $field); - rewind($temp); - $tab = fgetcsv($temp, MAX_LINE_SIZE, $separator); - fclose($temp); + do $uniqid = uniqid(); while (file_exists(_PS_UPLOAD_DIR_.$uniqid)); + $tmp_file = file_put_contents(_PS_UPLOAD_DIR_.$uniqid, $field); + $fd = fopen($temp, 'r'); + $tab = fgetcsv($fd, MAX_LINE_SIZE, $separator); + fclose($fd); + unlink($tmp_file); + if (empty($tab) || (!is_array($tab))) return array(); return $tab; - } protected static function createMultiLangField($field) From 207669038378e9283d208481e89243582cb77f72 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Mon, 17 Dec 2012 16:18:57 +0100 Subject: [PATCH 012/802] [-] FO : fixed multishipping crash when too many products and addresses --- install-dev/upgrade/sql/1.5.3.0.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install-dev/upgrade/sql/1.5.3.0.sql b/install-dev/upgrade/sql/1.5.3.0.sql index 7633f3711..19cf3a44d 100644 --- a/install-dev/upgrade/sql/1.5.3.0.sql +++ b/install-dev/upgrade/sql/1.5.3.0.sql @@ -18,4 +18,6 @@ UPDATE `PREFIX_order_state_lang` SET `template` = 'payment' WHERE `id_order_stat DELETE FROM `PREFIX_configuration` WHERE `name`= 'PS_HIGH_HTML_THEME_COMPRESSION'; -INSERT INTO `PREFIX_configuration`(`name`, `value`, `date_add`, `date_upd`) VALUES ('PS_MAIL_COLOR', '#db3484', NOW(), NOW()); \ No newline at end of file +INSERT INTO `PREFIX_configuration`(`name`, `value`, `date_add`, `date_upd`) VALUES ('PS_MAIL_COLOR', '#db3484', NOW(), NOW()); + +ALTER TABLE `PREFIX_cart` CHANGE `delivery_option` `delivery_option` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ''; From 3a55ff9ee99ff3ce16bd127f23faef499e07995b Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Mon, 17 Dec 2012 16:51:21 +0100 Subject: [PATCH 013/802] //added more details in some error messages --- controllers/admin/AdminTaxRulesGroupController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/admin/AdminTaxRulesGroupController.php b/controllers/admin/AdminTaxRulesGroupController.php index c7621c90f..c7aa929bc 100644 --- a/controllers/admin/AdminTaxRulesGroupController.php +++ b/controllers/admin/AdminTaxRulesGroupController.php @@ -416,7 +416,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zip_code); // Construct Object Country - $country = new Country((int)$id_country); + $country = new Country((int)$id_country, (int)$this->context->language->id); if ($zip_code && $country->need_zip_code) { @@ -427,8 +427,8 @@ class AdminTaxRulesGroupControllerCore extends AdminController if (!$country->checkZipCode($zip_code)) { $this->errors[] = sprintf( - Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), - str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))) + Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s for %s'), + str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))), $country->name ); } } From 122c3e5a86c05c14e9676f838fe598720278a63c Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 18 Dec 2012 11:15:01 +0100 Subject: [PATCH 014/802] [-] FO : fixed CSS compression when using inline images #PSCFV-5326 --- classes/Media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Media.php b/classes/Media.php index 9a123e8b9..1b31cc5fc 100755 --- a/classes/Media.php +++ b/classes/Media.php @@ -144,7 +144,7 @@ class MediaCore if (strlen($css_content) > 0) { $css_content = preg_replace('#/\*.*?\*/#s', '', $css_content); - $css_content = preg_replace_callback('#url\((?:\'|")?([^\)\'"]*)(?:\'|")?\)#s', array('Tools', 'replaceByAbsoluteURL'), $css_content); + $css_content = preg_replace_callback('#url\((?!data:)(?:\'|")?([^\)\'"]*)(?:\'|")?\)#s', array('Tools', 'replaceByAbsoluteURL'), $css_content); $css_content = preg_replace('#\s+#', ' ', $css_content); $css_content = str_replace("\t", '', $css_content); From 7869a43d1610ad1076cbeafac45ef7366b3a60d8 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 18 Dec 2012 11:48:50 +0100 Subject: [PATCH 015/802] [-] Core : do not die in production mode! #PSCFV-5751 --- classes/module/Module.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/classes/module/Module.php b/classes/module/Module.php index c96ef30fb..efe38a9ce 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -855,7 +855,12 @@ abstract class ModuleCore public static function getInstanceByName($module_name) { if (!Validate::isModuleName($module_name)) - die(Tools::displayError()); + { + if (_PS_MODE_DEV_) + die(Tools::displayError()); + return false; + } + if (!isset(self::$_INSTANCE[$module_name])) { if (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/'.$module_name.'.php')) From 403ce760b22fd92cf03714ed41a8fe4dbd8dace2 Mon Sep 17 00:00:00 2001 From: Damon Skelhorn Date: Tue, 18 Dec 2012 11:52:25 +0000 Subject: [PATCH 016/802] [*] MO : crossselling - moved javascript include into header hook. --- modules/crossselling/crossselling.php | 1 + modules/crossselling/crossselling.tpl | 3 +-- modules/crossselling/js/crossselling.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/crossselling/crossselling.php b/modules/crossselling/crossselling.php index ebb0434a1..ee9fc14a8 100755 --- a/modules/crossselling/crossselling.php +++ b/modules/crossselling/crossselling.php @@ -100,6 +100,7 @@ class CrossSelling extends Module public function hookHeader() { $this->context->controller->addCSS(($this->_path).'crossselling.css', 'all'); + $this->context->controller->addJS(($this->_path).'js/crossselling.js'); } /** diff --git a/modules/crossselling/crossselling.tpl b/modules/crossselling/crossselling.tpl index 80ce798f5..b10ab5f99 100755 --- a/modules/crossselling/crossselling.tpl +++ b/modules/crossselling/crossselling.tpl @@ -25,8 +25,7 @@ {if isset($orderProducts) && count($orderProducts)}
- - +

{l s='Customers who bought this product also bought:' mod='crossselling'}

{if count($orderProducts) > 5}{l s='Previous' mod='crossselling'}{/if} diff --git a/modules/crossselling/js/crossselling.js b/modules/crossselling/js/crossselling.js index 73db212a5..deb924291 100755 --- a/modules/crossselling/js/crossselling.js +++ b/modules/crossselling/js/crossselling.js @@ -60,5 +60,5 @@ $(document).ready(function(){ force:false, cycle:false }); - $('#crossselling_list').trigger( 'goto', [middle-3] ); + $('#crossselling_list').trigger( 'goto', [cs_middle-3] ); }); From c24da4aafc40f917f855749e496c05fad413997f Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 18 Dec 2012 14:27:11 +0100 Subject: [PATCH 017/802] [-] BO : fixed weight and distance units validation --- classes/Validate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Validate.php b/classes/Validate.php index a3e564f1b..cf2dd030b 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -802,12 +802,12 @@ class ValidateCore public static function isWeightUnit($unit) { - return preg_match('/^[a-zA-Z]{1,3}$/', $unit); + return preg_match('/^[a-zA-Z]{1,5}$/U', $unit); } public static function isDistanceUnit($unit) { - return preg_match('/^[a-zA-Z]{1,2}$/', $unit); + return preg_match('/^[a-zA-Z]{1,5}$/U', $unit); } public static function isSubDomainName($domain) From bd17218001ba9a5adec340a5165b2383a74e932c Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 18 Dec 2012 14:34:33 +0100 Subject: [PATCH 018/802] // Not enough --- classes/Validate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Validate.php b/classes/Validate.php index cf2dd030b..37fd03435 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -802,12 +802,12 @@ class ValidateCore public static function isWeightUnit($unit) { - return preg_match('/^[a-zA-Z]{1,5}$/U', $unit); + return (Tools::isGenericName($unit) & (Tools::strlen($unit) < 5)); } public static function isDistanceUnit($unit) { - return preg_match('/^[a-zA-Z]{1,5}$/U', $unit); + return (Tools::isGenericName($unit) & (Tools::strlen($unit) < 5)); } public static function isSubDomainName($domain) From 86547e0b792a482688630a5c9140dbf66ea44c67 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 18 Dec 2012 14:35:28 +0100 Subject: [PATCH 019/802] // Grumpf --- classes/Validate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Validate.php b/classes/Validate.php index 37fd03435..f939f81cf 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -802,12 +802,12 @@ class ValidateCore public static function isWeightUnit($unit) { - return (Tools::isGenericName($unit) & (Tools::strlen($unit) < 5)); + return (Validate::isGenericName($unit) & (Tools::strlen($unit) < 5)); } public static function isDistanceUnit($unit) { - return (Tools::isGenericName($unit) & (Tools::strlen($unit) < 5)); + return (Validate::isGenericName($unit) & (Tools::strlen($unit) < 5)); } public static function isSubDomainName($domain) From 144081ae9ef52049e6380a3db3116cce5cb8f982 Mon Sep 17 00:00:00 2001 From: Damon Skelhorn Date: Tue, 18 Dec 2012 14:38:48 +0000 Subject: [PATCH 020/802] [-] MO : crossselling - Added in condition to test element is present. --- modules/crossselling/js/crossselling.js | 43 +++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/crossselling/js/crossselling.js b/modules/crossselling/js/crossselling.js index deb924291..3e64b8bc0 100755 --- a/modules/crossselling/js/crossselling.js +++ b/modules/crossselling/js/crossselling.js @@ -41,24 +41,27 @@ function cs_serialScrollFixLock(event, targeted, scrolled, items, position) } $(document).ready(function(){ - //init the serialScroll for thumbs - cs_serialScrollNbImages = $('#crossselling_list li').length; - cs_serialScrollNbImagesDisplayed = 5; - cs_serialScrollActualImagesIndex = 0; - $('#crossselling_list').serialScroll({ - items:'li', - prev:'a#crossselling_scroll_left', - next:'a#crossselling_scroll_right', - axis:'x', - offset:0, - stop:true, - onBefore:cs_serialScrollFixLock, - duration:300, - step: 1, - lazy:true, - lock: false, - force:false, - cycle:false - }); - $('#crossselling_list').trigger( 'goto', [cs_middle-3] ); + if($('#crossselling_list').length > 0) + { + //init the serialScroll for thumbs + cs_serialScrollNbImages = $('#crossselling_list li').length; + cs_serialScrollNbImagesDisplayed = 5; + cs_serialScrollActualImagesIndex = 0; + $('#crossselling_list').serialScroll({ + items:'li', + prev:'a#crossselling_scroll_left', + next:'a#crossselling_scroll_right', + axis:'x', + offset:0, + stop:true, + onBefore:cs_serialScrollFixLock, + duration:300, + step: 1, + lazy:true, + lock: false, + force:false, + cycle:false + }); + $('#crossselling_list').trigger( 'goto', [cs_middle-3] ); + } }); From 96d6abe2af1677a8cf802324d9924c6d9d68a768 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 18 Dec 2012 15:47:09 +0100 Subject: [PATCH 021/802] [-] BO : Fixed warning in helper #PSCFV-6183 --- admin-dev/themes/default/template/helpers/form/form.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/admin-dev/themes/default/template/helpers/form/form.tpl b/admin-dev/themes/default/template/helpers/form/form.tpl index 86d6a63c0..8d73fcac3 100644 --- a/admin-dev/themes/default/template/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/helpers/form/form.tpl @@ -167,6 +167,8 @@ {/if} {/if} >{$option->$input.options.name} + {elseif $option == "-"} + {else}