Skip to content

Commit

Permalink
Fixes #4493 Make sure tracker cache also contain the Anonymizer IP se…
Browse files Browse the repository at this point in the history
…ttings + debug output
  • Loading branch information
mattab committed Jan 13, 2014
1 parent a665821 commit bb65f51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion plugins/PrivacyManager/IPAnonymizer.php
Expand Up @@ -10,6 +10,7 @@
*/
namespace Piwik\Plugins\PrivacyManager;

use Piwik\Common;
use Piwik\Config;
use Piwik\IP;
use Piwik\Tracker\Cache;
Expand Down Expand Up @@ -50,7 +51,7 @@ public static function applyIPMask($ip, $maskLength)
'ffff:ffff:ffff:0000::',
'ffff:ff00:0000:0000::'
);
return $ip & pack('a16', inet_pton($masks[$maskLength]));
$ip = $ip & pack('a16', inet_pton($masks[$maskLength]));
}
return $ip;
}
Expand All @@ -60,11 +61,15 @@ public static function applyIPMask($ip, $maskLength)
*/
public function setVisitorIpAddress(&$ip)
{

if (!$this->isActiveInTracker()) {
Common::printDebug("Visitor IP was _not_ anonymized: ". IP::N2P($ip));
return;
}

$originalIp = $ip;
$ip = self::applyIPMask($ip, Config::getInstance()->Tracker['ip_address_mask_length']);
Common::printDebug("Visitor IP (was: ". IP::N2P($originalIp) .") has been anonymized: ". IP::N2P($ip));
}

/**
Expand Down
8 changes: 7 additions & 1 deletion plugins/PrivacyManager/PrivacyManager.php
Expand Up @@ -147,12 +147,18 @@ public function getListHooksRegistered()
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'Menu.Admin.addItems' => 'addMenu',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'Tracker.setTrackerCacheGeneral' => array($this->dntChecker, 'setTrackerCacheGeneral'),
'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral',
'Tracker.isExcludedVisit' => array($this->dntChecker, 'checkHeaderInTracker'),
'Tracker.setVisitorIp' => array($this->ipAnonymizer, 'setVisitorIpAddress'),
);
}

public function setTrackerCacheGeneral(&$cacheContent)
{
$this->ipAnonymizer->setTrackerCacheGeneral($cacheContent);
$this->dntChecker->setTrackerCacheGeneral($cacheContent);
}

public function getScheduledTasks(&$tasks)
{
// both tasks are low priority so they will execute after most others, but not lowest, so
Expand Down

0 comments on commit bb65f51

Please sign in to comment.