/** * 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: " . $ipObject->toString()); return; } $privacyConfig = new Config(); $newIpObject = self::applyIPMask($ipObject, $privacyConfig->ipAddressMaskLength); $ip = $newIpObject->toBinary(); Common::printDebug("Visitor IP (was: " . $ipObject->toString() . ") has been anonymized: " . $newIpObject->toString()); }
/** * Checks if the visitor ip is in the excluded list * * @return bool */ protected function isVisitorIpExcluded() { $websiteAttributes = Cache::getCacheWebsiteAttributes($this->idSite); if (!empty($websiteAttributes['excluded_ips'])) { $ip = IP::fromBinaryIP($this->ip); if ($ip->isInRanges($websiteAttributes['excluded_ips'])) { Common::printDebug('Visitor IP ' . $ip->toString() . ' is excluded from being tracked'); return true; } } return false; }
function isIpInRange($ip, $ipRanges) { $ip = \Piwik\Network\IP::fromBinaryIP($ip); return $ip->isInRanges($ipRanges); }
/** * Determines if the IP address is in a search engine bot IP address range * * @param $ip * @return bool */ public static function isInRangesOfSearchBots($ip) { $ip = IP::fromBinaryIP($ip); $isInRanges = $ip->isInRanges(self::getBotIpRanges()); return $isInRanges; }
/** * Called by event `Tracker.newVisitorInformation` * * @see getListHooksRegistered() */ public function logIntranetSubNetworkInfo(&$visitorInfo) { if (!file_exists($this->getDataFilePath())) { Log::error('Plugin IntranetGeoIP does not work. File is missing: ' . $this->getDataFilePath()); return; } $data = (include $this->getDataFilePath()); if ($data === false) { // no data file found // @todo ...inform the user/ log something Log::error('Plugin IntranetGeoIP does not work. File is missing: ' . $this->getDataFilePath()); return; } foreach ($data as $value) { $ip = Network\IP::fromBinaryIP($visitorInfo['location_ip']); if (isset($value['networks']) && $ip->isInRanges($value['networks']) === true) { // values with the same key are not overwritten by right! // http://www.php.net/manual/en/language.operators.array.php if (isset($value['visitorInfo'])) { $visitorInfo = $value['visitorInfo'] + $visitorInfo; } return; } } // if nothing was matched, you can define default values if you want to if (isset($data['noMatch']) && isset($data['noMatch']['visitorInfo'])) { $visitorInfo = $data['noMatch']['visitorInfo'] + $visitorInfo; return; } }