diff options
author | benakamoorthi <benaka.moorthi@gmail.com> | 2012-10-23 08:33:19 +0400 |
---|---|---|
committer | benakamoorthi <benaka.moorthi@gmail.com> | 2012-10-23 08:33:19 +0400 |
commit | 92d165a6c3fc825f08e38ad846bf57ac5814f1ca (patch) | |
tree | 2aa3504cebc208826aca56e432c177d44c85e100 /plugins/UserCountry | |
parent | 5c8ecb8bbe1a0cb0d4811dbc3ac0d60996c3e3dc (diff) |
Fixes #3463, allow serverbased geoip provider to work w/ anonymized IPs & add description about this issue in provider description.
git-svn-id: http://dev.piwik.org/svn/trunk@7285 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/UserCountry')
-rwxr-xr-x | plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php | 44 |
1 files changed, 43 insertions, 1 deletions
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; + } } |