Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lang/en.php1
-rwxr-xr-xplugins/UserCountry/LocationProvider/GeoIp/ServerBased.php44
2 files changed, 44 insertions, 1 deletions
diff --git a/lang/en.php b/lang/en.php
index 1dfa59dab4..3322df2595 100644
--- a/lang/en.php
+++ b/lang/en.php
@@ -1502,6 +1502,7 @@ And thank you for using Piwik!',
'UserCountry_GeoIpLocationProviderDesc_Php2' => 'If your website gets a lot of traffic, you may find that this location provider is too slow. In this case, you should install the %1$sPECL extension%2$s or a %3$sserver module%4$s.',
'UserCountry_GeoIpLocationProviderDesc_ServerBased1' => 'This location provider uses the GeoIP module that has been installed in your HTTP server. This provider is fast and accurate, but %1$scan only be used with normal browser tracking.%2$s',
'UserCountry_GeoIpLocationProviderDesc_ServerBased2' => 'If you have to import log files or do something else that requires setting IP addresses, use the %1$sPECL GeoIP implementation (recommended)%2$s or the %3$sPHP GeoIP implementation%4$s.',
+ 'UserCountry_GeoIpLocationProviderDesc_ServerBasedAnonWarn' => 'Note: IP anonymization has no effect on the locations reported by this provider. Before using it with IP anonymization, make sure this does not violate any privacy laws you may be subject to.',
'UserCountry_GeolocationPageDesc' => 'On this page you can change how Piwik determines visitor locations.',
'UserCountry_CurrentLocationIntro' => 'According to this provider, your current location is',
'UserCountry_CannotFindPeclGeoIPDb' => 'Could not find a country, region or city database for the GeoIP PECL module. Make sure your GeoIP database is located in %1$s and is named %2$s or %3$s otherwise the PECL module will not notice it.',
diff --git a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php
index 105d19e077..b5c92ce110 100755
--- a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php
+++ b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php
@@ -64,7 +64,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou
// geoip modules that are built into servers can't use a forced IP. in this case we try
// to fallback to another version.
$myIP = Piwik_IP::getIpFromHeader();
- if ($info['ip'] != $myIP
+ if (!self::isSameOrAnonymizedIp($info['ip'], $myIP)
&& (!isset($info['disable_fallbacks'])
|| !$info['disable_fallbacks']))
{
@@ -197,6 +197,8 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou
$title = sprintf(self::TITLE, $serverDesc);
$desc = Piwik_Translate('UserCountry_GeoIpLocationProviderDesc_ServerBased1', array('<strong>', '</strong>'))
. '<br/><br/>'
+ . '<em>'.Piwik_Translate('UserCountry_GeoIpLocationProviderDesc_ServerBasedAnonWarn').'</em>'
+ . '<br/><br/>'
. Piwik_Translate('UserCountry_GeoIpLocationProviderDesc_ServerBased2',
array('<strong><em>', '</em></strong>', '<strong><em>', '</em></strong>'));
$installDocs =
@@ -213,4 +215,44 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou
'order' => 4,
'install_docs' => $installDocs);
}
+
+ /**
+ * Checks if two IP addresses are the same or if the first is the anonymized
+ * version of the other.
+ *
+ * @param string $ip
+ * @param string $currentIp This IP should not be anonymized.
+ * @return bool
+ */
+ public static function isSameOrAnonymizedIp( $ip, $currentIp )
+ {
+ $ip = array_reverse(explode('.', $ip));
+ $currentIp = array_reverse(explode('.', $currentIp));
+
+ if (count($ip) != count($currentIp))
+ {
+ return false;
+ }
+
+ foreach ($ip as $i => $byte)
+ {
+ if ($byte == 0)
+ {
+ $currentIp[$i] = 0;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ foreach ($ip as $i => $byte)
+ {
+ if ($byte != $currentIp[$i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}