Пример #1
0
 /**
  * @param Request $request
  * @param Visitor $visitor
  * @param Action|null $action
  * @return mixed
  */
 public function onNewVisit(Request $request, Visitor $visitor, $action)
 {
     // Adding &dp=1 will disable the provider plugin, this is an "unofficial" parameter used to speed up log importer
     $disableProvider = $request->getParam('dp');
     if (!empty($disableProvider)) {
         return false;
     }
     // if provider info has already been set, abort
     $locationValue = $visitor->getVisitorColumn('location_provider');
     if (!empty($locationValue)) {
         return false;
     }
     $ip = $visitor->getVisitorColumn('location_ip');
     $privacyConfig = new PrivacyManagerConfig();
     if (!$privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $request->getIp();
     }
     $ip = IPUtils::binaryToStringIP($ip);
     // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking
     if (substr($ip, -2, 2) == '.0') {
         Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup...");
         return false;
     }
     $hostname = $this->getHost($ip);
     $hostnameExtension = ProviderPlugin::getCleanHostname($hostname);
     // add the provider value in the table log_visit
     $locationProvider = substr($hostnameExtension, 0, 100);
     return $locationProvider;
 }
Пример #2
0
 function getIp()
 {
     if (isset($this->details['location_ip'])) {
         return IPUtils::binaryToStringIP($this->details['location_ip']);
     }
     return null;
 }
Пример #3
0
 public function insertVisit($visit = array())
 {
     $defaultProperties = array('idsite' => 1, 'idvisitor' => $this->getDummyVisitorId(), 'visit_last_action_time' => '2012-01-01 00:00:00', 'config_id' => $this->getDummyVisitorId(), 'location_ip' => IPUtils::stringToBinaryIP('1.2.3.4'), 'visitor_localtime' => '2012-01-01 00:00:00', 'location_country' => 'xx', 'config_os' => 'xxx', 'visit_total_events' => 0, 'visitor_days_since_last' => 0, 'config_quicktime' => 0, 'config_pdf' => 0, 'config_realplayer' => 0, 'config_silverlight' => 0, 'config_windowsmedia' => 0, 'config_java' => 0, 'config_gears' => 0, 'config_resolution' => 0, 'config_resolution' => '', 'config_cookie' => 0, 'config_director' => 0, 'config_flash' => 0, 'config_browser_version' => '', 'visitor_count_visits' => 1, 'visitor_returning' => 0, 'visit_total_time' => 123, 'visit_entry_idaction_name' => 0, 'visit_entry_idaction_url' => 0, 'visitor_days_since_order' => 0, 'visitor_days_since_first' => 0, 'visit_first_action_time' => '2012-01-01 00:00:00', 'visit_goal_buyer' => 0, 'visit_goal_converted' => 0, 'visit_exit_idaction_name' => 0, 'referer_url' => '', 'location_browser_lang' => 'xx', 'config_browser_engine' => '', 'config_browser_name' => '', 'referer_type' => 0, 'referer_name' => '', 'visit_total_actions' => 0, 'visit_total_searches' => 0);
     $visit = array_merge($defaultProperties, $visit);
     $this->insertInto('log_visit', $visit);
     $idVisit = Db::fetchOne("SELECT LAST_INSERT_ID()");
     return $this->getVisit($idVisit, $allColumns = true);
 }
Пример #4
0
 private function getIpAddress($anonymizedIp, \Piwik\Tracker\Request $request)
 {
     $privacyConfig = new PrivacyManagerConfig();
     $ip = $request->getIp();
     if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $anonymizedIp;
     }
     $ipAddress = IPUtils::binaryToStringIP($ip);
     return $ipAddress;
 }
 /**
  *
  * @param Visitor $visitor            
  * @param Request $request            
  *
  * @return string
  */
 private function getIpAddress(Visitor $visitor, Request $request)
 {
     if ($this->ipToUse !== null) {
         return $this->ipToUse;
     }
     $privacyConfig = new PrivacyManagerConfig();
     $ip = $request->getIp();
     if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $visitor->getVisitorColumn('location_ip');
     }
     $ip = IPUtils::binaryToStringIP($ip);
     $this->ipToUse = $ip;
     return $ip;
 }
Пример #6
0
 public function insertVisitorLocation(&$visitorInfo, \Piwik\Tracker\Request $request)
 {
     $dbPath = PIWIK_INCLUDE_PATH . '/plugins/IP2Location/data/';
     $dbFile = '';
     if ($handle = opendir($dbPath)) {
         while (false !== ($file = readdir($handle))) {
             if (strtoupper(substr($file, -4)) == '.BIN') {
                 $dbFile = $dbPath . $file;
                 break;
             }
         }
         closedir($handle);
     }
     if ($dbFile) {
         $privacyConfig = new PrivacyManagerConfig();
         $ipAddress = IPUtils::binaryToStringIP($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp());
         $result = IP2LocationAPI::lookup($ipAddress, $dbFile);
         $countryCode = $result['countryCode'] != '-' ? strtolower($result['countryCode']) : null;
         $regionName = $result['regionName'] != '-' ? $result['regionName'] : null;
         $regionCode = $this->getRegionCode(strtoupper($countryCode), $regionName);
         $cityName = !preg_match('/not supported/', $result['cityName']) && $result['cityName'] != '-' ? $result['cityName'] : null;
         $latitude = !preg_match('/not supported/', $result['latitude']) && $result['latitude'] != '-' ? $result['latitude'] : null;
         $longitude = !preg_match('/not supported/', $result['longitude']) && $result['longitude'] != '-' ? $result['longitude'] : null;
         if ($countryCode) {
             $visitorInfo['location_country'] = $countryCode;
         }
         if ($regionCode) {
             $visitorInfo['location_region'] = $regionCode;
         }
         if ($cityName) {
             $visitorInfo['location_city'] = $cityName;
         }
         if ($latitude) {
             $visitorInfo['location_latitude'] = $latitude;
         }
         if ($longitude) {
             $visitorInfo['location_longitude'] = $longitude;
         }
     }
 }
Пример #7
0
 private function printVisitorInformation()
 {
     $debugVisitInfo = $this->visitProperties->getProperties();
     $debugVisitInfo['idvisitor'] = bin2hex($debugVisitInfo['idvisitor']);
     $debugVisitInfo['config_id'] = bin2hex($debugVisitInfo['config_id']);
     $debugVisitInfo['location_ip'] = IPUtils::binaryToStringIP($debugVisitInfo['location_ip']);
     Common::printDebug($debugVisitInfo);
 }
Пример #8
0
 public function getIp()
 {
     return IPUtils::stringToBinaryIP($this->getIpString());
 }
Пример #9
0
 /**
  * Returns the last IP address in a comma separated list, subject to an optional exclusion list.
  *
  * @param string $csv Comma separated list of elements.
  * @param array $excludedIps Optional list of excluded IP addresses (or IP address ranges).
  * @return string Last (non-excluded) IP address in the list or an empty string if all given IPs are excluded.
  */
 public static function getLastIpFromList($csv, $excludedIps = null)
 {
     $p = strrpos($csv, ',');
     if ($p !== false) {
         $elements = explode(',', $csv);
         for ($i = count($elements); $i--;) {
             $element = trim(Common::sanitizeInputValue($elements[$i]));
             $ip = \Piwik\Network\IP::fromStringIP(IPUtils::sanitizeIp($element));
             if (empty($excludedIps) || !in_array($element, $excludedIps) && !$ip->isInRanges($excludedIps)) {
                 return $element;
             }
         }
         return '';
     }
     return trim(Common::sanitizeInputValue($csv));
 }
Пример #10
0
        }
    }
    $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')) {
            require_once PIWIK_INCLUDE_PATH . '/tmp/cache/tracker/' . $site . '.php';
            if (isset($content['excluded_ips'])) {
                $ip = IPUtils::stringToBinaryIP(\Piwik\Network\IP::fromStringIP(IP::getIpFromHeader()));
                if (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';
}
Пример #11
0
 /**
  * Returns hostname, without port numbers
  *
  * @param $host
  * @return array
  */
 public static function getHostSanitized($host)
 {
     if (!class_exists("Piwik\\Network\\IPUtils")) {
         throw new Exception("Piwik\\Network\\IPUtils could not be found, maybe you are using Piwik from git and need to update Composer. \$ php composer.phar update");
     }
     return IPUtils::sanitizeIp($host);
 }
Пример #12
0
 /**
  * Geolcates an existing visit and then updates it if it's current attributes are different than
  * what was geolocated. Also updates all conversions of a visit.
  *
  * **This method should NOT be used from within the tracker.**
  *
  * @param array $visit The visit information. Must contain an `"idvisit"` element and `"location_ip"` element.
  * @param bool $useClassCache
  * @return array|null The visit properties that were updated in the DB mapped to the updated values. If null,
  *                    required information was missing from `$visit`.
  */
 public function attributeExistingVisit($visit, $useClassCache = true)
 {
     if (empty($visit['idvisit'])) {
         $this->logger->debug('Empty idvisit field. Skipping re-attribution..');
         return null;
     }
     $idVisit = $visit['idvisit'];
     if (empty($visit['location_ip'])) {
         $this->logger->debug('Empty location_ip field for idvisit = %s. Skipping re-attribution.', array('idvisit' => $idVisit));
         return null;
     }
     $ip = IPUtils::binaryToStringIP($visit['location_ip']);
     $location = $this->getLocation(array('ip' => $ip), $useClassCache);
     $valuesToUpdate = $this->getVisitFieldsToUpdate($visit, $location);
     if (!empty($valuesToUpdate)) {
         $this->logger->debug('Updating visit with idvisit = {idVisit} (IP = {ip}). Changes: {changes}', array('idVisit' => $idVisit, 'ip' => $ip, 'changes' => $valuesToUpdate));
         $this->dao->updateVisits($valuesToUpdate, $idVisit);
         $this->dao->updateConversions($valuesToUpdate, $idVisit);
     } else {
         $this->logger->debug('Nothing to update for idvisit = %s (IP = {ip}). Existing location info is same as geolocated.', array('idVisit' => $idVisit, 'ip' => $ip));
     }
     return $valuesToUpdate;
 }
 private function insertVisit($visit = array())
 {
     $defaultProperties = array('location_ip' => IPUtils::stringToBinaryIP(self::TEST_IP));
     return $this->logInserter->insertVisit(array_merge($defaultProperties, $visit));
 }
Пример #14
0
 public function test_getIp()
 {
     $ip = $_SERVER['REMOTE_ADDR'];
     $this->assertEquals(IPUtils::stringToBinaryIP($ip), $this->request->getIp());
 }
Пример #15
0
 /**
  * @group IpIsKnownBot
  */
 public function testIsVisitor_ipIsKnownBot()
 {
     $isIpBot = array('66.249.85.36' => true, '66.249.91.150' => true, '64.233.172.1' => true, '64.233.172.200' => true, '66.249.88.216' => true, '66.249.83.204' => true, '64.233.172.6' => true, '1.202.218.8' => true, '66.248.91.150' => false, '66.250.91.150' => false, '66.249.2.1' => false, '66.249.60.1' => false);
     $idsite = API::getInstance()->addSite("name", "http://piwik.net/");
     $request = new Request(array('idsite' => $idsite, 'bots' => 0));
     foreach ($isIpBot as $ip => $isBot) {
         $excluded = new VisitExcluded_public($request, IPUtils::stringToBinaryIP($ip));
         $this->assertSame($isBot, $excluded->public_isNonHumanBot(), $ip);
     }
 }
Пример #16
0
 /**
  * Tests if the IP is a valid IP, allowing wildcards, except in the first octet.
  * Wildcards can only be used from right to left, ie. 1.1.*.* is allowed, but 1.1.*.1 is not.
  *
  * @param string $ip IP address
  * @return bool
  */
 private function isValidIp($ip)
 {
     return IPUtils::getIPRangeBounds($ip) !== null;
 }
Пример #17
0
 private function makeExcludeIps()
 {
     return $this->makeProperty('excluded_ips', $default = array(), FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
         $ip = IP::getIpFromHeader();
         $field->title = Piwik::translate('SitesManager_ExcludedIps');
         $field->inlineHelp = Piwik::translate('SitesManager_HelpExcludedIps', array('1.2.3.*', '1.2.*.*')) . '<br /><br />' . Piwik::translate('SitesManager_YourCurrentIpAddressIs', array('<i>' . $ip . '</i>'));
         $field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
         $field->uiControlAttributes = array('cols' => '20', 'rows' => '4');
         $field->validate = function ($value) {
             if (!empty($value)) {
                 $ips = array_map('trim', $value);
                 $ips = array_filter($ips, 'strlen');
                 foreach ($ips as $ip) {
                     if (IPUtils::getIPRangeBounds($ip) === null) {
                         throw new Exception(Piwik::translate('SitesManager_ExceptionInvalidIPFormat', array($ip, "1.2.3.4, 1.2.3.*, or 1.2.3.4/5")));
                     }
                 }
             }
         };
         $field->transform = function ($value) {
             if (empty($value)) {
                 return array();
             }
             $ips = array_map('trim', $value);
             $ips = array_filter($ips, 'strlen');
             return $ips;
         };
     });
 }