function __construct() { $logToFileFilename = self::ID; $logToDatabaseTableName = self::ID; $logToDatabaseColumnMapping = null; $screenFormatter = new Piwik_Log_APICall_Formatter_ScreenFormatter(); $fileFormatter = new Piwik_Log_Formatter_FileFormatter(); parent::__construct($logToFileFilename, $fileFormatter, $screenFormatter, $logToDatabaseTableName, $logToDatabaseColumnMapping); $this->setEventItem('caller_ip', Piwik_IP::P2N(Piwik_IP::getIpFromHeader())); }
/** * Constructor */ function __construct() { $logToFileFilename = self::ID; $logToDatabaseTableName = self::ID; $logToDatabaseColumnMapping = array('class_name' => 'class_name', 'method_name' => 'method_name', 'parameter_names_default_values' => 'parameter_names_default_values', 'parameter_values' => 'parameter_values', 'execution_time' => 'execution_time', 'caller_ip' => 'caller_ip', 'timestamp' => 'timestamp', 'returned_value' => 'returned_value'); $screenFormatter = new Piwik_Log_APICall_Formatter_ScreenFormatter(); $fileFormatter = new Piwik_Log_Formatter_FileFormatter(); parent::__construct($logToFileFilename, $fileFormatter, $screenFormatter, $logToDatabaseTableName, $logToDatabaseColumnMapping); $this->setEventItem('caller_ip', Piwik_IP::P2N(Piwik_IP::getIpFromHeader())); }
/** * @group Core * @group Tracker * @group Tracker_Visit * @dataProvider getExcludedIpTestData */ public function testIsVisitorIpExcluded($excludedIp, $tests) { $visit = new Test_Piwik_TrackerVisit_public(); $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0, $excludedIp); $visit->setRequest(array('idsite' => $idsite)); // test that IPs within the range, or the given IP, are excluded foreach ($tests as $ip => $expected) { $testIpIsExcluded = Piwik_IP::P2N($ip); $this->assertSame($expected, $visit->public_isVisitorIpExcluded($testIpIsExcluded)); } }
function test_isVisitorIpExcluded() { $excludedIps = array('12.12.12.12' => array('12.12.12.12' => true, '12.12.12.11' => false, '12.12.12.13' => false, '0.0.0.0' => false, '255.255.255.255' => false), '12.12.12.12/32' => array('12.12.12.12' => true, '12.12.12.11' => false, '12.12.12.13' => false, '0.0.0.0' => false, '255.255.255.255' => false), '12.12.12.*' => array('12.12.12.0' => true, '12.12.12.255' => true, '12.12.12.12' => true, '12.12.11.255' => false, '12.12.13.0' => false, '0.0.0.0' => false, '255.255.255.255' => false), '12.12.12.0/24' => array('12.12.12.0' => true, '12.12.12.255' => true, '12.12.12.12' => true, '12.12.11.255' => false, '12.12.13.0' => false, '0.0.0.0' => false, '255.255.255.255' => false)); $visit = new Test_Piwik_TrackerVisit_public(); foreach ($excludedIps as $excludedIp => $tests) { $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0, $excludedIp); $visit->setRequest(array('idsite' => $idsite)); // test that IPs within the range, or the given IP, are excluded foreach ($tests as $ip => $expected) { $testIpIsExcluded = Piwik_IP::P2N($ip); $this->assertTrue($visit->public_isVisitorIpExcluded($testIpIsExcluded) === $expected, $ip . " is not excluded in " . $excludedIp); } } }
public function __construct($forcedIpString = null, $forcedDateTime = null) { $this->timestamp = time(); if (!empty($forcedDateTime)) { if (!is_numeric($forcedDateTime)) { $forcedDateTime = strtotime($forcedDateTime); } $this->timestamp = $forcedDateTime; } $ipString = $forcedIpString; if (empty($ipString)) { $ipString = Piwik_IP::getIpFromHeader(); } $ip = Piwik_IP::P2N($ipString); $this->ip = $ip; }
/** * @dataProvider getipv4Addresses * @group Plugins * @group AnonymizeIP */ public function testApplyIPMask($ip, $expected) { // each IP is tested with 0 to 4 octets masked for ($maskLength = 0; $maskLength <= 4; $maskLength++) { $res = Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N($ip), $maskLength); $this->assertEquals($expected[$maskLength], $res, "Got " . bin2hex($res) . ", Expected " . bin2hex($expected[$maskLength])); } // edge case (bounds check) $this->assertEquals("", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N($ip), 5)); // mask IPv4 mapped addresses for ($maskLength = 0; $maskLength <= 4; $maskLength++) { $res = Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('::ffff:' . $ip), $maskLength); $this->assertEquals($res, "ÿÿ" . $expected[$maskLength], "Got " . bin2hex($res) . ", Expected " . bin2hex($expected[$maskLength])); } $this->assertEquals("ÿ", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('::ffff:' . $ip), 5)); // edge case (bounds check) $this->assertEquals("", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('2001::ffff:' . $ip), 17)); }
public function __construct($forcedIpString = null, $forcedDateTime = null) { $this->timestamp = time(); if(!empty($forcedDateTime)) { if(!is_int($forcedDateTime)) { $forcedDateTime = strtotime($forcedDateTime); } $this->timestamp = $forcedDateTime; } $ipString = $forcedIpString; if(empty($ipString)) { $ipString = Piwik_IP::getIpFromHeader(); } $ip = Piwik_IP::P2N($ipString); Piwik_PostEvent('Tracker.Visit.setVisitorIp', $ip); $this->ip = $ip; }
/** * @group Core * @group IP * @dataProvider getIpsInRangeData */ public function testIsIpInRange($range, $test) { foreach ($test as $ip => $expected) { // range as a string $this->assertEquals($expected, Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($range)), "{$ip} in {$range}"); // range as an array(low, high) $aRange = Piwik_IP::getIpsForRange($range); $aRange[0] = Piwik_IP::N2P($aRange[0]); $aRange[1] = Piwik_IP::N2P($aRange[1]); $this->assertEquals($expected, Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($aRange)), "{$ip} in {$range}"); } }
function test_isIpInRange() { $tests = array('192.168.1.10' => array('192.168.1.9' => false, '192.168.1.10' => true, '192.168.1.11' => false, '::ffff:192.168.1.10' => false), '::ffff:192.168.1.10' => array('::ffff:192.168.1.9' => false, '::ffff:192.168.1.10' => true, '::ffff:c0a8:010a' => true, '0000:0000:0000:0000:0000:ffff:c0a8:010a' => true, '::ffff:192.168.1.11' => false, '192.168.1.10' => false), '192.168.1.10/32' => array('192.168.1.9' => false, '192.168.1.10' => true, '192.168.1.11' => false), '192.168.1.10/31' => array('192.168.1.9' => false, '192.168.1.10' => true, '192.168.1.11' => true, '192.168.1.12' => false), '192.168.1.128/25' => array('192.168.1.127' => false, '192.168.1.128' => true, '192.168.1.255' => true, '192.168.2.0' => false), '192.168.1.10/24' => array('192.168.0.255' => false, '192.168.1.0' => true, '192.168.1.1' => true, '192.168.1.2' => true, '192.168.1.3' => true, '192.168.1.4' => true, '192.168.1.7' => true, '192.168.1.8' => true, '192.168.1.15' => true, '192.168.1.16' => true, '192.168.1.31' => true, '192.168.1.32' => true, '192.168.1.63' => true, '192.168.1.64' => true, '192.168.1.127' => true, '192.168.1.128' => true, '192.168.1.255' => true, '192.168.2.0' => false), '192.168.1.*' => array('192.168.0.255' => false, '192.168.1.0' => true, '192.168.1.1' => true, '192.168.1.2' => true, '192.168.1.3' => true, '192.168.1.4' => true, '192.168.1.7' => true, '192.168.1.8' => true, '192.168.1.15' => true, '192.168.1.16' => true, '192.168.1.31' => true, '192.168.1.32' => true, '192.168.1.63' => true, '192.168.1.64' => true, '192.168.1.127' => true, '192.168.1.128' => true, '192.168.1.255' => true, '192.168.2.0' => false)); // testing with a single range foreach ($tests as $range => $test) { foreach ($test as $ip => $expected) { // range as a string $this->assertEqual(Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($range)), $expected, "{$ip} in {$range}"); // range as an array(low, high) $aRange = Piwik_IP::getIpsForRange($range); $aRange[0] = Piwik_IP::N2P($aRange[0]); $aRange[1] = Piwik_IP::N2P($aRange[1]); $this->assertEqual(Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($aRange)), $expected, "{$ip} in {$range}"); } } }
$f = fopen($clickheatConf['logPath'] . $final . '/' . date('Y-m-d') . '.log', 'a'); } if (is_resource($f)) { $logMe = true; if (isset($_COOKIE['clickheat-admin'])) { echo 'OK, but click not logged as you selected it in the admin panel ("Log my clicks/Enregistrer mes clics")'; $logMe = false; } elseif (IS_PIWIK_MODULE === true) { $site = (string) (int) $site; // prevents path injection if (file_exists(PIWIK_INCLUDE_PATH . '/tmp/cache/tracker/' . $site . '.php')) { include PIWIK_INCLUDE_PATH . '/tmp/cache/tracker/' . $site . '.php'; if (isset($content['excluded_ips'])) { include PIWIK_INCLUDE_PATH . '/core/Common.php'; include PIWIK_INCLUDE_PATH . '/core/IP.php'; $ip = Piwik_IP::P2N(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']); if (Piwik_IP::isIpInRange($ip, $content['excluded_ips']) === true) { echo 'OK, but click not logged as you prevent this IP to be tracked in Piwik\'s configuration'; $logMe = false; } } } } if ($logMe === true) { echo 'OK'; fputs($f, (int) $_GET['x'] . '|' . (int) $_GET['y'] . '|' . (int) $_GET['w'] . '|' . $browser . '|' . (int) $_GET['c'] . "\n"); } fclose($f); } else { echo 'KO, file not writable'; }