update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* Piwik - Open source web analytics
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
@ -9,7 +9,7 @@
namespace Piwik\Plugins\PrivacyManager;
use Piwik\Common;
use Piwik\IP;
use Piwik\Network\IP;
/**
* Anonymize visitor IP addresses to comply with the privacy laws/guidelines in countries, such as Germany.
@ -19,50 +19,36 @@ class IPAnonymizer
/**
* Internal function to mask portions of the visitor IP address
*
* @param string $ip IP address in network address format
* @param IP $ip
* @param int $maskLength Number of octets to reset
* @return string
* @return IP
*/
public static function applyIPMask($ip, $maskLength)
public static function applyIPMask(IP $ip, $maskLength)
{
// IPv4 or mapped IPv4 in IPv6
if (IP::isIPv4($ip)) {
$i = strlen($ip);
if ($maskLength > $i) {
$maskLength = $i;
}
$newIpObject = $ip->anonymize($maskLength);
while ($maskLength-- > 0) {
$ip[--$i] = chr(0);
}
} else {
$masks = array(
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
'ffff:ffff:ffff:ffff::',
'ffff:ffff:ffff:0000::',
'ffff:ff00:0000:0000::'
);
$ip = $ip & pack('a16', inet_pton($masks[$maskLength]));
}
return $ip;
return $newIpObject;
}
/**
* Hook on Tracker.Visit.setVisitorIp to anomymize visitor IP addresses
* @param string $ip IP address in binary format (network format)
*/
public function setVisitorIpAddress(&$ip)
{
$ipObject = IP::fromBinaryIP($ip);
if (!$this->isActive()) {
Common::printDebug("Visitor IP was _not_ anonymized: ". IP::N2P($ip));
Common::printDebug("Visitor IP was _not_ anonymized: ". $ipObject->toString());
return;
}
$originalIp = $ip;
$privacyConfig = new Config();
$ip = self::applyIPMask($ip, $privacyConfig->ipAddressMaskLength);
Common::printDebug("Visitor IP (was: ". IP::N2P($originalIp) .") has been anonymized: ". IP::N2P($ip));
$newIpObject = self::applyIPMask($ipObject, $privacyConfig->ipAddressMaskLength);
$ip = $newIpObject->toBinary();
Common::printDebug("Visitor IP (was: ". $ipObject->toString() .") has been anonymized: ". $newIpObject->toString());
}
/**