Chapagain_AutoCurrency - Version 0.2.0

Version Notes

Updated to latest MaxMind's database and geoip .inc file.
Added IPv6 support to MaxMind.
Added a new Ip2Country database of Webnet77.

Download this release

Release Info

Developer Magento Core Team
Extension Chapagain_AutoCurrency
Version 0.2.0
Comparing to
See all releases


Code changes from version 0.1.9 to 0.2.0

app/code/community/Chapagain/AutoCurrency/Helper/Data.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @category Chapagain
6
  * @package Chapagain_AutoCurrency
7
- * @version 0.1.0
8
  * @author Mukesh Chapagain <mukesh.chapagain@gmail.com>
9
  * @link http://blog.chapagain.com.np/category/magento/
10
  */
@@ -12,33 +12,159 @@
12
  class Chapagain_AutoCurrency_Helper_Data extends Mage_Core_Helper_Abstract
13
  {
14
  /**
15
- * Load GeoIP binary data file
16
- *
17
- * @return string
18
- */
19
- public function loadGeoIp()
20
- {
21
- // Load geoip.inc
22
- include_once(Mage::getBaseDir().'/var/geoip/geoip.inc');
23
-
24
- // Open Geo IP binary data file
25
- $geoIp = geoip_open(Mage::getBaseDir().'/var/geoip/GeoIP.dat',GEOIP_STANDARD);
26
-
27
- return $geoIp;
28
- }
29
-
30
  public function isEnabled()
31
  {
32
- return Mage::getStoreConfig('catalog/autocurrency/enable_disable');
33
  }
34
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  /**
36
  * Get IP Address
37
  *
38
  * @return string
39
  */
40
  public function getIpAddress()
41
- {
42
  return $_SERVER['REMOTE_ADDR'];
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
4
  *
5
  * @category Chapagain
6
  * @package Chapagain_AutoCurrency
7
+ * @version 0.2.0
8
  * @author Mukesh Chapagain <mukesh.chapagain@gmail.com>
9
  * @link http://blog.chapagain.com.np/category/magento/
10
  */
12
  class Chapagain_AutoCurrency_Helper_Data extends Mage_Core_Helper_Abstract
13
  {
14
  /**
15
+ * Check if the module is enabled
16
+ *
17
+ * @return boolean 0 or 1
18
+ */
 
 
 
 
 
 
 
 
 
 
 
19
  public function isEnabled()
20
  {
21
+ return Mage::getStoreConfig('catalog/autocurrency/enable_disable');
22
  }
23
+
24
+ /**
25
+ * Check IP database source
26
+ *
27
+ * @return string
28
+ */
29
+ public function getDatabaseSource()
30
+ {
31
+ $db = Mage::getStoreConfig('catalog/autocurrency/database_source');
32
+ if ($db == null) {
33
+ $db = 'ip2country';
34
+ }
35
+ return $db;
36
+ }
37
+
38
  /**
39
  * Get IP Address
40
  *
41
  * @return string
42
  */
43
  public function getIpAddress()
44
+ {
45
  return $_SERVER['REMOTE_ADDR'];
46
  }
47
+
48
+ /**
49
+ * Include GeoIP Inc file
50
+ */
51
+ public function loadGeoIpInc()
52
+ {
53
+ // Load geoip.inc
54
+ include_once(Mage::getBaseDir().'/var/geoip/geoip.inc');
55
+ }
56
+
57
+ /**
58
+ * Load GeoIPv4 binary data file
59
+ */
60
+ public function loadGeoIpv4()
61
+ {
62
+ $geoIPv4 = geoip_open(Mage::getBaseDir().'/var/geoip/GeoIP.dat',GEOIP_STANDARD);
63
+ return $geoIPv4;
64
+ }
65
+
66
+ /**
67
+ * Load GeoIPv6 binary data file
68
+ */
69
+ public function loadGeoIpv6()
70
+ {
71
+ $geoIPv6 = geoip_open(Mage::getBaseDir().'/var/geoip/GeoIPv6.dat',GEOIP_STANDARD);
72
+ return $geoIPv6;
73
+ }
74
+
75
+ /**
76
+ * Check whether the given IP Address is valid
77
+ *
78
+ * @param string IP Address
79
+ * @return boolean True/False
80
+ */
81
+ public function checkValidIp($ip)
82
+ {
83
+ if(!filter_var($ip, FILTER_VALIDATE_IP)) {
84
+ return false;
85
+ }
86
+ return true;
87
+ }
88
+
89
+ /**
90
+ * Check whether the given IP Address is IPv6
91
+ *
92
+ * @param string IP Address
93
+ * @return boolean True/False
94
+ */
95
+ public function checkIpv6($ip)
96
+ {
97
+ if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
98
+ return false;
99
+ }
100
+ return true;
101
+ }
102
+
103
+ /**
104
+ * Include IP2Country.php file
105
+ * and load ip2country.dat file
106
+ *
107
+ */
108
+ public function loadIp2Country()
109
+ {
110
+ include_once(Mage::getBaseDir().'/var/geoip/ip2country/Ip2Country.php');
111
+ $ipc = new Ip2Country(Mage::getBaseDir().'/var/geoip/ip2country/ip2country.dat');
112
+ $ipc->preload();
113
+ return $ipc;
114
+ }
115
+
116
+ /**
117
+ * Get Currency code by Country code
118
+ *
119
+ * @return string
120
+ */
121
+ public function getCurrencyByCountry($countryCode)
122
+ {
123
+ $map = array( '' => '',
124
+ "EU" => "EUR", "AD" => "EUR", "AE" => "AED", "AF" => "AFN", "AG" => "XCD", "AI" => "XCD",
125
+ "AL" => "ALL", "AM" => "AMD", "CW" => "ANG", "AO" => "AOA", "AQ" => "AQD", "AR" => "ARS", "AS" => "EUR",
126
+ "AT" => "EUR", "AU" => "AUD", "AW" => "AWG", "AZ" => "AZN", "BA" => "BAM", "BB" => "BBD",
127
+ "BD" => "BDT", "BE" => "EUR", "BF" => "XOF", "BG" => "BGL", "BH" => "BHD", "BI" => "BIF",
128
+ "BJ" => "XOF", "BM" => "BMD", "BN" => "BND", "BO" => "BOB", "BR" => "BRL", "BS" => "BSD",
129
+ "BT" => "BTN", "BV" => "NOK", "BW" => "BWP", "BY" => "BYR", "BZ" => "BZD", "CA" => "CAD",
130
+ "CC" => "AUD", "CD" => "CDF", "CF" => "XAF", "CG" => "XAF", "CH" => "CHF", "CI" => "XOF",
131
+ "CK" => "NZD", "CL" => "CLP", "CM" => "XAF", "CN" => "CNY", "CO" => "COP", "CR" => "CRC",
132
+ "CU" => "CUP", "CV" => "CVE", "CX" => "AUD", "CY" => "EUR", "CZ" => "CZK", "DE" => "EUR",
133
+ "DJ" => "DJF", "DK" => "DKK", "DM" => "XCD", "DO" => "DOP", "DZ" => "DZD", "EC" => "ECS",
134
+ "EE" => "EEK", "EG" => "EGP", "EH" => "MAD", "ER" => "ETB", "ES" => "EUR", "ET" => "ETB",
135
+ "FI" => "EUR", "FJ" => "FJD", "FK" => "FKP", "FM" => "USD", "FO" => "DKK", "FR" => "EUR", "SX" => "ANG",
136
+ "GA" => "XAF", "GB" => "GBP", "GD" => "XCD", "GE" => "GEL", "GF" => "EUR", "GH" => "GHS",
137
+ "GI" => "GIP", "GL" => "DKK", "GM" => "GMD", "GN" => "GNF", "GP" => "EUR", "GQ" => "XAF",
138
+ "GR" => "EUR", "GS" => "GBP", "GT" => "GTQ", "GU" => "USD", "GW" => "XOF", "GY" => "GYD",
139
+ "HK" => "HKD", "HM" => "AUD", "HN" => "HNL", "HR" => "HRK", "HT" => "HTG", "HU" => "HUF",
140
+ "ID" => "IDR", "IE" => "EUR", "IL" => "ILS", "IN" => "INR", "IO" => "USD", "IQ" => "IQD",
141
+ "IR" => "IRR", "IS" => "ISK", "IT" => "EUR", "JM" => "JMD", "JO" => "JOD", "JP" => "JPY",
142
+ "KE" => "KES", "KG" => "KGS", "KH" => "KHR", "KI" => "AUD", "KM" => "KMF", "KN" => "XCD",
143
+ "KP" => "KPW", "KR" => "KRW", "KW" => "KWD", "KY" => "KYD", "KZ" => "KZT", "LA" => "LAK",
144
+ "LB" => "LBP", "LC" => "XCD", "LI" => "CHF", "LK" => "LKR", "LR" => "LRD", "LS" => "LSL",
145
+ "LT" => "LTL", "LU" => "EUR", "LV" => "LVL", "LY" => "LYD", "MA" => "MAD", "MC" => "EUR",
146
+ "MD" => "MDL", "MG" => "MGF", "MH" => "USD", "MK" => "MKD", "ML" => "XOF", "MM" => "MMK",
147
+ "MN" => "MNT", "MO" => "MOP", "MP" => "USD", "MQ" => "EUR", "MR" => "MRO", "MS" => "XCD",
148
+ "MT" => "EUR", "MU" => "MUR", "MV" => "MVR", "MW" => "MWK", "MX" => "MXN", "MY" => "MYR",
149
+ "MZ" => "MZN", "NA" => "NAD", "NC" => "XPF", "NE" => "XOF", "NF" => "AUD", "NG" => "NGN",
150
+ "NI" => "NIO", "NL" => "EUR", "NO" => "NOK", "NP" => "NPR", "NR" => "AUD", "NU" => "NZD",
151
+ "NZ" => "NZD", "OM" => "OMR", "PA" => "PAB", "PE" => "PEN", "PF" => "XPF", "PG" => "PGK",
152
+ "PH" => "PHP", "PK" => "PKR", "PL" => "PLN", "PM" => "EUR", "PN" => "NZD", "PR" => "USD", "PS" => "ILS", "PT" => "EUR",
153
+ "PW" => "USD", "PY" => "PYG", "QA" => "QAR", "RE" => "EUR", "RO" => "RON", "RU" => "RUB",
154
+ "RW" => "RWF", "SA" => "SAR", "SB" => "SBD", "SC" => "SCR", "SD" => "SDD", "SE" => "SEK",
155
+ "SG" => "SGD", "SH" => "SHP", "SI" => "EUR", "SJ" => "NOK", "SK" => "SKK", "SL" => "SLL",
156
+ "SM" => "EUR", "SN" => "XOF", "SO" => "SOS", "SR" => "SRG", "ST" => "STD", "SV" => "SVC",
157
+ "SY" => "SYP", "SZ" => "SZL", "TC" => "USD", "TD" => "XAF", "TF" => "EUR", "TG" => "XOF",
158
+ "TH" => "THB", "TJ" => "TJS", "TK" => "NZD", "TM" => "TMM", "TN" => "TND", "TO" => "TOP", "TL" => "USD",
159
+ "TR" => "TRY", "TT" => "TTD", "TV" => "AUD", "TW" => "TWD", "TZ" => "TZS", "UA" => "UAH",
160
+ "UG" => "UGX", "UM" => "USD", "US" => "USD", "UY" => "UYU", "UZ" => "UZS", "VA" => "EUR",
161
+ "VC" => "XCD", "VE" => "VEF", "VG" => "USD", "VI" => "USD", "VN" => "VND", "VU" => "VUV",
162
+ "WF" => "XPF", "WS" => "EUR", "YE" => "YER", "YT" => "EUR", "RS" => "RSD",
163
+ "ZA" => "ZAR", "ZM" => "ZMK", "ME" => "EUR", "ZW" => "ZWD",
164
+ "AX" => "EUR", "GG" => "GBP", "IM" => "GBP",
165
+ "JE" => "GBP", "BL" => "EUR", "MF" => "EUR", "BQ" => "USD", "SS" => "SSP"
166
+ );
167
+
168
+ return $map[$countryCode];
169
+ }
170
  }
app/code/community/Chapagain/AutoCurrency/Model/Store.php CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @category Chapagain
7
  * @package Chapagain_AutoCurrency
8
- * @version 0.1.0
9
  * @author Mukesh Chapagain <mukesh.chapagain@gmail.com>
10
  * @link http://blog.chapagain.com.np/category/magento/
11
  */
@@ -33,32 +33,83 @@ class Chapagain_AutoCurrency_Model_Store extends Mage_Core_Model_Store
33
  * @return string
34
  */
35
  public function getCurrencyCodeByIp($result = '')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  {
37
- // load GeoIP binary data file
38
- $geoIp = Mage::helper('autocurrency')->loadGeoIp();
39
 
 
40
  $ipAddress = Mage::helper('autocurrency')->getIpAddress();
 
 
 
 
 
 
41
 
42
- // get country code from ip address
43
- $countryCode = geoip_country_code_by_addr($geoIp, $ipAddress);
 
44
 
45
- if($countryCode == '') {
46
- return $result;
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
 
 
 
 
 
 
 
 
 
 
49
  // get currency code from country code
50
- $currencyCode = geoip_currency_code_by_country_code($geoIp, $countryCode);
 
51
 
52
  // close the geo database
53
  geoip_close($geoIp);
54
 
55
- // if currencyCode is not present in allowedCurrencies
56
- // then return the default currency code
57
- $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
58
- if(!in_array($currencyCode, $allowedCurrencies)) {
59
- return $result;
60
- }
61
-
62
  return $currencyCode;
63
  }
64
  }
5
  *
6
  * @category Chapagain
7
  * @package Chapagain_AutoCurrency
8
+ * @version 0.2.0
9
  * @author Mukesh Chapagain <mukesh.chapagain@gmail.com>
10
  * @link http://blog.chapagain.com.np/category/magento/
11
  */
33
  * @return string
34
  */
35
  public function getCurrencyCodeByIp($result = '')
36
+ {
37
+ $databaseSource = Mage::helper('autocurrency')->getDatabaseSource();
38
+
39
+ if ($databaseSource == 'maxmind') {
40
+ $currencyCode = $this->getCurrencyCodeMaxMind();
41
+ } else {
42
+ $currencyCode = $this->getCurrencyCodeIp2Country();
43
+ }
44
+
45
+ // if currencyCode is not present in allowedCurrencies
46
+ // then return the default currency code
47
+ $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
48
+ if(!in_array($currencyCode, $allowedCurrencies)) {
49
+ return $result;
50
+ }
51
+
52
+ return $currencyCode;
53
+ }
54
+
55
+ /**
56
+ * Get Currency code by IP Address
57
+ * Using Ip2Country Database
58
+ *
59
+ * @return string
60
+ */
61
+ public function getCurrencyCodeIp2Country()
62
  {
63
+ // load Ip2Country database
64
+ $ipc = Mage::helper('autocurrency')->loadIp2Country();
65
 
66
+ // get IP Address
67
  $ipAddress = Mage::helper('autocurrency')->getIpAddress();
68
+
69
+ // additional valid ip check
70
+ // because Ip2Country generates error for invalid IP address
71
+ if (!Mage::helper('autocurrency')->checkValidIp($ipAddress)) {
72
+ return null;
73
+ }
74
 
75
+ $countryCode = $ipc->lookup($ipAddress);
76
+
77
+ $currencyCode = Mage::helper('autocurrency')->getCurrencyByCountry($countryCode);
78
 
79
+ return $currencyCode;
80
+ }
81
+
82
+ /**
83
+ * Get Currency code by IP Address
84
+ * Using MaxMind Database
85
+ *
86
+ * @return string
87
+ */
88
+ public function getCurrencyCodeMaxMind()
89
+ {
90
+ // include geoip.inc file
91
+ Mage::helper('autocurrency')->loadGeoIpInc();
92
+
93
+ // get IP Address
94
+ $ipAddress = Mage::helper('autocurrency')->getIpAddress();
95
 
96
+ // load GeoIP .dat binary file
97
+ if (Mage::helper('autocurrency')->checkIpv6($ipAddress)) {
98
+ $geoIp = Mage::helper('autocurrency')->loadGeoIpv6();
99
+ } else {
100
+ $geoIp = Mage::helper('autocurrency')->loadGeoIpv4();
101
+ }
102
+
103
+ // get country code from ip address
104
+ $countryCode = geoip_country_code_by_addr($geoIp, $ipAddress);
105
+
106
  // get currency code from country code
107
+ //$currencyCode = geoip_currency_code_by_country_code($geoIp, $countryCode);
108
+ $currencyCode = Mage::helper('autocurrency')->getCurrencyByCountry($countryCode);
109
 
110
  // close the geo database
111
  geoip_close($geoIp);
112
 
 
 
 
 
 
 
 
113
  return $currencyCode;
114
  }
115
  }
app/code/community/Chapagain/AutoCurrency/Model/System/Config/Source/Database.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Used in creating options config value selection
4
+ *
5
+ * @category Chapagain
6
+ * @package Chapagain_AutoCurrency
7
+ * @version 0.2.0
8
+ * @author Mukesh Chapagain <mukesh.chapagain@gmail.com>
9
+ * @link http://blog.chapagain.com.np/category/magento/
10
+ */
11
+ class Chapagain_AutoCurrency_Model_System_Config_Source_Database
12
+ {
13
+
14
+ /**
15
+ * Options getter
16
+ *
17
+ * @return array
18
+ */
19
+ public function toOptionArray()
20
+ {
21
+ return array(
22
+ array('value' => 'ip2country', 'label'=>Mage::helper('autocurrency')->__('IP to Country')),
23
+ array('value' => 'maxmind', 'label'=>Mage::helper('autocurrency')->__('Max Mind')),
24
+ );
25
+ }
26
+
27
+ /**
28
+ * Get options in "key-value" format
29
+ *
30
+ * @return array
31
+ */
32
+ public function toArray()
33
+ {
34
+ return array(
35
+ 'ip2country' => Mage::helper('autocurrency')->__('IP to Country'),
36
+ 'maxmind' => Mage::helper('autocurrency')->__('Max Mind'),
37
+ );
38
+ }
39
+ }
app/code/community/Chapagain/AutoCurrency/etc/config.xml CHANGED
@@ -2,11 +2,14 @@
2
  <config>
3
  <modules>
4
  <Chapagain_AutoCurrency>
5
- <version>0.1.9</version>
6
  </Chapagain_AutoCurrency>
7
  </modules>
8
  <global>
9
- <models>
 
 
 
10
  <core>
11
  <rewrite>
12
  <store>Chapagain_AutoCurrency_Model_Store</store>
2
  <config>
3
  <modules>
4
  <Chapagain_AutoCurrency>
5
+ <version>0.2.0</version>
6
  </Chapagain_AutoCurrency>
7
  </modules>
8
  <global>
9
+ <models>
10
+ <autocurrency>
11
+ <class>Chapagain_AutoCurrency_Model</class>
12
+ </autocurrency>
13
  <core>
14
  <rewrite>
15
  <store>Chapagain_AutoCurrency_Model_Store</store>
app/code/community/Chapagain/AutoCurrency/etc/system.xml CHANGED
@@ -20,7 +20,17 @@
20
  <show_in_default>1</show_in_default>
21
  <show_in_website>1</show_in_website>
22
  <show_in_store>1</show_in_store>
23
- </enable_disable>
 
 
 
 
 
 
 
 
 
 
24
  </fields>
25
  </autocurrency>
26
  </groups>
20
  <show_in_default>1</show_in_default>
21
  <show_in_website>1</show_in_website>
22
  <show_in_store>1</show_in_store>
23
+ </enable_disable>
24
+ <database_source translate="label comment">
25
+ <label>Database Source</label>
26
+ <comment></comment>
27
+ <frontend_type>select</frontend_type>
28
+ <source_model>autocurrency/system_config_source_database</source_model>
29
+ <sort_order>20</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </database_source>
34
  </fields>
35
  </autocurrency>
36
  </groups>
package.xml CHANGED
@@ -1,28 +1,22 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Chapagain_AutoCurrency</name>
4
- <version>0.1.9</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>A currency switcher extension which automatically switches store currency based on visitor's IP address.</summary>
10
- <description>Auto Currency extension tracks visitor's IP address and automatically changes the store currency to the visitor's location currency. Visitor can switch to his/her desired currency at any time.&#xD;
11
  &#xD;
12
- This extension uses MaxMind's GeoIP technology for IP address lookup.&#xD;
13
- &#xD;
14
- No extra configuration settings is to be made. Just install the module in your multi-currency Magento shop and the module will work on the fly.&#xD;
15
- &#xD;
16
- Features:-&#xD;
17
- &#xD;
18
- Easy to install and use&#xD;
19
- 100% Free&#xD;
20
- 100% Open Source</description>
21
- <notes>Minor text change for configuration settings option</notes>
22
- <authors><author><name>Mukesh Chapagain</name><user>chapagain</user><email>mukesh.chapagain@gmail.com</email></author></authors>
23
- <date>2013-10-22</date>
24
- <time>06:00:40</time>
25
- <contents><target name="magecommunity"><dir name="Chapagain"><dir name="AutoCurrency"><dir name="Helper"><file name="Data.php" hash="9ae32ce80508d03b79fd462228c7d2ee"/></dir><dir name="Model"><file name="Store.php" hash="f4ccbef38b82b6a9b27093da2ce660e4"/></dir><dir name="etc"><file name="config.xml" hash="d8b81e0591d45ee5a188753e350233b8"/><file name="system.xml" hash="b581f1aeb562ef9e220489351bf58d5c"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Chapagain_AutoCurrency.xml" hash="dd65769f686b4c12011f5d09e18249ff"/></dir></target><target name="mage"><dir name="var"><dir name="geoip"><file name="GeoIP.dat" hash="9533bdd7c9705ad2bec16dba59ce092f"/><file name="geoip.inc" hash="f2e497053c5d7dbd39431d14a87b2b27"/></dir></dir></target></contents>
26
  <compatible/>
27
- <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
28
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Chapagain_AutoCurrency</name>
4
+ <version>0.2.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>A currency switcher extension which automatically switches store's currency based on visitor's IP address.</summary>
10
+ <description>Auto Currency extension tracks visitor's IP address and automatically changes the store's currency to the visitor's location currency. Visitor can switch to his/her desired currency at any time.&#xD;
11
  &#xD;
12
+ This extension uses two IP Address databases for IP Address lookup. One is MaxMind's GeoIP and the other is Webnet77's Ip2Country database. Shop admins have the option to choose between these two databases. The default one is Webnet77's Ip2Country database.</description>
13
+ <notes>Updated to latest MaxMind's database and geoip .inc file.&#xD;
14
+ Added IPv6 support to MaxMind. &#xD;
15
+ Added a new Ip2Country database of Webnet77.</notes>
16
+ <authors><author><name>Mukesh Chapagain</name><user>auto-converted</user><email>mukesh.chapagain@gmail.com</email></author></authors>
17
+ <date>2014-12-29</date>
18
+ <time>08:55:06</time>
19
+ <contents><target name="magecommunity"><dir name="Chapagain"><dir name="AutoCurrency"><dir name="Helper"><file name="Data.php" hash="d853b8b6c2baa439bc7c59cf14a0b023"/></dir><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="Database.php" hash="90a0a1ae6616c583284e51c629132e89"/></dir></dir></dir><file name="Store.php" hash="a16e9c173acc2d539b302c1500370f4a"/></dir><dir name="etc"><file name="config.xml" hash="0c51dfdb6090c2654013b0454f8b7f20"/><file name="system.xml" hash="53c818634d95422a194e1816bbc3190d"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Chapagain_AutoCurrency.xml" hash="dd65769f686b4c12011f5d09e18249ff"/></dir></target><target name="mage"><dir name="var"><dir name="geoip"><dir name="ip2country"><file name="Ip2Country.php" hash="e4c874a15745221b402b78b8c7366dc1"/><file name="ip2country.dat" hash="7fd6d50c4ffc64cf05498556c3673e84"/></dir><file name="GeoIP.dat" hash="28e77c28a1d378ba9aade6a919400f02"/><file name="GeoIPv6.dat" hash="c45653f7a894ba84ccab5efb24d6e0f1"/><file name="geoip.inc" hash="f8f704ef71b5d294c7530dc5637b6638"/></dir></dir></target></contents>
 
 
 
 
 
 
20
  <compatible/>
21
+ <dependencies/>
22
  </package>
var/geoip/GeoIP.dat CHANGED
Binary file
var/geoip/GeoIPv6.dat ADDED
Binary file
var/geoip/geoip.inc CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
 
3
  /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
4
  /* geoip.inc
@@ -28,15 +28,15 @@ define("GEOIP_MEMORY_CACHE", 1);
28
  define("GEOIP_SHARED_MEMORY", 2);
29
  define("STRUCTURE_INFO_MAX_SIZE", 20);
30
  define("DATABASE_INFO_MAX_SIZE", 100);
31
- define("GEOIP_COUNTRY_EDITION", 106);
32
  define("GEOIP_PROXY_EDITION", 8);
33
  define("GEOIP_ASNUM_EDITION", 9);
34
  define("GEOIP_NETSPEED_EDITION", 10);
35
- define("GEOIP_REGION_EDITION_REV0", 112);
36
  define("GEOIP_REGION_EDITION_REV1", 3);
37
- define("GEOIP_CITY_EDITION_REV0", 111);
38
  define("GEOIP_CITY_EDITION_REV1", 2);
39
- define("GEOIP_ORG_EDITION", 110);
40
  define("GEOIP_ISP_EDITION", 4);
41
  define("SEGMENT_RECORD_LENGTH", 3);
42
  define("STANDARD_RECORD_LENGTH", 3);
@@ -53,605 +53,1886 @@ define("GEOIP_DIALUP_SPEED", 1);
53
  define("GEOIP_CABLEDSL_SPEED", 2);
54
  define("GEOIP_CORPORATE_SPEED", 3);
55
  define("GEOIP_DOMAIN_EDITION", 11);
 
56
  define("GEOIP_LOCATIONA_EDITION", 13);
57
  define("GEOIP_ACCURACYRADIUS_EDITION", 14);
58
  define("GEOIP_CITYCOMBINED_EDITION", 15);
59
- define("CITYCOMBINED_FIXED_RECORD", 7 );
60
-
61
- class GeoIP {
62
- var $flags;
63
- var $filehandle;
64
- var $memory_buffer;
65
- var $databaseType;
66
- var $databaseSegments;
67
- var $record_length;
68
- var $shmid;
69
- var $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
70
- "" => 0, "AP" => 1, "EU" => 2, "AD" => 3, "AE" => 4, "AF" => 5,
71
- "AG" => 6, "AI" => 7, "AL" => 8, "AM" => 9, "AN" => 10, "AO" => 11,
72
- "AQ" => 12, "AR" => 13, "AS" => 14, "AT" => 15, "AU" => 16, "AW" => 17,
73
- "AZ" => 18, "BA" => 19, "BB" => 20, "BD" => 21, "BE" => 22, "BF" => 23,
74
- "BG" => 24, "BH" => 25, "BI" => 26, "BJ" => 27, "BM" => 28, "BN" => 29,
75
- "BO" => 30, "BR" => 31, "BS" => 32, "BT" => 33, "BV" => 34, "BW" => 35,
76
- "BY" => 36, "BZ" => 37, "CA" => 38, "CC" => 39, "CD" => 40, "CF" => 41,
77
- "CG" => 42, "CH" => 43, "CI" => 44, "CK" => 45, "CL" => 46, "CM" => 47,
78
- "CN" => 48, "CO" => 49, "CR" => 50, "CU" => 51, "CV" => 52, "CX" => 53,
79
- "CY" => 54, "CZ" => 55, "DE" => 56, "DJ" => 57, "DK" => 58, "DM" => 59,
80
- "DO" => 60, "DZ" => 61, "EC" => 62, "EE" => 63, "EG" => 64, "EH" => 65,
81
- "ER" => 66, "ES" => 67, "ET" => 68, "FI" => 69, "FJ" => 70, "FK" => 71,
82
- "FM" => 72, "FO" => 73, "FR" => 74, "FX" => 75, "GA" => 76, "GB" => 77,
83
- "GD" => 78, "GE" => 79, "GF" => 80, "GH" => 81, "GI" => 82, "GL" => 83,
84
- "GM" => 84, "GN" => 85, "GP" => 86, "GQ" => 87, "GR" => 88, "GS" => 89,
85
- "GT" => 90, "GU" => 91, "GW" => 92, "GY" => 93, "HK" => 94, "HM" => 95,
86
- "HN" => 96, "HR" => 97, "HT" => 98, "HU" => 99, "ID" => 100, "IE" => 101,
87
- "IL" => 102, "IN" => 103, "IO" => 104, "IQ" => 105, "IR" => 106, "IS" => 107,
88
- "IT" => 108, "JM" => 109, "JO" => 110, "JP" => 111, "KE" => 112, "KG" => 113,
89
- "KH" => 114, "KI" => 115, "KM" => 116, "KN" => 117, "KP" => 118, "KR" => 119,
90
- "KW" => 120, "KY" => 121, "KZ" => 122, "LA" => 123, "LB" => 124, "LC" => 125,
91
- "LI" => 126, "LK" => 127, "LR" => 128, "LS" => 129, "LT" => 130, "LU" => 131,
92
- "LV" => 132, "LY" => 133, "MA" => 134, "MC" => 135, "MD" => 136, "MG" => 137,
93
- "MH" => 138, "MK" => 139, "ML" => 140, "MM" => 141, "MN" => 142, "MO" => 143,
94
- "MP" => 144, "MQ" => 145, "MR" => 146, "MS" => 147, "MT" => 148, "MU" => 149,
95
- "MV" => 150, "MW" => 151, "MX" => 152, "MY" => 153, "MZ" => 154, "NA" => 155,
96
- "NC" => 156, "NE" => 157, "NF" => 158, "NG" => 159, "NI" => 160, "NL" => 161,
97
- "NO" => 162, "NP" => 163, "NR" => 164, "NU" => 165, "NZ" => 166, "OM" => 167,
98
- "PA" => 168, "PE" => 169, "PF" => 170, "PG" => 171, "PH" => 172, "PK" => 173,
99
- "PL" => 174, "PM" => 175, "PN" => 176, "PR" => 177, "PS" => 178, "PT" => 179,
100
- "PW" => 180, "PY" => 181, "QA" => 182, "RE" => 183, "RO" => 184, "RU" => 185,
101
- "RW" => 186, "SA" => 187, "SB" => 188, "SC" => 189, "SD" => 190, "SE" => 191,
102
- "SG" => 192, "SH" => 193, "SI" => 194, "SJ" => 195, "SK" => 196, "SL" => 197,
103
- "SM" => 198, "SN" => 199, "SO" => 200, "SR" => 201, "ST" => 202, "SV" => 203,
104
- "SY" => 204, "SZ" => 205, "TC" => 206, "TD" => 207, "TF" => 208, "TG" => 209,
105
- "TH" => 210, "TJ" => 211, "TK" => 212, "TM" => 213, "TN" => 214, "TO" => 215,
106
- "TL" => 216, "TR" => 217, "TT" => 218, "TV" => 219, "TW" => 220, "TZ" => 221,
107
- "UA" => 222, "UG" => 223, "UM" => 224, "US" => 225, "UY" => 226, "UZ" => 227,
108
- "VA" => 228, "VC" => 229, "VE" => 230, "VG" => 231, "VI" => 232, "VN" => 233,
109
- "VU" => 234, "WF" => 235, "WS" => 236, "YE" => 237, "YT" => 238, "RS" => 239,
110
- "ZA" => 240, "ZM" => 241, "ME" => 242, "ZW" => 243, "A1" => 244, "A2" => 245,
111
- "O1" => 246, "AX" => 247, "GG" => 248, "IM" => 249, "JE" => 250, "BL" => 251,
112
- "MF" => 252
113
- );
114
 
115
- /**
116
- * Added for Chapagain_AutoCurrency Magento Module
117
- */
118
- var $GEOIP_COUNTRY_CODE_TO_CURRENCY = array(
119
- "EU" => "EUR", "AD" => "EUR", "AE" => "AED", "AF" => "AFN", "AG" => "XCD", "AI" => "XCD",
120
- "AL" => "ALL", "AM" => "AMD", "AN" => "ANG", "AO" => "AOA", "AR" => "ARS", "AS" => "EUR",
121
- "AT" => "EUR", "AU" => "AUD", "AW" => "AWG", "AZ" => "AZN", "BA" => "BAM", "BB" => "BBD",
122
- "BD" => "BDT", "BE" => "EUR", "BF" => "XOF", "BG" => "BGL", "BH" => "BHD", "BI" => "BIF",
123
- "BJ" => "XOF", "BM" => "BMD", "BN" => "BND", "BO" => "BOB", "BR" => "BRL", "BS" => "BSD",
124
- "BT" => "BTN", "BV" => "NOK", "BW" => "BWP", "BY" => "BYR", "BZ" => "BZD", "CA" => "CAD",
125
- "CC" => "AUD", "CD" => "CDF", "CF" => "XAF", "CG" => "XAF", "CH" => "CHF", "CI" => "XOF",
126
- "CK" => "NZD", "CL" => "CLP", "CM" => "XAF", "CN" => "CNY", "CO" => "COP", "CR" => "CRC",
127
- "CU" => "CUP", "CV" => "CVE", "CX" => "AUD", "CY" => "EUR", "CZ" => "CZK", "DE" => "EUR",
128
- "DJ" => "DJF", "DK" => "DKK", "DM" => "XCD", "DO" => "DOP", "DZ" => "DZD", "EC" => "ECS",
129
- "EE" => "EEK", "EG" => "EGP", "EH" => "MAD", "ER" => "ETB", "ES" => "EUR", "ET" => "ETB",
130
- "FI" => "EUR", "FJ" => "FJD", "FK" => "FKP", "FM" => "USD", "FO" => "DKK", "FR" => "EUR",
131
- "GA" => "XAF", "GB" => "GBP", "GD" => "XCD", "GE" => "GEL", "GF" => "EUR", "GH" => "GHS",
132
- "GI" => "GIP", "GL" => "DKK", "GM" => "GMD", "GN" => "GNF", "GP" => "EUR", "GQ" => "XAF",
133
- "GR" => "EUR", "GS" => "GBP", "GT" => "GTQ", "GU" => "USD", "GW" => "XOF", "GY" => "GYD",
134
- "HK" => "HKD", "HM" => "AUD", "HN" => "HNL", "HR" => "HRK", "HT" => "HTG", "HU" => "HUF",
135
- "ID" => "IDR", "IE" => "EUR", "IL" => "ILS", "IN" => "INR", "IO" => "USD", "IQ" => "IQD",
136
- "IR" => "IRR", "IS" => "ISK", "IT" => "EUR", "JM" => "JMD", "JO" => "JOD", "JP" => "JPY",
137
- "KE" => "KES", "KG" => "KGS", "KH" => "KHR", "KI" => "AUD", "KM" => "KMF", "KN" => "XCD",
138
- "KP" => "KPW", "KR" => "KRW", "KW" => "KWD", "KY" => "KYD", "KZ" => "KZT", "LA" => "LAK",
139
- "LB" => "LBP", "LC" => "XCD", "LI" => "CHF", "LK" => "LKR", "LR" => "LRD", "LS" => "LSL",
140
- "LT" => "LTL", "LU" => "EUR", "LV" => "LVL", "LY" => "LYD", "MA" => "MAD", "MC" => "EUR",
141
- "MD" => "MDL", "MG" => "MGF", "MH" => "USD", "MK" => "MKD", "ML" => "XOF", "MM" => "MMK",
142
- "MN" => "MNT", "MO" => "MOP", "MP" => "USD", "MQ" => "EUR", "MR" => "MRO", "MS" => "XCD",
143
- "MT" => "EUR", "MU" => "MUR", "MV" => "MVR", "MW" => "MWK", "MX" => "MXN", "MY" => "MYR",
144
- "MZ" => "MZN", "NA" => "NAD", "NC" => "XPF", "NE" => "XOF", "NF" => "AUD", "NG" => "NGN",
145
- "NI" => "NIO", "NL" => "EUR", "NO" => "NOK", "NP" => "NPR", "NR" => "AUD", "NU" => "NZD",
146
- "NZ" => "NZD", "OM" => "OMR", "PA" => "PAB", "PE" => "PEN", "PF" => "XPF", "PG" => "PGK",
147
- "PH" => "PHP", "PK" => "PKR", "PL" => "PLN", "PN" => "NZD", "PR" => "USD", "PT" => "EUR",
148
- "PW" => "USD", "PY" => "PYG", "QA" => "QAR", "RE" => "EUR", "RO" => "RON", "RU" => "RUB",
149
- "RW" => "RWF", "SA" => "SAR", "SB" => "SBD", "SC" => "SCR", "SD" => "SDD", "SE" => "SEK",
150
- "SG" => "SGD", "SH" => "SHP", "SI" => "EUR", "SJ" => "NOK", "SK" => "SKK", "SL" => "SLL",
151
- "SM" => "EUR", "SN" => "XOF", "SO" => "SOS", "SR" => "SRG", "ST" => "STD", "SV" => "SVC",
152
- "SY" => "SYP", "SZ" => "SZL", "TC" => "USD", "TD" => "XAF", "TF" => "EUR", "TG" => "XOF",
153
- "TH" => "THB", "TJ" => "TJS", "TK" => "NZD", "TM" => "TMM", "TN" => "TND", "TO" => "TOP",
154
- "TR" => "TRY", "TT" => "TTD", "TV" => "AUD", "TW" => "TWD", "TZ" => "TZS", "UA" => "UAH",
155
- "UG" => "UGX", "UM" => "USD", "US" => "USD", "UY" => "UYU", "UZ" => "UZS", "VA" => "EUR",
156
- "VC" => "XCD", "VE" => "VEF", "VG" => "USD", "VI" => "USD", "VN" => "VND", "VU" => "VUV",
157
- "WF" => "XPF", "WS" => "EUR", "YE" => "YER", "YT" => "EUR", "ZA" => "ZAR", "ZM" => "ZMK", "ZW" => "ZWD"
158
- );
159
 
160
- /**
161
- * Chapagain_Autocurrency
162
- * Some currency codes were old/outdated
163
- */
164
- var $GEOIP_COUNTRY_CODE_TO_CURRENCY_OLD = array(
165
- "EU" => "EUR", "AD" => "EUR", "AE" => "AED", "AF" => "AFN",
166
- "AG" => "XCD", "AI" => "XCD", "AL" => "ALL", "AM" => "AMD", "AN" => "ANG", "AO" => "AOK",
167
- "AR" => "ARP", "AS" => "EUR", "AT" => "EUR", "AU" => "AUD", "AW" => "ANG",
168
- "AZ" => "AZM", "BA" => "BAK", "BB" => "BBD", "BD" => "BDT", "BE" => "EUR", "BF" => "XOF",
169
- "BG" => "BGL", "BH" => "BHD", "BI" => "BIF", "BJ" => "XOF", "BM" => "BMD", "BN" => "BND",
170
- "BO" => "BOB", "BR" => "BRR", "BS" => "BSD", "BT" => "INR", "BV" => "NOK", "BW" => "BWP",
171
- "BY" => "BYR", "BZ" => "BZD", "CA" => "CAD", "CC" => "AUD", "CD" => "CDF", "CF" => "XAF",
172
- "CG" => "XAF", "CH" => "CHF", "CI" => "XOF", "CK" => "NZD", "CL" => "CLP", "CM" => "XAF",
173
- "CN" => "CNY", "CO" => "COP", "CR" => "CRC", "CU" => "CUP", "CV" => "CVE", "CX" => "AUD",
174
- "CY" => "CYP", "CZ" => "CSK", "DE" => "EUR", "DJ" => "DJF", "DK" => "DKK", "DM" => "XCD",
175
- "DO" => "DOP", "DZ" => "DZD", "EC" => "ECS", "EE" => "EEK", "EG" => "EGP", "EH" => "MAD",
176
- "ER" => "ETB", "ES" => "EUR", "ET" => "ETB", "FI" => "EUR", "FJ" => "FJD", "FK" => "FKP",
177
- "FM" => "USD", "FO" => "DKK", "FR" => "EUR", "GA" => "XAF", "GB" => "GBP",
178
- "GD" => "XCD", "GE" => "GEL", "GF" => "EUR", "GH" => "GHC", "GI" => "GIP", "GL" => "DKK",
179
- "GM" => "GMD", "GN" => "GNF", "GP" => "EUR", "GQ" => "XAF", "GR" => "EUR", "GS" => "GBP",
180
- "GT" => "GTQ", "GU" => "USD", "GW" => "XOF", "GY" => "GYD", "HK" => "HKD", "HM" => "AUD",
181
- "HN" => "HNL", "HR" => "HRK", "HT" => "HTG", "HU" => "HUF", "ID" => "IDR", "IE" => "EUR",
182
- "IL" => "ILS", "IN" => "INR", "IO" => "USD", "IQ" => "IQD", "IR" => "IRR", "IS" => "ISK",
183
- "IT" => "EUR", "JM" => "JMD", "JO" => "JOD", "JP" => "JPY", "KE" => "KES", "KG" => "KGS",
184
- "KH" => "KHR", "KI" => "AUD", "KM" => "KMF", "KN" => "XCD", "KP" => "KPW", "KR" => "KRW",
185
- "KW" => "KWD", "KY" => "KYD", "KZ" => "KZT", "LA" => "LAK", "LB" => "LBP", "LC" => "XCD",
186
- "LI" => "CHF", "LK" => "LKR", "LR" => "LRD", "LS" => "LSL", "LT" => "LTL", "LU" => "EUR",
187
- "LV" => "LVL", "LY" => "LYD", "MA" => "MAD", "MC" => "EUR", "MD" => "MDL", "MG" => "MGF",
188
- "MH" => "USD", "MK" => "MKD", "ML" => "XOF", "MM" => "MMK", "MN" => "MNT", "MO" => "MOP",
189
- "MP" => "USD", "MQ" => "EUR", "MR" => "MRO", "MS" => "XCD", "MT" => "MTL", "MU" => "MUR",
190
- "MV" => "MVR", "MW" => "MWK", "MX" => "MXP", "MY" => "MYR", "MZ" => "MZM", "NA" => "NAD",
191
- "NC" => "XPF", "NE" => "XOF", "NF" => "AUD", "NG" => "NGN", "NI" => "NIO", "NL" => "EUR",
192
- "NO" => "NOK", "NP" => "NPR", "NR" => "AUD", "NU" => "NZD", "NZ" => "NZD", "OM" => "OMR",
193
- "PA" => "PAB", "PE" => "PEN", "PF" => "XPF", "PG" => "PGK", "PH" => "PHP", "PK" => "PKR",
194
- "PL" => "PLZ", "PN" => "NZD", "PR" => "USD", "PT" => "EUR",
195
- "PW" => "USD", "PY" => "PYG", "QA" => "QAR", "RE" => "EUR", "RO" => "ROL", "RU" => "RUR",
196
- "RW" => "RWF", "SA" => "SAR", "SB" => "SBD", "SC" => "SCR", "SD" => "SDD", "SE" => "SEK",
197
- "SG" => "SGD", "SH" => "SHP", "SI" => "EUR", "SJ" => "NOK", "SK" => "SKK", "SL" => "SLL",
198
- "SM" => "EUR", "SN" => "XOF", "SO" => "SOS", "SR" => "SRG", "ST" => "STD", "SV" => "SVC",
199
- "SY" => "SYP", "SZ" => "SZL", "TC" => "USD", "TD" => "XAF", "TF" => "EUR", "TG" => "XOF",
200
- "TH" => "THB", "TJ" => "TJR", "TK" => "NZD", "TM" => "TMM", "TN" => "TND", "TO" => "TOP",
201
- "TR" => "TRL", "TT" => "TTD", "TV" => "AUD", "TW" => "TWD", "TZ" => "TZS",
202
- "UA" => "UAH", "UG" => "UGX", "UM" => "USD", "US" => "USD", "UY" => "UYU", "UZ" => "UZS",
203
- "VA" => "EUR", "VC" => "XCD", "VE" => "VEB", "VG" => "USD", "VI" => "USD", "VN" => "VND",
204
- "VU" => "VUV", "WF" => "XPF", "WS" => "EUR", "YE" => "YER", "YT" => "EUR",
205
- "ZA" => "ZAR", "ZM" => "ZMK", "ZW" => "ZWD"
206
- );
207
-
208
- var $GEOIP_COUNTRY_CODES = array(
209
- "", "AP", "EU", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ",
210
- "AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH",
211
- "BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
212
- "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
213
- "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
214
- "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB",
215
- "GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT",
216
- "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN",
217
- "IO", "IQ", "IR", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
218
- "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS",
219
- "LT", "LU", "LV", "LY", "MA", "MC", "MD", "MG", "MH", "MK", "ML", "MM", "MN",
220
- "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA",
221
- "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA",
222
- "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
223
- "QA", "RE", "RO", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI",
224
- "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD",
225
- "TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TL", "TR", "TT", "TV", "TW",
226
- "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN",
227
- "VU", "WF", "WS", "YE", "YT", "RS", "ZA", "ZM", "ME", "ZW", "A1", "A2", "O1",
228
- "AX", "GG", "IM", "JE", "BL", "MF"
229
- );
230
- var $GEOIP_COUNTRY_CODES3 = array(
231
- "","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","ATA","ARG",
232
- "ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI",
233
- "BEN","BMU","BRN","BOL","BRA","BHS","BTN","BVT","BWA","BLR","BLZ","CAN","CCK",
234
- "COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV",
235
- "CXR","CYP","CZE","DEU","DJI","DNK","DMA","DOM","DZA","ECU","EST","EGY","ESH",
236
- "ERI","ESP","ETH","FIN","FJI","FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD",
237
- "GEO","GUF","GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","SGS","GTM","GUM",
238
- "GNB","GUY","HKG","HMD","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IOT",
239
- "IRQ","IRN","ISL","ITA","JAM","JOR","JPN","KEN","KGZ","KHM","KIR","COM","KNA",
240
- "PRK","KOR","KWT","CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU",
241
- "LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI","MMR","MNG","MAC",
242
- "MNP","MTQ","MRT","MSR","MLT","MUS","MDV","MWI","MEX","MYS","MOZ","NAM","NCL",
243
- "NER","NFK","NGA","NIC","NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER",
244
- "PYF","PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW","PRY","QAT",
245
- "REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN","SWE","SGP","SHN","SVN","SJM",
246
- "SVK","SLE","SMR","SEN","SOM","SUR","STP","SLV","SYR","SWZ","TCA","TCD","ATF",
247
- "TGO","THA","TJK","TKL","TKM","TUN","TON","TLS","TUR","TTO","TUV","TWN","TZA",
248
- "UKR","UGA","UMI","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT",
249
- "WLF","WSM","YEM","MYT","SRB","ZAF","ZMB","MNE","ZWE","A1","A2","O1",
250
- "ALA","GGY","IMN","JEY","BLM","MAF"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  );
252
- var $GEOIP_COUNTRY_NAMES = array(
253
- "", "Asia/Pacific Region", "Europe", "Andorra", "United Arab Emirates",
254
- "Afghanistan", "Antigua and Barbuda", "Anguilla", "Albania", "Armenia",
255
- "Netherlands Antilles", "Angola", "Antarctica", "Argentina", "American Samoa",
256
- "Austria", "Australia", "Aruba", "Azerbaijan", "Bosnia and Herzegovina",
257
- "Barbados", "Bangladesh", "Belgium", "Burkina Faso", "Bulgaria", "Bahrain",
258
- "Burundi", "Benin", "Bermuda", "Brunei Darussalam", "Bolivia", "Brazil",
259
- "Bahamas", "Bhutan", "Bouvet Island", "Botswana", "Belarus", "Belize",
260
- "Canada", "Cocos (Keeling) Islands", "Congo, The Democratic Republic of the",
261
- "Central African Republic", "Congo", "Switzerland", "Cote D'Ivoire", "Cook Islands",
262
- "Chile", "Cameroon", "China", "Colombia", "Costa Rica", "Cuba", "Cape Verde",
263
- "Christmas Island", "Cyprus", "Czech Republic", "Germany", "Djibouti",
264
- "Denmark", "Dominica", "Dominican Republic", "Algeria", "Ecuador", "Estonia",
265
- "Egypt", "Western Sahara", "Eritrea", "Spain", "Ethiopia", "Finland", "Fiji",
266
- "Falkland Islands (Malvinas)", "Micronesia, Federated States of", "Faroe Islands",
267
- "France", "France, Metropolitan", "Gabon", "United Kingdom",
268
- "Grenada", "Georgia", "French Guiana", "Ghana", "Gibraltar", "Greenland",
269
- "Gambia", "Guinea", "Guadeloupe", "Equatorial Guinea", "Greece", "South Georgia and the South Sandwich Islands",
270
- "Guatemala", "Guam", "Guinea-Bissau",
271
- "Guyana", "Hong Kong", "Heard Island and McDonald Islands", "Honduras",
272
- "Croatia", "Haiti", "Hungary", "Indonesia", "Ireland", "Israel", "India",
273
- "British Indian Ocean Territory", "Iraq", "Iran, Islamic Republic of",
274
- "Iceland", "Italy", "Jamaica", "Jordan", "Japan", "Kenya", "Kyrgyzstan",
275
- "Cambodia", "Kiribati", "Comoros", "Saint Kitts and Nevis", "Korea, Democratic People's Republic of",
276
- "Korea, Republic of", "Kuwait", "Cayman Islands",
277
- "Kazakhstan", "Lao People's Democratic Republic", "Lebanon", "Saint Lucia",
278
- "Liechtenstein", "Sri Lanka", "Liberia", "Lesotho", "Lithuania", "Luxembourg",
279
- "Latvia", "Libyan Arab Jamahiriya", "Morocco", "Monaco", "Moldova, Republic of",
280
- "Madagascar", "Marshall Islands", "Macedonia",
281
- "Mali", "Myanmar", "Mongolia", "Macau", "Northern Mariana Islands",
282
- "Martinique", "Mauritania", "Montserrat", "Malta", "Mauritius", "Maldives",
283
- "Malawi", "Mexico", "Malaysia", "Mozambique", "Namibia", "New Caledonia",
284
- "Niger", "Norfolk Island", "Nigeria", "Nicaragua", "Netherlands", "Norway",
285
- "Nepal", "Nauru", "Niue", "New Zealand", "Oman", "Panama", "Peru", "French Polynesia",
286
- "Papua New Guinea", "Philippines", "Pakistan", "Poland", "Saint Pierre and Miquelon",
287
- "Pitcairn Islands", "Puerto Rico", "Palestinian Territory",
288
- "Portugal", "Palau", "Paraguay", "Qatar", "Reunion", "Romania",
289
- "Russian Federation", "Rwanda", "Saudi Arabia", "Solomon Islands",
290
- "Seychelles", "Sudan", "Sweden", "Singapore", "Saint Helena", "Slovenia",
291
- "Svalbard and Jan Mayen", "Slovakia", "Sierra Leone", "San Marino", "Senegal",
292
- "Somalia", "Suriname", "Sao Tome and Principe", "El Salvador", "Syrian Arab Republic",
293
- "Swaziland", "Turks and Caicos Islands", "Chad", "French Southern Territories",
294
- "Togo", "Thailand", "Tajikistan", "Tokelau", "Turkmenistan",
295
- "Tunisia", "Tonga", "Timor-Leste", "Turkey", "Trinidad and Tobago", "Tuvalu",
296
- "Taiwan", "Tanzania, United Republic of", "Ukraine",
297
- "Uganda", "United States Minor Outlying Islands", "United States", "Uruguay",
298
- "Uzbekistan", "Holy See (Vatican City State)", "Saint Vincent and the Grenadines",
299
- "Venezuela", "Virgin Islands, British", "Virgin Islands, U.S.",
300
- "Vietnam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte",
301
- "Serbia", "South Africa", "Zambia", "Montenegro", "Zimbabwe",
302
- "Anonymous Proxy","Satellite Provider","Other",
303
- "Aland Islands","Guernsey","Isle of Man","Jersey","Saint Barthelemy","Saint Martin"
304
- );
305
-
306
- var $GEOIP_CONTINENT_CODES = array(
307
- "--", "AS", "EU", "EU", "AS", "AS", "NA", "NA", "EU", "AS",
308
- "NA", "AF", "AN", "SA", "OC", "EU", "OC", "NA", "AS", "EU",
309
- "NA", "AS", "EU", "AF", "EU", "AS", "AF", "AF", "NA", "AS",
310
- "SA", "SA", "NA", "AS", "AN", "AF", "EU", "NA", "NA", "AS",
311
- "AF", "AF", "AF", "EU", "AF", "OC", "SA", "AF", "AS", "SA",
312
- "NA", "NA", "AF", "AS", "AS", "EU", "EU", "AF", "EU", "NA",
313
- "NA", "AF", "SA", "EU", "AF", "AF", "AF", "EU", "AF", "EU",
314
- "OC", "SA", "OC", "EU", "EU", "EU", "AF", "EU", "NA", "AS",
315
- "SA", "AF", "EU", "NA", "AF", "AF", "NA", "AF", "EU", "AN",
316
- "NA", "OC", "AF", "SA", "AS", "AN", "NA", "EU", "NA", "EU",
317
- "AS", "EU", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "NA",
318
- "AS", "AS", "AF", "AS", "AS", "OC", "AF", "NA", "AS", "AS",
319
- "AS", "NA", "AS", "AS", "AS", "NA", "EU", "AS", "AF", "AF",
320
- "EU", "EU", "EU", "AF", "AF", "EU", "EU", "AF", "OC", "EU",
321
- "AF", "AS", "AS", "AS", "OC", "NA", "AF", "NA", "EU", "AF",
322
- "AS", "AF", "NA", "AS", "AF", "AF", "OC", "AF", "OC", "AF",
323
- "NA", "EU", "EU", "AS", "OC", "OC", "OC", "AS", "NA", "SA",
324
- "OC", "OC", "AS", "AS", "EU", "NA", "OC", "NA", "AS", "EU",
325
- "OC", "SA", "AS", "AF", "EU", "EU", "AF", "AS", "OC", "AF",
326
- "AF", "EU", "AS", "AF", "EU", "EU", "EU", "AF", "EU", "AF",
327
- "AF", "SA", "AF", "NA", "AS", "AF", "NA", "AF", "AN", "AF",
328
- "AS", "AS", "OC", "AS", "AF", "OC", "AS", "EU", "NA", "OC",
329
- "AS", "AF", "EU", "AF", "OC", "NA", "SA", "AS", "EU", "NA",
330
- "SA", "NA", "NA", "AS", "OC", "OC", "OC", "AS", "AF", "EU",
331
- "AF", "AF", "EU", "AF", "--", "--", "--", "EU", "EU", "EU",
332
- "EU", "NA", "NA"
333
- );
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  }
336
- function geoip_load_shared_mem ($file) {
337
-
338
- $fp = fopen($file, "rb");
339
- if (!$fp) {
340
- print "error opening $file: $php_errormsg\n";
341
- exit;
342
- }
343
- $s_array = fstat($fp);
344
- $size = $s_array['size'];
345
- if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) {
346
- shmop_delete ($shmid);
347
- shmop_close ($shmid);
348
- }
349
- $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size);
350
- shmop_write ($shmid, fread($fp, $size), 0);
351
- shmop_close ($shmid);
 
352
  }
353
 
354
- function _setup_segments($gi){
355
- $gi->databaseType = GEOIP_COUNTRY_EDITION;
356
- $gi->record_length = STANDARD_RECORD_LENGTH;
357
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
358
- $offset = @shmop_size ($gi->shmid) - 3;
359
- for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
360
- $delim = @shmop_read ($gi->shmid, $offset, 3);
361
- $offset += 3;
362
- if ($delim == (chr(255).chr(255).chr(255))) {
363
- $gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1));
364
- $offset++;
365
-
366
- if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
367
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
368
- } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
369
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
370
- } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)||
371
- ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
 
 
 
 
372
  || ($gi->databaseType == GEOIP_ORG_EDITION)
 
373
  || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
374
- || ($gi->databaseType == GEOIP_ISP_EDITION)
375
- || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
376
- || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
377
- || ($gi->databaseType == GEOIP_ASNUM_EDITION)){
378
- $gi->databaseSegments = 0;
379
- $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
380
- for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
381
- $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
382
- }
383
- if (($gi->databaseType == GEOIP_ORG_EDITION)
 
 
 
 
 
 
 
 
 
 
 
384
  || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
385
- || ($gi->databaseType == GEOIP_ISP_EDITION)) {
386
- $gi->record_length = ORG_RECORD_LENGTH;
 
 
 
 
387
  }
 
 
 
388
  }
389
- break;
390
- } else {
391
- $offset -= 4;
392
  }
393
- }
394
- if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
395
- ($gi->databaseType == GEOIP_PROXY_EDITION)||
396
- ($gi->databaseType == GEOIP_NETSPEED_EDITION)){
397
- $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
398
- }
399
- } else {
400
- $filepos = ftell($gi->filehandle);
401
- fseek($gi->filehandle, -3, SEEK_END);
402
- for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
403
- $delim = fread($gi->filehandle,3);
404
- if ($delim == (chr(255).chr(255).chr(255))){
405
- $gi->databaseType = ord(fread($gi->filehandle,1));
406
- if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
407
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
408
  }
409
- else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){
410
- $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
411
- } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
412
- || ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
413
- || ($gi->databaseType == GEOIP_ORG_EDITION)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
415
- || ($gi->databaseType == GEOIP_ISP_EDITION)
416
- || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
417
- || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
418
- || ($gi->databaseType == GEOIP_ASNUM_EDITION)){
419
- $gi->databaseSegments = 0;
420
- $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH);
421
- for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){
422
- $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
423
- }
424
- if ( ( $gi->databaseType == GEOIP_ORG_EDITION )
425
- || ( $gi->databaseType == GEOIP_DOMAIN_EDITION )
426
- || ( $gi->databaseType == GEOIP_ISP_EDITION ) ) {
427
- $gi->record_length = ORG_RECORD_LENGTH;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  }
429
  }
430
- break;
431
- } else {
432
- fseek($gi->filehandle, -4, SEEK_CUR);
 
 
 
433
  }
 
434
  }
435
- if (($gi->databaseType == GEOIP_COUNTRY_EDITION)||
436
- ($gi->databaseType == GEOIP_PROXY_EDITION)||
437
- ($gi->databaseType == GEOIP_NETSPEED_EDITION)){
438
- $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
439
- }
440
- fseek($gi->filehandle,$filepos,SEEK_SET);
441
- }
442
- return $gi;
443
  }
444
 
445
- function geoip_open($filename, $flags) {
446
- $gi = new GeoIP;
447
- $gi->flags = $flags;
448
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
449
- $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0);
 
450
  } else {
451
- $gi->filehandle = fopen($filename,"rb") or die( "Can not open $filename\n" );
452
- if ($gi->flags & GEOIP_MEMORY_CACHE) {
453
- $s_array = fstat($gi->filehandle);
454
- $gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
 
455
  }
456
- }
457
 
458
- $gi = _setup_segments($gi);
459
- return $gi;
460
  }
461
 
462
- function geoip_close($gi) {
463
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
464
- return true;
465
- }
 
466
 
467
- return fclose($gi->filehandle);
468
  }
469
 
470
- function geoip_country_id_by_name($gi, $name) {
471
- $addr = gethostbyname($name);
472
- if (!$addr || $addr == $name) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
473
  return false;
474
- }
475
- return geoip_country_id_by_addr($gi, $addr);
476
  }
477
 
478
- function geoip_country_code_by_name($gi, $name) {
479
- $country_id = geoip_country_id_by_name($gi,$name);
480
- if ($country_id !== false) {
 
481
  return $gi->GEOIP_COUNTRY_CODES[$country_id];
482
- }
483
- return false;
484
  }
485
 
486
- function geoip_country_name_by_name($gi, $name) {
487
- $country_id = geoip_country_id_by_name($gi,$name);
488
- if ($country_id !== false) {
 
489
  return $gi->GEOIP_COUNTRY_NAMES[$country_id];
490
- }
491
- return false;
492
  }
493
 
494
- function geoip_country_id_by_addr($gi, $addr) {
495
- $ipnum = ip2long($addr);
496
- return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
 
 
 
 
497
  }
498
 
499
- function geoip_country_code_by_addr($gi, $addr) {
500
- if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
501
- $record = geoip_record_by_addr($gi,$addr);
502
- if ( $record !== false ) {
503
- return $record->country_code;
504
- }
505
- } else {
506
- $country_id = geoip_country_id_by_addr($gi,$addr);
 
 
 
 
 
 
 
507
  if ($country_id !== false) {
508
- return $gi->GEOIP_COUNTRY_CODES[$country_id];
509
  }
510
- }
511
- return false;
512
  }
513
 
514
- /**
515
- * Added for Chapagain_AutoCurrency Magento Module
516
- */
517
- function geoip_currency_code_by_country_code($gi, $code) {
518
- return $gi->GEOIP_COUNTRY_CODE_TO_CURRENCY[$code];
 
 
 
 
 
 
 
 
 
519
  }
520
 
521
- function geoip_country_name_by_addr($gi, $addr) {
522
- if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
523
- $record = geoip_record_by_addr($gi,$addr);
524
- return $record->country_name;
525
- } else {
526
- $country_id = geoip_country_id_by_addr($gi,$addr);
527
  if ($country_id !== false) {
528
- return $gi->GEOIP_COUNTRY_NAMES[$country_id];
529
  }
530
- }
531
- return false;
532
  }
533
 
534
- function _geoip_seek_country($gi, $ipnum) {
535
- $offset = 0;
536
- for ($depth = 31; $depth >= 0; --$depth) {
537
- if ($gi->flags & GEOIP_MEMORY_CACHE) {
538
- // workaround php's broken substr, strpos, etc handling with
539
- // mbstring.func_overload and mbstring.internal_encoding
540
- $enc = mb_internal_encoding();
541
- mb_internal_encoding('ISO-8859-1');
542
-
543
- $buf = substr($gi->memory_buffer,
544
- 2 * $gi->record_length * $offset,
545
- 2 * $gi->record_length);
546
-
547
- mb_internal_encoding($enc);
548
- } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
549
- $buf = @shmop_read ($gi->shmid,
550
- 2 * $gi->record_length * $offset,
551
- 2 * $gi->record_length );
552
- } else {
553
- fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
554
- or die("fseek failed");
555
- $buf = fread($gi->filehandle, 2 * $gi->record_length);
556
  }
557
- $x = array(0,0);
558
- for ($i = 0; $i < 2; ++$i) {
559
- for ($j = 0; $j < $gi->record_length; ++$j) {
560
- $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
561
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  }
563
- if ($ipnum & (1 << $depth)) {
564
- if ($x[1] >= $gi->databaseSegments) {
565
- return $x[1];
566
- }
567
- $offset = $x[1];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  } else {
569
- if ($x[0] >= $gi->databaseSegments) {
570
- return $x[0];
571
- }
572
- $offset = $x[0];
 
573
  }
574
- }
575
- trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
576
- return false;
577
  }
578
 
579
- function _get_org($gi,$ipnum){
580
- $seek_org = _geoip_seek_country($gi,$ipnum);
581
- if ($seek_org == $gi->databaseSegments) {
582
- return NULL;
583
- }
584
- $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
585
- if ($gi->flags & GEOIP_SHARED_MEMORY) {
586
- $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
587
  } else {
588
- fseek($gi->filehandle, $record_pointer, SEEK_SET);
589
- $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH);
590
- }
591
- // workaround php's broken substr, strpos, etc handling with
592
- // mbstring.func_overload and mbstring.internal_encoding
593
- $enc = mb_internal_encoding();
594
- mb_internal_encoding('ISO-8859-1');
595
- $org_buf = substr($org_buf, 0, strpos($org_buf, "\0"));
596
- mb_internal_encoding($enc);
597
- return $org_buf;
598
  }
599
 
600
- function geoip_org_by_addr ($gi,$addr) {
601
- if ($addr == NULL) {
602
- return 0;
603
- }
604
- $ipnum = ip2long($addr);
605
- return _get_org($gi, $ipnum);
 
606
  }
607
 
608
- function _get_region($gi,$ipnum){
609
- if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){
610
- $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0;
611
- if ($seek_region >= 1000){
612
- $country_code = "US";
613
- $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65);
614
- } else {
615
- $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
616
- $region = "";
617
  }
618
- return array ($country_code,$region);
619
- } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
620
- $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1;
621
- //print $seek_region;
622
- if ($seek_region < US_OFFSET){
623
- $country_code = "";
624
- $region = "";
625
- } else if ($seek_region < CANADA_OFFSET) {
626
- $country_code = "US";
627
- $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65);
628
- } else if ($seek_region < WORLD_OFFSET) {
629
- $country_code = "CA";
630
- $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65);
631
- } else {
632
- $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
633
- $region = "";
634
  }
635
- return array ($country_code,$region);
636
- }
637
  }
638
 
639
- function geoip_region_by_addr ($gi,$addr) {
640
- if ($addr == NULL) {
641
- return 0;
642
- }
643
- $ipnum = ip2long($addr);
644
- return _get_region($gi, $ipnum);
 
645
  }
646
 
647
- function getdnsattributes ($l,$ip){
648
- $r = new Net_DNS_Resolver();
649
- $r->nameservers = array("ws1.maxmind.com");
650
- $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN");
651
- $str = is_object($p->answer[0])?$p->answer[0]->string():'';
652
- ereg("\"(.*)\"",$str,$regs);
653
- $str = $regs[1];
654
- return $str;
655
  }
656
 
657
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
 
3
  /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
4
  /* geoip.inc
28
  define("GEOIP_SHARED_MEMORY", 2);
29
  define("STRUCTURE_INFO_MAX_SIZE", 20);
30
  define("DATABASE_INFO_MAX_SIZE", 100);
31
+ define("GEOIP_COUNTRY_EDITION", 1);
32
  define("GEOIP_PROXY_EDITION", 8);
33
  define("GEOIP_ASNUM_EDITION", 9);
34
  define("GEOIP_NETSPEED_EDITION", 10);
35
+ define("GEOIP_REGION_EDITION_REV0", 7);
36
  define("GEOIP_REGION_EDITION_REV1", 3);
37
+ define("GEOIP_CITY_EDITION_REV0", 6);
38
  define("GEOIP_CITY_EDITION_REV1", 2);
39
+ define("GEOIP_ORG_EDITION", 5);
40
  define("GEOIP_ISP_EDITION", 4);
41
  define("SEGMENT_RECORD_LENGTH", 3);
42
  define("STANDARD_RECORD_LENGTH", 3);
53
  define("GEOIP_CABLEDSL_SPEED", 2);
54
  define("GEOIP_CORPORATE_SPEED", 3);
55
  define("GEOIP_DOMAIN_EDITION", 11);
56
+ define("GEOIP_COUNTRY_EDITION_V6", 12);
57
  define("GEOIP_LOCATIONA_EDITION", 13);
58
  define("GEOIP_ACCURACYRADIUS_EDITION", 14);
59
  define("GEOIP_CITYCOMBINED_EDITION", 15);
60
+ define("GEOIP_CITY_EDITION_REV1_V6", 30);
61
+ define("GEOIP_CITY_EDITION_REV0_V6", 31);
62
+ define("GEOIP_NETSPEED_EDITION_REV1", 32);
63
+ define("GEOIP_NETSPEED_EDITION_REV1_V6", 33);
64
+ define("GEOIP_USERTYPE_EDITION", 28);
65
+ define("GEOIP_USERTYPE_EDITION_V6", 29);
66
+ define("GEOIP_ASNUM_EDITION_V6", 21);
67
+ define("GEOIP_ISP_EDITION_V6", 22);
68
+ define("GEOIP_ORG_EDITION_V6", 23);
69
+ define("GEOIP_DOMAIN_EDITION_V6", 24);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ define("CITYCOMBINED_FIXED_RECORD", 7);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
+ class GeoIP
74
+ {
75
+ public $flags;
76
+ public $filehandle;
77
+ public $memory_buffer;
78
+ public $databaseType;
79
+ public $databaseSegments;
80
+ public $record_length;
81
+ public $shmid;
82
+ public $GEOIP_COUNTRY_CODE_TO_NUMBER = array(
83
+ "" => 0,
84
+ "AP" => 1,
85
+ "EU" => 2,
86
+ "AD" => 3,
87
+ "AE" => 4,
88
+ "AF" => 5,
89
+ "AG" => 6,
90
+ "AI" => 7,
91
+ "AL" => 8,
92
+ "AM" => 9,
93
+ "CW" => 10,
94
+ "AO" => 11,
95
+ "AQ" => 12,
96
+ "AR" => 13,
97
+ "AS" => 14,
98
+ "AT" => 15,
99
+ "AU" => 16,
100
+ "AW" => 17,
101
+ "AZ" => 18,
102
+ "BA" => 19,
103
+ "BB" => 20,
104
+ "BD" => 21,
105
+ "BE" => 22,
106
+ "BF" => 23,
107
+ "BG" => 24,
108
+ "BH" => 25,
109
+ "BI" => 26,
110
+ "BJ" => 27,
111
+ "BM" => 28,
112
+ "BN" => 29,
113
+ "BO" => 30,
114
+ "BR" => 31,
115
+ "BS" => 32,
116
+ "BT" => 33,
117
+ "BV" => 34,
118
+ "BW" => 35,
119
+ "BY" => 36,
120
+ "BZ" => 37,
121
+ "CA" => 38,
122
+ "CC" => 39,
123
+ "CD" => 40,
124
+ "CF" => 41,
125
+ "CG" => 42,
126
+ "CH" => 43,
127
+ "CI" => 44,
128
+ "CK" => 45,
129
+ "CL" => 46,
130
+ "CM" => 47,
131
+ "CN" => 48,
132
+ "CO" => 49,
133
+ "CR" => 50,
134
+ "CU" => 51,
135
+ "CV" => 52,
136
+ "CX" => 53,
137
+ "CY" => 54,
138
+ "CZ" => 55,
139
+ "DE" => 56,
140
+ "DJ" => 57,
141
+ "DK" => 58,
142
+ "DM" => 59,
143
+ "DO" => 60,
144
+ "DZ" => 61,
145
+ "EC" => 62,
146
+ "EE" => 63,
147
+ "EG" => 64,
148
+ "EH" => 65,
149
+ "ER" => 66,
150
+ "ES" => 67,
151
+ "ET" => 68,
152
+ "FI" => 69,
153
+ "FJ" => 70,
154
+ "FK" => 71,
155
+ "FM" => 72,
156
+ "FO" => 73,
157
+ "FR" => 74,
158
+ "SX" => 75,
159
+ "GA" => 76,
160
+ "GB" => 77,
161
+ "GD" => 78,
162
+ "GE" => 79,
163
+ "GF" => 80,
164
+ "GH" => 81,
165
+ "GI" => 82,
166
+ "GL" => 83,
167
+ "GM" => 84,
168
+ "GN" => 85,
169
+ "GP" => 86,
170
+ "GQ" => 87,
171
+ "GR" => 88,
172
+ "GS" => 89,
173
+ "GT" => 90,
174
+ "GU" => 91,
175
+ "GW" => 92,
176
+ "GY" => 93,
177
+ "HK" => 94,
178
+ "HM" => 95,
179
+ "HN" => 96,
180
+ "HR" => 97,
181
+ "HT" => 98,
182
+ "HU" => 99,
183
+ "ID" => 100,
184
+ "IE" => 101,
185
+ "IL" => 102,
186
+ "IN" => 103,
187
+ "IO" => 104,
188
+ "IQ" => 105,
189
+ "IR" => 106,
190
+ "IS" => 107,
191
+ "IT" => 108,
192
+ "JM" => 109,
193
+ "JO" => 110,
194
+ "JP" => 111,
195
+ "KE" => 112,
196
+ "KG" => 113,
197
+ "KH" => 114,
198
+ "KI" => 115,
199
+ "KM" => 116,
200
+ "KN" => 117,
201
+ "KP" => 118,
202
+ "KR" => 119,
203
+ "KW" => 120,
204
+ "KY" => 121,
205
+ "KZ" => 122,
206
+ "LA" => 123,
207
+ "LB" => 124,
208
+ "LC" => 125,
209
+ "LI" => 126,
210
+ "LK" => 127,
211
+ "LR" => 128,
212
+ "LS" => 129,
213
+ "LT" => 130,
214
+ "LU" => 131,
215
+ "LV" => 132,
216
+ "LY" => 133,
217
+ "MA" => 134,
218
+ "MC" => 135,
219
+ "MD" => 136,
220
+ "MG" => 137,
221
+ "MH" => 138,
222
+ "MK" => 139,
223
+ "ML" => 140,
224
+ "MM" => 141,
225
+ "MN" => 142,
226
+ "MO" => 143,
227
+ "MP" => 144,
228
+ "MQ" => 145,
229
+ "MR" => 146,
230
+ "MS" => 147,
231
+ "MT" => 148,
232
+ "MU" => 149,
233
+ "MV" => 150,
234
+ "MW" => 151,
235
+ "MX" => 152,
236
+ "MY" => 153,
237
+ "MZ" => 154,
238
+ "NA" => 155,
239
+ "NC" => 156,
240
+ "NE" => 157,
241
+ "NF" => 158,
242
+ "NG" => 159,
243
+ "NI" => 160,
244
+ "NL" => 161,
245
+ "NO" => 162,
246
+ "NP" => 163,
247
+ "NR" => 164,
248
+ "NU" => 165,
249
+ "NZ" => 166,
250
+ "OM" => 167,
251
+ "PA" => 168,
252
+ "PE" => 169,
253
+ "PF" => 170,
254
+ "PG" => 171,
255
+ "PH" => 172,
256
+ "PK" => 173,
257
+ "PL" => 174,
258
+ "PM" => 175,
259
+ "PN" => 176,
260
+ "PR" => 177,
261
+ "PS" => 178,
262
+ "PT" => 179,
263
+ "PW" => 180,
264
+ "PY" => 181,
265
+ "QA" => 182,
266
+ "RE" => 183,
267
+ "RO" => 184,
268
+ "RU" => 185,
269
+ "RW" => 186,
270
+ "SA" => 187,
271
+ "SB" => 188,
272
+ "SC" => 189,
273
+ "SD" => 190,
274
+ "SE" => 191,
275
+ "SG" => 192,
276
+ "SH" => 193,
277
+ "SI" => 194,
278
+ "SJ" => 195,
279
+ "SK" => 196,
280
+ "SL" => 197,
281
+ "SM" => 198,
282
+ "SN" => 199,
283
+ "SO" => 200,
284
+ "SR" => 201,
285
+ "ST" => 202,
286
+ "SV" => 203,
287
+ "SY" => 204,
288
+ "SZ" => 205,
289
+ "TC" => 206,
290
+ "TD" => 207,
291
+ "TF" => 208,
292
+ "TG" => 209,
293
+ "TH" => 210,
294
+ "TJ" => 211,
295
+ "TK" => 212,
296
+ "TM" => 213,
297
+ "TN" => 214,
298
+ "TO" => 215,
299
+ "TL" => 216,
300
+ "TR" => 217,
301
+ "TT" => 218,
302
+ "TV" => 219,
303
+ "TW" => 220,
304
+ "TZ" => 221,
305
+ "UA" => 222,
306
+ "UG" => 223,
307
+ "UM" => 224,
308
+ "US" => 225,
309
+ "UY" => 226,
310
+ "UZ" => 227,
311
+ "VA" => 228,
312
+ "VC" => 229,
313
+ "VE" => 230,
314
+ "VG" => 231,
315
+ "VI" => 232,
316
+ "VN" => 233,
317
+ "VU" => 234,
318
+ "WF" => 235,
319
+ "WS" => 236,
320
+ "YE" => 237,
321
+ "YT" => 238,
322
+ "RS" => 239,
323
+ "ZA" => 240,
324
+ "ZM" => 241,
325
+ "ME" => 242,
326
+ "ZW" => 243,
327
+ "A1" => 244,
328
+ "A2" => 245,
329
+ "O1" => 246,
330
+ "AX" => 247,
331
+ "GG" => 248,
332
+ "IM" => 249,
333
+ "JE" => 250,
334
+ "BL" => 251,
335
+ "MF" => 252,
336
+ "BQ" => 253,
337
+ "SS" => 254
338
+ );
339
+
340
+ public $GEOIP_COUNTRY_CODES = array(
341
+ "",
342
+ "AP",
343
+ "EU",
344
+ "AD",
345
+ "AE",
346
+ "AF",
347
+ "AG",
348
+ "AI",
349
+ "AL",
350
+ "AM",
351
+ "CW",
352
+ "AO",
353
+ "AQ",
354
+ "AR",
355
+ "AS",
356
+ "AT",
357
+ "AU",
358
+ "AW",
359
+ "AZ",
360
+ "BA",
361
+ "BB",
362
+ "BD",
363
+ "BE",
364
+ "BF",
365
+ "BG",
366
+ "BH",
367
+ "BI",
368
+ "BJ",
369
+ "BM",
370
+ "BN",
371
+ "BO",
372
+ "BR",
373
+ "BS",
374
+ "BT",
375
+ "BV",
376
+ "BW",
377
+ "BY",
378
+ "BZ",
379
+ "CA",
380
+ "CC",
381
+ "CD",
382
+ "CF",
383
+ "CG",
384
+ "CH",
385
+ "CI",
386
+ "CK",
387
+ "CL",
388
+ "CM",
389
+ "CN",
390
+ "CO",
391
+ "CR",
392
+ "CU",
393
+ "CV",
394
+ "CX",
395
+ "CY",
396
+ "CZ",
397
+ "DE",
398
+ "DJ",
399
+ "DK",
400
+ "DM",
401
+ "DO",
402
+ "DZ",
403
+ "EC",
404
+ "EE",
405
+ "EG",
406
+ "EH",
407
+ "ER",
408
+ "ES",
409
+ "ET",
410
+ "FI",
411
+ "FJ",
412
+ "FK",
413
+ "FM",
414
+ "FO",
415
+ "FR",
416
+ "SX",
417
+ "GA",
418
+ "GB",
419
+ "GD",
420
+ "GE",
421
+ "GF",
422
+ "GH",
423
+ "GI",
424
+ "GL",
425
+ "GM",
426
+ "GN",
427
+ "GP",
428
+ "GQ",
429
+ "GR",
430
+ "GS",
431
+ "GT",
432
+ "GU",
433
+ "GW",
434
+ "GY",
435
+ "HK",
436
+ "HM",
437
+ "HN",
438
+ "HR",
439
+ "HT",
440
+ "HU",
441
+ "ID",
442
+ "IE",
443
+ "IL",
444
+ "IN",
445
+ "IO",
446
+ "IQ",
447
+ "IR",
448
+ "IS",
449
+ "IT",
450
+ "JM",
451
+ "JO",
452
+ "JP",
453
+ "KE",
454
+ "KG",
455
+ "KH",
456
+ "KI",
457
+ "KM",
458
+ "KN",
459
+ "KP",
460
+ "KR",
461
+ "KW",
462
+ "KY",
463
+ "KZ",
464
+ "LA",
465
+ "LB",
466
+ "LC",
467
+ "LI",
468
+ "LK",
469
+ "LR",
470
+ "LS",
471
+ "LT",
472
+ "LU",
473
+ "LV",
474
+ "LY",
475
+ "MA",
476
+ "MC",
477
+ "MD",
478
+ "MG",
479
+ "MH",
480
+ "MK",
481
+ "ML",
482
+ "MM",
483
+ "MN",
484
+ "MO",
485
+ "MP",
486
+ "MQ",
487
+ "MR",
488
+ "MS",
489
+ "MT",
490
+ "MU",
491
+ "MV",
492
+ "MW",
493
+ "MX",
494
+ "MY",
495
+ "MZ",
496
+ "NA",
497
+ "NC",
498
+ "NE",
499
+ "NF",
500
+ "NG",
501
+ "NI",
502
+ "NL",
503
+ "NO",
504
+ "NP",
505
+ "NR",
506
+ "NU",
507
+ "NZ",
508
+ "OM",
509
+ "PA",
510
+ "PE",
511
+ "PF",
512
+ "PG",
513
+ "PH",
514
+ "PK",
515
+ "PL",
516
+ "PM",
517
+ "PN",
518
+ "PR",
519
+ "PS",
520
+ "PT",
521
+ "PW",
522
+ "PY",
523
+ "QA",
524
+ "RE",
525
+ "RO",
526
+ "RU",
527
+ "RW",
528
+ "SA",
529
+ "SB",
530
+ "SC",
531
+ "SD",
532
+ "SE",
533
+ "SG",
534
+ "SH",
535
+ "SI",
536
+ "SJ",
537
+ "SK",
538
+ "SL",
539
+ "SM",
540
+ "SN",
541
+ "SO",
542
+ "SR",
543
+ "ST",
544
+ "SV",
545
+ "SY",
546
+ "SZ",
547
+ "TC",
548
+ "TD",
549
+ "TF",
550
+ "TG",
551
+ "TH",
552
+ "TJ",
553
+ "TK",
554
+ "TM",
555
+ "TN",
556
+ "TO",
557
+ "TL",
558
+ "TR",
559
+ "TT",
560
+ "TV",
561
+ "TW",
562
+ "TZ",
563
+ "UA",
564
+ "UG",
565
+ "UM",
566
+ "US",
567
+ "UY",
568
+ "UZ",
569
+ "VA",
570
+ "VC",
571
+ "VE",
572
+ "VG",
573
+ "VI",
574
+ "VN",
575
+ "VU",
576
+ "WF",
577
+ "WS",
578
+ "YE",
579
+ "YT",
580
+ "RS",
581
+ "ZA",
582
+ "ZM",
583
+ "ME",
584
+ "ZW",
585
+ "A1",
586
+ "A2",
587
+ "O1",
588
+ "AX",
589
+ "GG",
590
+ "IM",
591
+ "JE",
592
+ "BL",
593
+ "MF",
594
+ "BQ",
595
+ "SS",
596
+ "O1"
597
+ );
598
+
599
+ public $GEOIP_COUNTRY_CODES3 = array(
600
+ "",
601
+ "AP",
602
+ "EU",
603
+ "AND",
604
+ "ARE",
605
+ "AFG",
606
+ "ATG",
607
+ "AIA",
608
+ "ALB",
609
+ "ARM",
610
+ "CUW",
611
+ "AGO",
612
+ "ATA",
613
+ "ARG",
614
+ "ASM",
615
+ "AUT",
616
+ "AUS",
617
+ "ABW",
618
+ "AZE",
619
+ "BIH",
620
+ "BRB",
621
+ "BGD",
622
+ "BEL",
623
+ "BFA",
624
+ "BGR",
625
+ "BHR",
626
+ "BDI",
627
+ "BEN",
628
+ "BMU",
629
+ "BRN",
630
+ "BOL",
631
+ "BRA",
632
+ "BHS",
633
+ "BTN",
634
+ "BVT",
635
+ "BWA",
636
+ "BLR",
637
+ "BLZ",
638
+ "CAN",
639
+ "CCK",
640
+ "COD",
641
+ "CAF",
642
+ "COG",
643
+ "CHE",
644
+ "CIV",
645
+ "COK",
646
+ "CHL",
647
+ "CMR",
648
+ "CHN",
649
+ "COL",
650
+ "CRI",
651
+ "CUB",
652
+ "CPV",
653
+ "CXR",
654
+ "CYP",
655
+ "CZE",
656
+ "DEU",
657
+ "DJI",
658
+ "DNK",
659
+ "DMA",
660
+ "DOM",
661
+ "DZA",
662
+ "ECU",
663
+ "EST",
664
+ "EGY",
665
+ "ESH",
666
+ "ERI",
667
+ "ESP",
668
+ "ETH",
669
+ "FIN",
670
+ "FJI",
671
+ "FLK",
672
+ "FSM",
673
+ "FRO",
674
+ "FRA",
675
+ "SXM",
676
+ "GAB",
677
+ "GBR",
678
+ "GRD",
679
+ "GEO",
680
+ "GUF",
681
+ "GHA",
682
+ "GIB",
683
+ "GRL",
684
+ "GMB",
685
+ "GIN",
686
+ "GLP",
687
+ "GNQ",
688
+ "GRC",
689
+ "SGS",
690
+ "GTM",
691
+ "GUM",
692
+ "GNB",
693
+ "GUY",
694
+ "HKG",
695
+ "HMD",
696
+ "HND",
697
+ "HRV",
698
+ "HTI",
699
+ "HUN",
700
+ "IDN",
701
+ "IRL",
702
+ "ISR",
703
+ "IND",
704
+ "IOT",
705
+ "IRQ",
706
+ "IRN",
707
+ "ISL",
708
+ "ITA",
709
+ "JAM",
710
+ "JOR",
711
+ "JPN",
712
+ "KEN",
713
+ "KGZ",
714
+ "KHM",
715
+ "KIR",
716
+ "COM",
717
+ "KNA",
718
+ "PRK",
719
+ "KOR",
720
+ "KWT",
721
+ "CYM",
722
+ "KAZ",
723
+ "LAO",
724
+ "LBN",
725
+ "LCA",
726
+ "LIE",
727
+ "LKA",
728
+ "LBR",
729
+ "LSO",
730
+ "LTU",
731
+ "LUX",
732
+ "LVA",
733
+ "LBY",
734
+ "MAR",
735
+ "MCO",
736
+ "MDA",
737
+ "MDG",
738
+ "MHL",
739
+ "MKD",
740
+ "MLI",
741
+ "MMR",
742
+ "MNG",
743
+ "MAC",
744
+ "MNP",
745
+ "MTQ",
746
+ "MRT",
747
+ "MSR",
748
+ "MLT",
749
+ "MUS",
750
+ "MDV",
751
+ "MWI",
752
+ "MEX",
753
+ "MYS",
754
+ "MOZ",
755
+ "NAM",
756
+ "NCL",
757
+ "NER",
758
+ "NFK",
759
+ "NGA",
760
+ "NIC",
761
+ "NLD",
762
+ "NOR",
763
+ "NPL",
764
+ "NRU",
765
+ "NIU",
766
+ "NZL",
767
+ "OMN",
768
+ "PAN",
769
+ "PER",
770
+ "PYF",
771
+ "PNG",
772
+ "PHL",
773
+ "PAK",
774
+ "POL",
775
+ "SPM",
776
+ "PCN",
777
+ "PRI",
778
+ "PSE",
779
+ "PRT",
780
+ "PLW",
781
+ "PRY",
782
+ "QAT",
783
+ "REU",
784
+ "ROU",
785
+ "RUS",
786
+ "RWA",
787
+ "SAU",
788
+ "SLB",
789
+ "SYC",
790
+ "SDN",
791
+ "SWE",
792
+ "SGP",
793
+ "SHN",
794
+ "SVN",
795
+ "SJM",
796
+ "SVK",
797
+ "SLE",
798
+ "SMR",
799
+ "SEN",
800
+ "SOM",
801
+ "SUR",
802
+ "STP",
803
+ "SLV",
804
+ "SYR",
805
+ "SWZ",
806
+ "TCA",
807
+ "TCD",
808
+ "ATF",
809
+ "TGO",
810
+ "THA",
811
+ "TJK",
812
+ "TKL",
813
+ "TKM",
814
+ "TUN",
815
+ "TON",
816
+ "TLS",
817
+ "TUR",
818
+ "TTO",
819
+ "TUV",
820
+ "TWN",
821
+ "TZA",
822
+ "UKR",
823
+ "UGA",
824
+ "UMI",
825
+ "USA",
826
+ "URY",
827
+ "UZB",
828
+ "VAT",
829
+ "VCT",
830
+ "VEN",
831
+ "VGB",
832
+ "VIR",
833
+ "VNM",
834
+ "VUT",
835
+ "WLF",
836
+ "WSM",
837
+ "YEM",
838
+ "MYT",
839
+ "SRB",
840
+ "ZAF",
841
+ "ZMB",
842
+ "MNE",
843
+ "ZWE",
844
+ "A1",
845
+ "A2",
846
+ "O1",
847
+ "ALA",
848
+ "GGY",
849
+ "IMN",
850
+ "JEY",
851
+ "BLM",
852
+ "MAF",
853
+ "BES",
854
+ "SSD",
855
+ "O1"
856
+ );
857
+
858
+ public $GEOIP_COUNTRY_NAMES = array(
859
+ "",
860
+ "Asia/Pacific Region",
861
+ "Europe",
862
+ "Andorra",
863
+ "United Arab Emirates",
864
+ "Afghanistan",
865
+ "Antigua and Barbuda",
866
+ "Anguilla",
867
+ "Albania",
868
+ "Armenia",
869
+ "Curacao",
870
+ "Angola",
871
+ "Antarctica",
872
+ "Argentina",
873
+ "American Samoa",
874
+ "Austria",
875
+ "Australia",
876
+ "Aruba",
877
+ "Azerbaijan",
878
+ "Bosnia and Herzegovina",
879
+ "Barbados",
880
+ "Bangladesh",
881
+ "Belgium",
882
+ "Burkina Faso",
883
+ "Bulgaria",
884
+ "Bahrain",
885
+ "Burundi",
886
+ "Benin",
887
+ "Bermuda",
888
+ "Brunei Darussalam",
889
+ "Bolivia",
890
+ "Brazil",
891
+ "Bahamas",
892
+ "Bhutan",
893
+ "Bouvet Island",
894
+ "Botswana",
895
+ "Belarus",
896
+ "Belize",
897
+ "Canada",
898
+ "Cocos (Keeling) Islands",
899
+ "Congo, The Democratic Republic of the",
900
+ "Central African Republic",
901
+ "Congo",
902
+ "Switzerland",
903
+ "Cote D'Ivoire",
904
+ "Cook Islands",
905
+ "Chile",
906
+ "Cameroon",
907
+ "China",
908
+ "Colombia",
909
+ "Costa Rica",
910
+ "Cuba",
911
+ "Cape Verde",
912
+ "Christmas Island",
913
+ "Cyprus",
914
+ "Czech Republic",
915
+ "Germany",
916
+ "Djibouti",
917
+ "Denmark",
918
+ "Dominica",
919
+ "Dominican Republic",
920
+ "Algeria",
921
+ "Ecuador",
922
+ "Estonia",
923
+ "Egypt",
924
+ "Western Sahara",
925
+ "Eritrea",
926
+ "Spain",
927
+ "Ethiopia",
928
+ "Finland",
929
+ "Fiji",
930
+ "Falkland Islands (Malvinas)",
931
+ "Micronesia, Federated States of",
932
+ "Faroe Islands",
933
+ "France",
934
+ "Sint Maarten (Dutch part)",
935
+ "Gabon",
936
+ "United Kingdom",
937
+ "Grenada",
938
+ "Georgia",
939
+ "French Guiana",
940
+ "Ghana",
941
+ "Gibraltar",
942
+ "Greenland",
943
+ "Gambia",
944
+ "Guinea",
945
+ "Guadeloupe",
946
+ "Equatorial Guinea",
947
+ "Greece",
948
+ "South Georgia and the South Sandwich Islands",
949
+ "Guatemala",
950
+ "Guam",
951
+ "Guinea-Bissau",
952
+ "Guyana",
953
+ "Hong Kong",
954
+ "Heard Island and McDonald Islands",
955
+ "Honduras",
956
+ "Croatia",
957
+ "Haiti",
958
+ "Hungary",
959
+ "Indonesia",
960
+ "Ireland",
961
+ "Israel",
962
+ "India",
963
+ "British Indian Ocean Territory",
964
+ "Iraq",
965
+ "Iran, Islamic Republic of",
966
+ "Iceland",
967
+ "Italy",
968
+ "Jamaica",
969
+ "Jordan",
970
+ "Japan",
971
+ "Kenya",
972
+ "Kyrgyzstan",
973
+ "Cambodia",
974
+ "Kiribati",
975
+ "Comoros",
976
+ "Saint Kitts and Nevis",
977
+ "Korea, Democratic People's Republic of",
978
+ "Korea, Republic of",
979
+ "Kuwait",
980
+ "Cayman Islands",
981
+ "Kazakhstan",
982
+ "Lao People's Democratic Republic",
983
+ "Lebanon",
984
+ "Saint Lucia",
985
+ "Liechtenstein",
986
+ "Sri Lanka",
987
+ "Liberia",
988
+ "Lesotho",
989
+ "Lithuania",
990
+ "Luxembourg",
991
+ "Latvia",
992
+ "Libya",
993
+ "Morocco",
994
+ "Monaco",
995
+ "Moldova, Republic of",
996
+ "Madagascar",
997
+ "Marshall Islands",
998
+ "Macedonia",
999
+ "Mali",
1000
+ "Myanmar",
1001
+ "Mongolia",
1002
+ "Macau",
1003
+ "Northern Mariana Islands",
1004
+ "Martinique",
1005
+ "Mauritania",
1006
+ "Montserrat",
1007
+ "Malta",
1008
+ "Mauritius",
1009
+ "Maldives",
1010
+ "Malawi",
1011
+ "Mexico",
1012
+ "Malaysia",
1013
+ "Mozambique",
1014
+ "Namibia",
1015
+ "New Caledonia",
1016
+ "Niger",
1017
+ "Norfolk Island",
1018
+ "Nigeria",
1019
+ "Nicaragua",
1020
+ "Netherlands",
1021
+ "Norway",
1022
+ "Nepal",
1023
+ "Nauru",
1024
+ "Niue",
1025
+ "New Zealand",
1026
+ "Oman",
1027
+ "Panama",
1028
+ "Peru",
1029
+ "French Polynesia",
1030
+ "Papua New Guinea",
1031
+ "Philippines",
1032
+ "Pakistan",
1033
+ "Poland",
1034
+ "Saint Pierre and Miquelon",
1035
+ "Pitcairn Islands",
1036
+ "Puerto Rico",
1037
+ "Palestinian Territory",
1038
+ "Portugal",
1039
+ "Palau",
1040
+ "Paraguay",
1041
+ "Qatar",
1042
+ "Reunion",
1043
+ "Romania",
1044
+ "Russian Federation",
1045
+ "Rwanda",
1046
+ "Saudi Arabia",
1047
+ "Solomon Islands",
1048
+ "Seychelles",
1049
+ "Sudan",
1050
+ "Sweden",
1051
+ "Singapore",
1052
+ "Saint Helena",
1053
+ "Slovenia",
1054
+ "Svalbard and Jan Mayen",
1055
+ "Slovakia",
1056
+ "Sierra Leone",
1057
+ "San Marino",
1058
+ "Senegal",
1059
+ "Somalia",
1060
+ "Suriname",
1061
+ "Sao Tome and Principe",
1062
+ "El Salvador",
1063
+ "Syrian Arab Republic",
1064
+ "Swaziland",
1065
+ "Turks and Caicos Islands",
1066
+ "Chad",
1067
+ "French Southern Territories",
1068
+ "Togo",
1069
+ "Thailand",
1070
+ "Tajikistan",
1071
+ "Tokelau",
1072
+ "Turkmenistan",
1073
+ "Tunisia",
1074
+ "Tonga",
1075
+ "Timor-Leste",
1076
+ "Turkey",
1077
+ "Trinidad and Tobago",
1078
+ "Tuvalu",
1079
+ "Taiwan",
1080
+ "Tanzania, United Republic of",
1081
+ "Ukraine",
1082
+ "Uganda",
1083
+ "United States Minor Outlying Islands",
1084
+ "United States",
1085
+ "Uruguay",
1086
+ "Uzbekistan",
1087
+ "Holy See (Vatican City State)",
1088
+ "Saint Vincent and the Grenadines",
1089
+ "Venezuela",
1090
+ "Virgin Islands, British",
1091
+ "Virgin Islands, U.S.",
1092
+ "Vietnam",
1093
+ "Vanuatu",
1094
+ "Wallis and Futuna",
1095
+ "Samoa",
1096
+ "Yemen",
1097
+ "Mayotte",
1098
+ "Serbia",
1099
+ "South Africa",
1100
+ "Zambia",
1101
+ "Montenegro",
1102
+ "Zimbabwe",
1103
+ "Anonymous Proxy",
1104
+ "Satellite Provider",
1105
+ "Other",
1106
+ "Aland Islands",
1107
+ "Guernsey",
1108
+ "Isle of Man",
1109
+ "Jersey",
1110
+ "Saint Barthelemy",
1111
+ "Saint Martin",
1112
+ "Bonaire, Saint Eustatius and Saba",
1113
+ "South Sudan",
1114
+ "Other"
1115
+ );
1116
+
1117
+ public $GEOIP_CONTINENT_CODES = array(
1118
+ "--",
1119
+ "AS",
1120
+ "EU",
1121
+ "EU",
1122
+ "AS",
1123
+ "AS",
1124
+ "NA",
1125
+ "NA",
1126
+ "EU",
1127
+ "AS",
1128
+ "NA",
1129
+ "AF",
1130
+ "AN",
1131
+ "SA",
1132
+ "OC",
1133
+ "EU",
1134
+ "OC",
1135
+ "NA",
1136
+ "AS",
1137
+ "EU",
1138
+ "NA",
1139
+ "AS",
1140
+ "EU",
1141
+ "AF",
1142
+ "EU",
1143
+ "AS",
1144
+ "AF",
1145
+ "AF",
1146
+ "NA",
1147
+ "AS",
1148
+ "SA",
1149
+ "SA",
1150
+ "NA",
1151
+ "AS",
1152
+ "AN",
1153
+ "AF",
1154
+ "EU",
1155
+ "NA",
1156
+ "NA",
1157
+ "AS",
1158
+ "AF",
1159
+ "AF",
1160
+ "AF",
1161
+ "EU",
1162
+ "AF",
1163
+ "OC",
1164
+ "SA",
1165
+ "AF",
1166
+ "AS",
1167
+ "SA",
1168
+ "NA",
1169
+ "NA",
1170
+ "AF",
1171
+ "AS",
1172
+ "AS",
1173
+ "EU",
1174
+ "EU",
1175
+ "AF",
1176
+ "EU",
1177
+ "NA",
1178
+ "NA",
1179
+ "AF",
1180
+ "SA",
1181
+ "EU",
1182
+ "AF",
1183
+ "AF",
1184
+ "AF",
1185
+ "EU",
1186
+ "AF",
1187
+ "EU",
1188
+ "OC",
1189
+ "SA",
1190
+ "OC",
1191
+ "EU",
1192
+ "EU",
1193
+ "NA",
1194
+ "AF",
1195
+ "EU",
1196
+ "NA",
1197
+ "AS",
1198
+ "SA",
1199
+ "AF",
1200
+ "EU",
1201
+ "NA",
1202
+ "AF",
1203
+ "AF",
1204
+ "NA",
1205
+ "AF",
1206
+ "EU",
1207
+ "AN",
1208
+ "NA",
1209
+ "OC",
1210
+ "AF",
1211
+ "SA",
1212
+ "AS",
1213
+ "AN",
1214
+ "NA",
1215
+ "EU",
1216
+ "NA",
1217
+ "EU",
1218
+ "AS",
1219
+ "EU",
1220
+ "AS",
1221
+ "AS",
1222
+ "AS",
1223
+ "AS",
1224
+ "AS",
1225
+ "EU",
1226
+ "EU",
1227
+ "NA",
1228
+ "AS",
1229
+ "AS",
1230
+ "AF",
1231
+ "AS",
1232
+ "AS",
1233
+ "OC",
1234
+ "AF",
1235
+ "NA",
1236
+ "AS",
1237
+ "AS",
1238
+ "AS",
1239
+ "NA",
1240
+ "AS",
1241
+ "AS",
1242
+ "AS",
1243
+ "NA",
1244
+ "EU",
1245
+ "AS",
1246
+ "AF",
1247
+ "AF",
1248
+ "EU",
1249
+ "EU",
1250
+ "EU",
1251
+ "AF",
1252
+ "AF",
1253
+ "EU",
1254
+ "EU",
1255
+ "AF",
1256
+ "OC",
1257
+ "EU",
1258
+ "AF",
1259
+ "AS",
1260
+ "AS",
1261
+ "AS",
1262
+ "OC",
1263
+ "NA",
1264
+ "AF",
1265
+ "NA",
1266
+ "EU",
1267
+ "AF",
1268
+ "AS",
1269
+ "AF",
1270
+ "NA",
1271
+ "AS",
1272
+ "AF",
1273
+ "AF",
1274
+ "OC",
1275
+ "AF",
1276
+ "OC",
1277
+ "AF",
1278
+ "NA",
1279
+ "EU",
1280
+ "EU",
1281
+ "AS",
1282
+ "OC",
1283
+ "OC",
1284
+ "OC",
1285
+ "AS",
1286
+ "NA",
1287
+ "SA",
1288
+ "OC",
1289
+ "OC",
1290
+ "AS",
1291
+ "AS",
1292
+ "EU",
1293
+ "NA",
1294
+ "OC",
1295
+ "NA",
1296
+ "AS",
1297
+ "EU",
1298
+ "OC",
1299
+ "SA",
1300
+ "AS",
1301
+ "AF",
1302
+ "EU",
1303
+ "EU",
1304
+ "AF",
1305
+ "AS",
1306
+ "OC",
1307
+ "AF",
1308
+ "AF",
1309
+ "EU",
1310
+ "AS",
1311
+ "AF",
1312
+ "EU",
1313
+ "EU",
1314
+ "EU",
1315
+ "AF",
1316
+ "EU",
1317
+ "AF",
1318
+ "AF",
1319
+ "SA",
1320
+ "AF",
1321
+ "NA",
1322
+ "AS",
1323
+ "AF",
1324
+ "NA",
1325
+ "AF",
1326
+ "AN",
1327
+ "AF",
1328
+ "AS",
1329
+ "AS",
1330
+ "OC",
1331
+ "AS",
1332
+ "AF",
1333
+ "OC",
1334
+ "AS",
1335
+ "EU",
1336
+ "NA",
1337
+ "OC",
1338
+ "AS",
1339
+ "AF",
1340
+ "EU",
1341
+ "AF",
1342
+ "OC",
1343
+ "NA",
1344
+ "SA",
1345
+ "AS",
1346
+ "EU",
1347
+ "NA",
1348
+ "SA",
1349
+ "NA",
1350
+ "NA",
1351
+ "AS",
1352
+ "OC",
1353
+ "OC",
1354
+ "OC",
1355
+ "AS",
1356
+ "AF",
1357
+ "EU",
1358
+ "AF",
1359
+ "AF",
1360
+ "EU",
1361
+ "AF",
1362
+ "--",
1363
+ "--",
1364
+ "--",
1365
+ "EU",
1366
+ "EU",
1367
+ "EU",
1368
+ "EU",
1369
+ "NA",
1370
+ "NA",
1371
+ "NA",
1372
+ "AF",
1373
+ "--"
1374
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1375
 
1376
+ /**
1377
+ * Added for Chapagain_AutoCurrency Magento Module
1378
+ * GEOIP_COUNTRY_CODE_TO_CURRENCY
1379
+ */
1380
+ public $GEOIP_COUNTRY_CODE_TO_CURRENCY = array(
1381
+ "EU" => "EUR", "AD" => "EUR", "AE" => "AED", "AF" => "AFN", "AG" => "XCD", "AI" => "XCD",
1382
+ "AL" => "ALL", "AM" => "AMD", "CW" => "ANG", "AO" => "AOA", "AQ" => "AQD", "AR" => "ARS", "AS" => "EUR",
1383
+ "AT" => "EUR", "AU" => "AUD", "AW" => "AWG", "AZ" => "AZN", "BA" => "BAM", "BB" => "BBD",
1384
+ "BD" => "BDT", "BE" => "EUR", "BF" => "XOF", "BG" => "BGL", "BH" => "BHD", "BI" => "BIF",
1385
+ "BJ" => "XOF", "BM" => "BMD", "BN" => "BND", "BO" => "BOB", "BR" => "BRL", "BS" => "BSD",
1386
+ "BT" => "BTN", "BV" => "NOK", "BW" => "BWP", "BY" => "BYR", "BZ" => "BZD", "CA" => "CAD",
1387
+ "CC" => "AUD", "CD" => "CDF", "CF" => "XAF", "CG" => "XAF", "CH" => "CHF", "CI" => "XOF",
1388
+ "CK" => "NZD", "CL" => "CLP", "CM" => "XAF", "CN" => "CNY", "CO" => "COP", "CR" => "CRC",
1389
+ "CU" => "CUP", "CV" => "CVE", "CX" => "AUD", "CY" => "EUR", "CZ" => "CZK", "DE" => "EUR",
1390
+ "DJ" => "DJF", "DK" => "DKK", "DM" => "XCD", "DO" => "DOP", "DZ" => "DZD", "EC" => "ECS",
1391
+ "EE" => "EEK", "EG" => "EGP", "EH" => "MAD", "ER" => "ETB", "ES" => "EUR", "ET" => "ETB",
1392
+ "FI" => "EUR", "FJ" => "FJD", "FK" => "FKP", "FM" => "USD", "FO" => "DKK", "FR" => "EUR", "SX" => "ANG",
1393
+ "GA" => "XAF", "GB" => "GBP", "GD" => "XCD", "GE" => "GEL", "GF" => "EUR", "GH" => "GHS",
1394
+ "GI" => "GIP", "GL" => "DKK", "GM" => "GMD", "GN" => "GNF", "GP" => "EUR", "GQ" => "XAF",
1395
+ "GR" => "EUR", "GS" => "GBP", "GT" => "GTQ", "GU" => "USD", "GW" => "XOF", "GY" => "GYD",
1396
+ "HK" => "HKD", "HM" => "AUD", "HN" => "HNL", "HR" => "HRK", "HT" => "HTG", "HU" => "HUF",
1397
+ "ID" => "IDR", "IE" => "EUR", "IL" => "ILS", "IN" => "INR", "IO" => "USD", "IQ" => "IQD",
1398
+ "IR" => "IRR", "IS" => "ISK", "IT" => "EUR", "JM" => "JMD", "JO" => "JOD", "JP" => "JPY",
1399
+ "KE" => "KES", "KG" => "KGS", "KH" => "KHR", "KI" => "AUD", "KM" => "KMF", "KN" => "XCD",
1400
+ "KP" => "KPW", "KR" => "KRW", "KW" => "KWD", "KY" => "KYD", "KZ" => "KZT", "LA" => "LAK",
1401
+ "LB" => "LBP", "LC" => "XCD", "LI" => "CHF", "LK" => "LKR", "LR" => "LRD", "LS" => "LSL",
1402
+ "LT" => "LTL", "LU" => "EUR", "LV" => "LVL", "LY" => "LYD", "MA" => "MAD", "MC" => "EUR",
1403
+ "MD" => "MDL", "MG" => "MGF", "MH" => "USD", "MK" => "MKD", "ML" => "XOF", "MM" => "MMK",
1404
+ "MN" => "MNT", "MO" => "MOP", "MP" => "USD", "MQ" => "EUR", "MR" => "MRO", "MS" => "XCD",
1405
+ "MT" => "EUR", "MU" => "MUR", "MV" => "MVR", "MW" => "MWK", "MX" => "MXN", "MY" => "MYR",
1406
+ "MZ" => "MZN", "NA" => "NAD", "NC" => "XPF", "NE" => "XOF", "NF" => "AUD", "NG" => "NGN",
1407
+ "NI" => "NIO", "NL" => "EUR", "NO" => "NOK", "NP" => "NPR", "NR" => "AUD", "NU" => "NZD",
1408
+ "NZ" => "NZD", "OM" => "OMR", "PA" => "PAB", "PE" => "PEN", "PF" => "XPF", "PG" => "PGK",
1409
+ "PH" => "PHP", "PK" => "PKR", "PL" => "PLN", "PM" => "EUR", "PN" => "NZD", "PR" => "USD", "PS" => "ILS", "PT" => "EUR",
1410
+ "PW" => "USD", "PY" => "PYG", "QA" => "QAR", "RE" => "EUR", "RO" => "RON", "RU" => "RUB",
1411
+ "RW" => "RWF", "SA" => "SAR", "SB" => "SBD", "SC" => "SCR", "SD" => "SDD", "SE" => "SEK",
1412
+ "SG" => "SGD", "SH" => "SHP", "SI" => "EUR", "SJ" => "NOK", "SK" => "SKK", "SL" => "SLL",
1413
+ "SM" => "EUR", "SN" => "XOF", "SO" => "SOS", "SR" => "SRG", "ST" => "STD", "SV" => "SVC",
1414
+ "SY" => "SYP", "SZ" => "SZL", "TC" => "USD", "TD" => "XAF", "TF" => "EUR", "TG" => "XOF",
1415
+ "TH" => "THB", "TJ" => "TJS", "TK" => "NZD", "TM" => "TMM", "TN" => "TND", "TO" => "TOP", "TL" => "USD",
1416
+ "TR" => "TRY", "TT" => "TTD", "TV" => "AUD", "TW" => "TWD", "TZ" => "TZS", "UA" => "UAH",
1417
+ "UG" => "UGX", "UM" => "USD", "US" => "USD", "UY" => "UYU", "UZ" => "UZS", "VA" => "EUR",
1418
+ "VC" => "XCD", "VE" => "VEF", "VG" => "USD", "VI" => "USD", "VN" => "VND", "VU" => "VUV",
1419
+ "WF" => "XPF", "WS" => "EUR", "YE" => "YER", "YT" => "EUR", "RS" => "RSD",
1420
+ "ZA" => "ZAR", "ZM" => "ZMK", "ME" => "EUR", "ZW" => "ZWD",
1421
+ "AX" => "EUR", "GG" => "GBP", "IM" => "GBP",
1422
+ "JE" => "GBP", "BL" => "EUR", "MF" => "EUR", "BQ" => "USD", "SS" => "SSP"
1423
+ );
1424
+ }
1425
+
1426
+ /**
1427
+ * Added for Chapagain_AutoCurrency Magento Module
1428
+ * geoip_currency_code_by_country_code
1429
+ */
1430
+ function geoip_currency_code_by_country_code($gi, $code) {
1431
+ return $gi->GEOIP_COUNTRY_CODE_TO_CURRENCY[$code];
1432
  }
1433
+
1434
+ function geoip_load_shared_mem($file)
1435
+ {
1436
+ $fp = fopen($file, "rb");
1437
+ if (!$fp) {
1438
+ print "error opening $file: $php_errormsg\n";
1439
+ exit;
1440
+ }
1441
+ $s_array = fstat($fp);
1442
+ $size = $s_array['size'];
1443
+ if (($shmid = @shmop_open(GEOIP_SHM_KEY, "w", 0, 0))) {
1444
+ shmop_delete($shmid);
1445
+ shmop_close($shmid);
1446
+ }
1447
+ $shmid = shmop_open(GEOIP_SHM_KEY, "c", 0644, $size);
1448
+ shmop_write($shmid, fread($fp, $size), 0);
1449
+ shmop_close($shmid);
1450
  }
1451
 
1452
+ function _setup_segments($gi)
1453
+ {
1454
+ $gi->databaseType = GEOIP_COUNTRY_EDITION;
1455
+ $gi->record_length = STANDARD_RECORD_LENGTH;
1456
+ if ($gi->flags & GEOIP_SHARED_MEMORY) {
1457
+ $offset = @shmop_size($gi->shmid) - 3;
1458
+ for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
1459
+ $delim = @shmop_read($gi->shmid, $offset, 3);
1460
+ $offset += 3;
1461
+ if ($delim == (chr(255) . chr(255) . chr(255))) {
1462
+ $gi->databaseType = ord(@shmop_read($gi->shmid, $offset, 1));
1463
+ if ($gi->databaseType >= 106) {
1464
+ $gi->databaseType -= 105;
1465
+ }
1466
+ $offset++;
1467
+
1468
+ if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
1469
+ $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
1470
+ } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
1471
+ $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
1472
+ } elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
1473
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
1474
  || ($gi->databaseType == GEOIP_ORG_EDITION)
1475
+ || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1476
  || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1477
+ || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1478
+ || ($gi->databaseType == GEOIP_ISP_EDITION)
1479
+ || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1480
+ || ($gi->databaseType == GEOIP_USERTYPE_EDITION)
1481
+ || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
1482
+ || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
1483
+ || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
1484
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
1485
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
1486
+ || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
1487
+ || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
1488
+ || ($gi->databaseType == GEOIP_ASNUM_EDITION)
1489
+ || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)
1490
+ ) {
1491
+ $gi->databaseSegments = 0;
1492
+ $buf = @shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH);
1493
+ for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) {
1494
+ $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
1495
+ }
1496
+ if (($gi->databaseType == GEOIP_ORG_EDITION)
1497
+ || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1498
  || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1499
+ || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1500
+ || ($gi->databaseType == GEOIP_ISP_EDITION)
1501
+ || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1502
+ ) {
1503
+ $gi->record_length = ORG_RECORD_LENGTH;
1504
+ }
1505
  }
1506
+ break;
1507
+ } else {
1508
+ $offset -= 4;
1509
  }
 
 
 
1510
  }
1511
+ if (($gi->databaseType == GEOIP_COUNTRY_EDITION) ||
1512
+ ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) ||
1513
+ ($gi->databaseType == GEOIP_PROXY_EDITION) ||
1514
+ ($gi->databaseType == GEOIP_NETSPEED_EDITION)
1515
+ ) {
1516
+ $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
 
 
 
 
 
 
 
 
 
1517
  }
1518
+ } else {
1519
+ $filepos = ftell($gi->filehandle);
1520
+ fseek($gi->filehandle, -3, SEEK_END);
1521
+ for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) {
1522
+ $delim = fread($gi->filehandle, 3);
1523
+ if ($delim == (chr(255) . chr(255) . chr(255))) {
1524
+ $gi->databaseType = ord(fread($gi->filehandle, 1));
1525
+ if ($gi->databaseType >= 106) {
1526
+ $gi->databaseType -= 105;
1527
+ }
1528
+ if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
1529
+ $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0;
1530
+ } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
1531
+ $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1;
1532
+ } elseif (($gi->databaseType == GEOIP_CITY_EDITION_REV0)
1533
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV1)
1534
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
1535
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
1536
+ || ($gi->databaseType == GEOIP_ORG_EDITION)
1537
  || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1538
+ || ($gi->databaseType == GEOIP_ISP_EDITION)
1539
+ || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1540
+ || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1541
+ || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1542
+ || ($gi->databaseType == GEOIP_LOCATIONA_EDITION)
1543
+ || ($gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION)
1544
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV0_V6)
1545
+ || ($gi->databaseType == GEOIP_CITY_EDITION_REV1_V6)
1546
+ || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1)
1547
+ || ($gi->databaseType == GEOIP_NETSPEED_EDITION_REV1_V6)
1548
+ || ($gi->databaseType == GEOIP_USERTYPE_EDITION)
1549
+ || ($gi->databaseType == GEOIP_USERTYPE_EDITION_V6)
1550
+ || ($gi->databaseType == GEOIP_ASNUM_EDITION)
1551
+ || ($gi->databaseType == GEOIP_ASNUM_EDITION_V6)
1552
+ ) {
1553
+ $gi->databaseSegments = 0;
1554
+ $buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH);
1555
+ for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) {
1556
+ $gi->databaseSegments += (ord($buf[$j]) << ($j * 8));
1557
+ }
1558
+ if (($gi->databaseType == GEOIP_ORG_EDITION)
1559
+ || ($gi->databaseType == GEOIP_DOMAIN_EDITION)
1560
+ || ($gi->databaseType == GEOIP_ISP_EDITION)
1561
+ || ($gi->databaseType == GEOIP_ORG_EDITION_V6)
1562
+ || ($gi->databaseType == GEOIP_DOMAIN_EDITION_V6)
1563
+ || ($gi->databaseType == GEOIP_ISP_EDITION_V6)
1564
+ ) {
1565
+ $gi->record_length = ORG_RECORD_LENGTH;
1566
+ }
1567
+ }
1568
+ break;
1569
+ } else {
1570
+ fseek($gi->filehandle, -4, SEEK_CUR);
1571
  }
1572
  }
1573
+ if (($gi->databaseType == GEOIP_COUNTRY_EDITION) ||
1574
+ ($gi->databaseType == GEOIP_COUNTRY_EDITION_V6) ||
1575
+ ($gi->databaseType == GEOIP_PROXY_EDITION) ||
1576
+ ($gi->databaseType == GEOIP_NETSPEED_EDITION)
1577
+ ) {
1578
+ $gi->databaseSegments = GEOIP_COUNTRY_BEGIN;
1579
  }
1580
+ fseek($gi->filehandle, $filepos, SEEK_SET);
1581
  }
1582
+ return $gi;
 
 
 
 
 
 
 
1583
  }
1584
 
1585
+ function geoip_open($filename, $flags)
1586
+ {
1587
+ $gi = new GeoIP;
1588
+ $gi->flags = $flags;
1589
+ if ($gi->flags & GEOIP_SHARED_MEMORY) {
1590
+ $gi->shmid = @shmop_open(GEOIP_SHM_KEY, "a", 0, 0);
1591
  } else {
1592
+ $gi->filehandle = fopen($filename, "rb") or trigger_error("GeoIP API: Can not open $filename\n", E_USER_ERROR);
1593
+ if ($gi->flags & GEOIP_MEMORY_CACHE) {
1594
+ $s_array = fstat($gi->filehandle);
1595
+ $gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
1596
+ }
1597
  }
 
1598
 
1599
+ $gi = _setup_segments($gi);
1600
+ return $gi;
1601
  }
1602
 
1603
+ function geoip_close($gi)
1604
+ {
1605
+ if ($gi->flags & GEOIP_SHARED_MEMORY) {
1606
+ return true;
1607
+ }
1608
 
1609
+ return fclose($gi->filehandle);
1610
  }
1611
 
1612
+ function geoip_country_id_by_name_v6($gi, $name)
1613
+ {
1614
+ $rec = dns_get_record($name, DNS_AAAA);
1615
+ if (!$rec) {
1616
+ return false;
1617
+ }
1618
+ $addr = $rec[0]["ipv6"];
1619
+ if (!$addr || $addr == $name) {
1620
+ return false;
1621
+ }
1622
+ return geoip_country_id_by_addr_v6($gi, $addr);
1623
+ }
1624
+
1625
+ function geoip_country_id_by_name($gi, $name)
1626
+ {
1627
+ $addr = gethostbyname($name);
1628
+ if (!$addr || $addr == $name) {
1629
+ return false;
1630
+ }
1631
+ return geoip_country_id_by_addr($gi, $addr);
1632
+ }
1633
+
1634
+ function geoip_country_code_by_name_v6($gi, $name)
1635
+ {
1636
+ $country_id = geoip_country_id_by_name_v6($gi, $name);
1637
+ if ($country_id !== false) {
1638
+ return $gi->GEOIP_COUNTRY_CODES[$country_id];
1639
+ }
1640
  return false;
 
 
1641
  }
1642
 
1643
+ function geoip_country_code_by_name($gi, $name)
1644
+ {
1645
+ $country_id = geoip_country_id_by_name($gi, $name);
1646
+ if ($country_id !== false) {
1647
  return $gi->GEOIP_COUNTRY_CODES[$country_id];
1648
+ }
1649
+ return false;
1650
  }
1651
 
1652
+ function geoip_country_name_by_name_v6($gi, $name)
1653
+ {
1654
+ $country_id = geoip_country_id_by_name_v6($gi, $name);
1655
+ if ($country_id !== false) {
1656
  return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1657
+ }
1658
+ return false;
1659
  }
1660
 
1661
+ function geoip_country_name_by_name($gi, $name)
1662
+ {
1663
+ $country_id = geoip_country_id_by_name($gi, $name);
1664
+ if ($country_id !== false) {
1665
+ return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1666
+ }
1667
+ return false;
1668
  }
1669
 
1670
+ function geoip_country_id_by_addr_v6($gi, $addr)
1671
+ {
1672
+ $ipnum = inet_pton($addr);
1673
+ return _geoip_seek_country_v6($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
1674
+ }
1675
+
1676
+ function geoip_country_id_by_addr($gi, $addr)
1677
+ {
1678
+ $ipnum = ip2long($addr);
1679
+ return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN;
1680
+ }
1681
+
1682
+ function geoip_country_code_by_addr_v6($gi, $addr)
1683
+ {
1684
+ $country_id = geoip_country_id_by_addr_v6($gi, $addr);
1685
  if ($country_id !== false) {
1686
+ return $gi->GEOIP_COUNTRY_CODES[$country_id];
1687
  }
1688
+ return false;
 
1689
  }
1690
 
1691
+ function geoip_country_code_by_addr($gi, $addr)
1692
+ {
1693
+ if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
1694
+ $record = geoip_record_by_addr($gi, $addr);
1695
+ if ($record !== false) {
1696
+ return $record->country_code;
1697
+ }
1698
+ } else {
1699
+ $country_id = geoip_country_id_by_addr($gi, $addr);
1700
+ if ($country_id !== false) {
1701
+ return $gi->GEOIP_COUNTRY_CODES[$country_id];
1702
+ }
1703
+ }
1704
+ return false;
1705
  }
1706
 
1707
+ function geoip_country_name_by_addr_v6($gi, $addr)
1708
+ {
1709
+ $country_id = geoip_country_id_by_addr_v6($gi, $addr);
 
 
 
1710
  if ($country_id !== false) {
1711
+ return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1712
  }
1713
+ return false;
 
1714
  }
1715
 
1716
+ function geoip_country_name_by_addr($gi, $addr)
1717
+ {
1718
+ if ($gi->databaseType == GEOIP_CITY_EDITION_REV1) {
1719
+ $record = geoip_record_by_addr($gi, $addr);
1720
+ return $record->country_name;
1721
+ } else {
1722
+ $country_id = geoip_country_id_by_addr($gi, $addr);
1723
+ if ($country_id !== false) {
1724
+ return $gi->GEOIP_COUNTRY_NAMES[$country_id];
1725
+ }
 
 
 
 
 
 
 
 
 
 
 
 
1726
  }
1727
+ return false;
1728
+ }
1729
+
1730
+ function _geoip_seek_country_v6($gi, $ipnum)
1731
+ {
1732
+ # arrays from unpack start with offset 1
1733
+ # yet another php mystery. array_merge work around
1734
+ # this broken behaviour
1735
+ $v6vec = array_merge(unpack("C16", $ipnum));
1736
+
1737
+ $offset = 0;
1738
+ for ($depth = 127; $depth >= 0; --$depth) {
1739
+ if ($gi->flags & GEOIP_MEMORY_CACHE) {
1740
+ $buf = _safe_substr(
1741
+ $gi->memory_buffer,
1742
+ 2 * $gi->record_length * $offset,
1743
+ 2 * $gi->record_length
1744
+ );
1745
+ } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
1746
+ $buf = @shmop_read(
1747
+ $gi->shmid,
1748
+ 2 * $gi->record_length * $offset,
1749
+ 2 * $gi->record_length
1750
+ );
1751
+ } else {
1752
+ fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
1753
+ or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
1754
+ $buf = fread($gi->filehandle, 2 * $gi->record_length);
1755
+ }
1756
+ $x = array(0, 0);
1757
+ for ($i = 0; $i < 2; ++$i) {
1758
+ for ($j = 0; $j < $gi->record_length; ++$j) {
1759
+ $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
1760
+ }
1761
+ }
1762
+
1763
+ $bnum = 127 - $depth;
1764
+ $idx = $bnum >> 3;
1765
+ $b_mask = 1 << ($bnum & 7 ^ 7);
1766
+ if (($v6vec[$idx] & $b_mask) > 0) {
1767
+ if ($x[1] >= $gi->databaseSegments) {
1768
+ return $x[1];
1769
+ }
1770
+ $offset = $x[1];
1771
+ } else {
1772
+ if ($x[0] >= $gi->databaseSegments) {
1773
+ return $x[0];
1774
+ }
1775
+ $offset = $x[0];
1776
+ }
1777
  }
1778
+ trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
1779
+ return false;
1780
+ }
1781
+
1782
+ function _geoip_seek_country($gi, $ipnum)
1783
+ {
1784
+ $offset = 0;
1785
+ for ($depth = 31; $depth >= 0; --$depth) {
1786
+ if ($gi->flags & GEOIP_MEMORY_CACHE) {
1787
+ $buf = _safe_substr(
1788
+ $gi->memory_buffer,
1789
+ 2 * $gi->record_length * $offset,
1790
+ 2 * $gi->record_length
1791
+ );
1792
+ } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
1793
+ $buf = @shmop_read(
1794
+ $gi->shmid,
1795
+ 2 * $gi->record_length * $offset,
1796
+ 2 * $gi->record_length
1797
+ );
1798
+ } else {
1799
+ fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
1800
+ or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
1801
+ $buf = fread($gi->filehandle, 2 * $gi->record_length);
1802
+ }
1803
+ $x = array(0, 0);
1804
+ for ($i = 0; $i < 2; ++$i) {
1805
+ for ($j = 0; $j < $gi->record_length; ++$j) {
1806
+ $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
1807
+ }
1808
+ }
1809
+ if ($ipnum & (1 << $depth)) {
1810
+ if ($x[1] >= $gi->databaseSegments) {
1811
+ return $x[1];
1812
+ }
1813
+ $offset = $x[1];
1814
  } else {
1815
+ if ($x[0] >= $gi->databaseSegments) {
1816
+ return $x[0];
1817
+ }
1818
+ $offset = $x[0];
1819
+ }
1820
  }
1821
+ trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
1822
+ return false;
 
1823
  }
1824
 
1825
+ function _common_get_org($gi, $seek_org)
1826
+ {
1827
+ $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments;
1828
+ if ($gi->flags & GEOIP_SHARED_MEMORY) {
1829
+ $org_buf = @shmop_read($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH);
 
 
 
1830
  } else {
1831
+ fseek($gi->filehandle, $record_pointer, SEEK_SET);
1832
+ $org_buf = fread($gi->filehandle, MAX_ORG_RECORD_LENGTH);
1833
+ }
1834
+ $org_buf = _safe_substr($org_buf, 0, strpos($org_buf, "\0"));
1835
+ return $org_buf;
 
 
 
 
 
1836
  }
1837
 
1838
+ function _get_org_v6($gi, $ipnum)
1839
+ {
1840
+ $seek_org = _geoip_seek_country_v6($gi, $ipnum);
1841
+ if ($seek_org == $gi->databaseSegments) {
1842
+ return null;
1843
+ }
1844
+ return _common_get_org($gi, $seek_org);
1845
  }
1846
 
1847
+ function _get_org($gi, $ipnum)
1848
+ {
1849
+ $seek_org = _geoip_seek_country($gi, $ipnum);
1850
+ if ($seek_org == $gi->databaseSegments) {
1851
+ return null;
 
 
 
 
1852
  }
1853
+ return _common_get_org($gi, $seek_org);
1854
+ }
1855
+
1856
+
1857
+ function geoip_name_by_addr_v6($gi, $addr)
1858
+ {
1859
+ if ($addr == null) {
1860
+ return 0;
 
 
 
 
 
 
 
 
1861
  }
1862
+ $ipnum = inet_pton($addr);
1863
+ return _get_org_v6($gi, $ipnum);
1864
  }
1865
 
1866
+ function geoip_name_by_addr($gi, $addr)
1867
+ {
1868
+ if ($addr == null) {
1869
+ return 0;
1870
+ }
1871
+ $ipnum = ip2long($addr);
1872
+ return _get_org($gi, $ipnum);
1873
  }
1874
 
1875
+ function geoip_org_by_addr($gi, $addr)
1876
+ {
1877
+ return geoip_name_by_addr($gi, $addr);
 
 
 
 
 
1878
  }
1879
 
1880
+ function _get_region($gi, $ipnum)
1881
+ {
1882
+ if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) {
1883
+ $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0;
1884
+ if ($seek_region >= 1000) {
1885
+ $country_code = "US";
1886
+ $region = chr(($seek_region - 1000) / 26 + 65) . chr(($seek_region - 1000) % 26 + 65);
1887
+ } else {
1888
+ $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region];
1889
+ $region = "";
1890
+ }
1891
+ return array($country_code, $region);
1892
+ } elseif ($gi->databaseType == GEOIP_REGION_EDITION_REV1) {
1893
+ $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1;
1894
+ if ($seek_region < US_OFFSET) {
1895
+ $country_code = "";
1896
+ $region = "";
1897
+ } elseif ($seek_region < CANADA_OFFSET) {
1898
+ $country_code = "US";
1899
+ $region = chr(($seek_region - US_OFFSET) / 26 + 65) . chr(($seek_region - US_OFFSET) % 26 + 65);
1900
+ } elseif ($seek_region < WORLD_OFFSET) {
1901
+ $country_code = "CA";
1902
+ $region = chr(($seek_region - CANADA_OFFSET) / 26 + 65) . chr(($seek_region - CANADA_OFFSET) % 26 + 65);
1903
+ } else {
1904
+ $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE];
1905
+ $region = "";
1906
+ }
1907
+ return array($country_code, $region);
1908
+ }
1909
+ }
1910
+
1911
+ function geoip_region_by_addr($gi, $addr)
1912
+ {
1913
+ if ($addr == null) {
1914
+ return 0;
1915
+ }
1916
+ $ipnum = ip2long($addr);
1917
+ return _get_region($gi, $ipnum);
1918
+ }
1919
+
1920
+ function _safe_substr($string, $start, $length)
1921
+ {
1922
+ // workaround php's broken substr, strpos, etc handling with
1923
+ // mbstring.func_overload and mbstring.internal_encoding
1924
+ $mbExists = extension_loaded('mbstring');
1925
+
1926
+ if ($mbExists) {
1927
+ $enc = mb_internal_encoding();
1928
+ mb_internal_encoding('ISO-8859-1');
1929
+ }
1930
+
1931
+ $buf = substr($string, $start, $length);
1932
+
1933
+ if ($mbExists) {
1934
+ mb_internal_encoding($enc);
1935
+ }
1936
+
1937
+ return $buf;
1938
+ }
var/geoip/ip2country/Ip2Country.php ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This class contains the capability to look up IP addresses and return the correct
5
+ * country, based on the lookup data generated from process_csv.php.
6
+ *
7
+ * Since PHP cannot handle 32-bit unsigned longs, we translate the IP addresses
8
+ * into 4-byte strings instead, which also should safeguard against future IPv6
9
+ * lookups.
10
+ *
11
+ * The index file contains 12-byte records, grouped into three 32-bit dwords.
12
+ * The first is an IP block address, the second contains the position in the data
13
+ * file, and the third is the block length for that IP group.
14
+ *
15
+ * The data file contains a long list of 6-byte records, the first four form the
16
+ * start of the IP address block and the remaining two bytes the two-letter ISO
17
+ * country code to which that IP block is allocated.
18
+ *
19
+ * The lookups are done by calculating the "group number" of the IP address,
20
+ * which is the high 13 bits, and looking that up in a hash table. This yields
21
+ * a position into the data file, which can be either preloaded or loaded on
22
+ * demand. The data is then searched using a binary tree search, yielding
23
+ * effectively O(log2 n) lookups.
24
+ *
25
+ * Memory is used very conservatively - since we only use strings to represent
26
+ * data, a fully preloaded database should add about 1.2 MB of internal memory.
27
+ *
28
+ * On a 2.3 GHz Intel Core i5 we get about 40,000 lookups per second.
29
+ */
30
+ class Ip2Country
31
+ {
32
+ private $index = null; // Holds the preloaded index
33
+ private $data = array(); // Holds the data records, one chunk per index group
34
+ private $fp;
35
+ private $offset;
36
+ private $datalen;
37
+ private $lastentry;
38
+
39
+ /**
40
+ * Initializes the ip to country lookup tables and preloads the index.
41
+ */
42
+ public function __construct($datafile = null)
43
+ {
44
+ if (!$datafile)
45
+ $datafile = 'ip2country.dat';
46
+
47
+ $this->fp = fopen($datafile, 'r');
48
+
49
+ $header = fread($this->fp, 8);
50
+ list(, $indexlen, $this->datalen) = unpack('L2', $header);
51
+ $this->offset = 8 + $indexlen;
52
+
53
+ $this->index = array_fill_keys(range(0, 8191), null);
54
+
55
+ $index = str_split(fread($this->fp, $indexlen), 12);
56
+ foreach($index as $ix)
57
+ $this->index[self::ipgroup($ix)] .= $ix;
58
+
59
+ $lastv = null;
60
+ foreach($this->index as $k => &$v)
61
+ if ($v)
62
+ $lastv = $v;
63
+ else
64
+ $v = $lastv;
65
+ }
66
+
67
+ /**
68
+ * Destroys the ip 2 country instance.
69
+ */
70
+ public function __destruct()
71
+ {
72
+ if ($this->fp)
73
+ fclose($this->fp);
74
+ }
75
+
76
+ /**
77
+ * Get the group of an IP address by returning the 13 high bits
78
+ */
79
+ public static function ipgroup($ipbin)
80
+ {
81
+ return (ord($ipbin[0]) << 8 | ord($ipbin[1])) >> 3;
82
+ }
83
+
84
+ /**
85
+ * Preloads the entire data file into memory for faster lookups of many IP
86
+ * addresses
87
+ */
88
+ public function preload()
89
+ {
90
+ if ($this->fp == null)
91
+ return;
92
+
93
+ fseek($this->fp, $this->offset);
94
+ $data = fread($this->fp, $this->datalen);
95
+
96
+ foreach($this->index as $index)
97
+ foreach(str_split($index, 12) as $ix)
98
+ {
99
+ list(, , $pos, $len) = unpack('L3', $ix);
100
+ if (!isset($this->data[$pos]))
101
+ $this->data[$pos] = substr($data, $pos, $len + 6); // Always one extra record, for upper bound
102
+ }
103
+
104
+ fclose($this->fp);
105
+ $this->fp = null;
106
+ }
107
+
108
+ /**
109
+ * Binary search function that searches a string with records for a match.
110
+ * Requires that the array is sorted. Since we're operating on 32-bit
111
+ * IPs, we match the first four bytes of every string and the
112
+ * rest is just payload. Returns the entry "n" for which the relation
113
+ * 32bit($data[n]) <= $str < 32bit($data[n+1])
114
+ * is true.
115
+ *
116
+ * Always tries to return 4 extra bytes from the next record, for an upper
117
+ * bound. So if $reclen is 12, it tries to return 16 bytes.
118
+ */
119
+ private function findRecord($data, $str, $reclen)
120
+ {
121
+ $l = 0;
122
+ $count = strlen($data) / $reclen;
123
+ $h = $count - 1;
124
+ while ($l <= $h)
125
+ {
126
+ $i = ($l + $h) >> 1;
127
+
128
+ // Get the current record (i) and compare
129
+ $rec = substr($data, $i * $reclen, $reclen + 4);
130
+ $c = strcmp($str, substr($rec, 0, 4));
131
+
132
+ // Equal? I guess we found it.
133
+ if ($c == 0)
134
+ return $rec;
135
+ // If it's more, then compare with the next record to see if that one is less
136
+ else if ($c > 0)
137
+ {
138
+ // If this was the last record, then return it
139
+ if ($i+1 >= $count)
140
+ return $rec;
141
+
142
+ $rec1 = substr($data, ($i+1)*$reclen, $reclen + 4);
143
+ $c1 = strcmp($str, substr($rec1, 0, 4));
144
+
145
+ // Did we stumble upon the right one?
146
+ if ($c1 == 0)
147
+ // Oops. Equal with the next one. Just return.
148
+ return $rec1;
149
+ else if ($c1 < 0)
150
+ // Yep, this is the right one.
151
+ return $rec;
152
+
153
+ $l = $i + 1;
154
+ }
155
+ else
156
+ $h = $i - 1;
157
+ }
158
+
159
+ // Never supposed to end up here - something is wrong.
160
+ throw new Exception('Binary find failure');
161
+ }
162
+
163
+ /**
164
+ * Find the index given by the IP address.
165
+ */
166
+ private function findIndex($ipbin)
167
+ {
168
+ $group = self::ipgroup($ipbin);
169
+
170
+ $ix = $this->index[$group];
171
+ if (strcmp($ipbin, substr($ix, 0, 4)) < 0 && $group > 0)
172
+ $ix = $this->index[$group-1];
173
+
174
+ if (strlen($ix) > 12)
175
+ $ix = $this->findRecord($ix, $ipbin, 12);
176
+
177
+ return $ix;
178
+ }
179
+
180
+ /**
181
+ * Load the specific data chunk from the main data file and save it
182
+ * to the data cache.
183
+ */
184
+ private function getDataEntry($pos, $len)
185
+ {
186
+ // If it doesn't exist in the cache, load it
187
+ if (!isset($this->data[$pos]))
188
+ {
189
+ fseek($this->fp, $pos + $this->offset);
190
+ $this->data[$pos] = fread($this->fp, $len + 6); // Always one extra record, for upper bound
191
+ }
192
+
193
+ return $this->data[$pos];
194
+ }
195
+
196
+ /**
197
+ * Lookup a 4-byte binary IP string and return the two-letter ISO country.
198
+ */
199
+ public function lookupbin($ipbin)
200
+ {
201
+ if (strlen($this->lastentry) == 10 && strcmp($ipbin, substr($this->lastentry, 0, 4)) >= 0 && strcmp($ipbin, substr($this->lastentry, 6, 4)) < 0)
202
+ return substr($this->lastentry, 4, 2);
203
+
204
+ list(, , $pos, $len) = unpack('L3', $this->findIndex($ipbin));
205
+ $data = $this->getDataEntry($pos, $len);
206
+
207
+ $this->lastentry = $this->findRecord($data, $ipbin, 6);
208
+
209
+ return substr($this->lastentry, 4, 2);
210
+ }
211
+
212
+ /**
213
+ * Lookup an IP address and return the two-letter ISO country.
214
+ */
215
+ public function lookup($ip)
216
+ {
217
+ return $this->lookupbin(inet_pton($ip));
218
+ }
219
+ }
var/geoip/ip2country/ip2country.dat ADDED
Binary file