blob: e921b57e318348cd548fca912ef83d89dff2619b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
* @category Piwik_Plugins
* @package Piwik_AnonymizeIP
*/
/**
* Anonymize visitor IP addresses to comply with the privacy laws/guidelines in countries, such as Germany.
*
* @package Piwik_AnonymizeIP
*/
class Piwik_AnonymizeIP extends Piwik_Plugin
{
/**
* Get plugin information
*/
public function getInformation()
{
return array(
'description' => Piwik_Translate('AnonymizeIP_PluginDescription'),
'author' => 'Piwik',
'author_homepage' => 'http://piwik.org/',
'version' => Piwik_Version::VERSION,
'TrackerPlugin' => true,
);
}
/**
* Get list of hooks to register
*/
public function getListHooksRegistered()
{
return array(
'Tracker.saveVisitorInformation' => 'anonymizeVisitorIpAddress',
);
}
/**
* Internal function to mask portions of the visitor IP address
*
* @param $ip Unsigned long representation of IP address
* @param $maskLength Number of octets to reset
*/
static public function applyIPMask($ip, $maskLength)
{
$maskedIP = pack('V', (float)$ip);
switch($maskLength) {
case 4:
$maskedIP[3] = "\0";
case 3:
$maskedIP[2] = "\0";
case 2:
$maskedIP[1] = "\0";
case 1:
$maskedIP[0] = "\0";
case 0:
default:
}
$res = unpack('V', $maskedIP);
return sprintf("%u", $res[1]);
}
/**
* Hook on Tracker.saveVisitorInformation to anonymize visitor IP addresses
*/
function anonymizeVisitorIpAddress($notification)
{
$visitorInfo =& $notification->getNotificationObject();
$visitorInfo['location_ip'] = self::applyIPMask($visitorInfo['location_ip'], Piwik_Tracker_Config::getInstance()->Tracker['ip_address_mask_length']);
}
}
|