Db
6 years ago
Handler
6 years ago
TableLogAction
6 years ago
Visit
6 years ago
Action.php
6 years ago
ActionPageview.php
6 years ago
Cache.php
6 years ago
Db.php
6 years ago
Failures.php
6 years ago
FingerprintSalt.php
6 years ago
GoalManager.php
6 years ago
Handler.php
6 years ago
IgnoreCookie.php
6 years ago
LogTable.php
6 years ago
Model.php
6 years ago
PageUrl.php
6 years ago
Request.php
5 years ago
RequestProcessor.php
6 years ago
RequestSet.php
6 years ago
Response.php
6 years ago
ScheduledTasksRunner.php
6 years ago
Settings.php
5 years ago
TableLogAction.php
6 years ago
TrackerCodeGenerator.php
6 years ago
TrackerConfig.php
6 years ago
Visit.php
5 years ago
VisitExcluded.php
6 years ago
VisitInterface.php
6 years ago
Visitor.php
6 years ago
VisitorNotFoundInDb.php
6 years ago
VisitorRecognizer.php
6 years ago
Settings.php
171 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Piwik - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 9 | namespace Piwik\Tracker; |
| 10 | |
| 11 | use Piwik\Config; |
| 12 | use Piwik\Container\StaticContainer; |
| 13 | use Piwik\Date; |
| 14 | use Piwik\Option; |
| 15 | use Piwik\SettingsServer; |
| 16 | use Piwik\Site; |
| 17 | use Piwik\Tracker; |
| 18 | use Piwik\DeviceDetector\DeviceDetectorFactory; |
| 19 | use Piwik\SettingsPiwik; |
| 20 | |
| 21 | class Settings // TODO: merge w/ visitor recognizer or make it it's own service. the class name is required for BC. |
| 22 | { |
| 23 | const OS_BOT = 'BOT'; |
| 24 | |
| 25 | /** |
| 26 | * If `true`, the config ID for a visitor will be the same no matter what site is being tracked. |
| 27 | * If `false, the config ID will be different. |
| 28 | * |
| 29 | * @var bool |
| 30 | */ |
| 31 | private $isSameFingerprintsAcrossWebsites; |
| 32 | |
| 33 | public function __construct($isSameFingerprintsAcrossWebsites) |
| 34 | { |
| 35 | $this->isSameFingerprintsAcrossWebsites = $isSameFingerprintsAcrossWebsites; |
| 36 | } |
| 37 | |
| 38 | public function getConfigId(Request $request, $ipAddress) |
| 39 | { |
| 40 | list($plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, |
| 41 | $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie) = $request->getPlugins(); |
| 42 | |
| 43 | $userAgent = $request->getUserAgent(); |
| 44 | |
| 45 | $deviceDetector = StaticContainer::get(DeviceDetectorFactory::class)->makeInstance($userAgent); |
| 46 | $aBrowserInfo = $deviceDetector->getClient(); |
| 47 | |
| 48 | if (empty($aBrowserInfo['type']) || 'browser' !== $aBrowserInfo['type']) { |
| 49 | // for now only track browsers |
| 50 | unset($aBrowserInfo); |
| 51 | } |
| 52 | |
| 53 | $browserName = !empty($aBrowserInfo['short_name']) ? $aBrowserInfo['short_name'] : 'UNK'; |
| 54 | $browserVersion = !empty($aBrowserInfo['version']) ? $aBrowserInfo['version'] : ''; |
| 55 | |
| 56 | if ($deviceDetector->isBot()) { |
| 57 | $os = self::OS_BOT; |
| 58 | } else { |
| 59 | $os = $deviceDetector->getOS(); |
| 60 | $os = empty($os['short_name']) ? 'UNK' : $os['short_name']; |
| 61 | } |
| 62 | |
| 63 | $client = $deviceDetector->getClient(); |
| 64 | if (!empty($client['name']) && $client['name'] === 'Internet Explorer') { |
| 65 | // we assume cookies are disabled... when in tracker cookies are disabled, this ensures when upgrading to this version |
| 66 | // that no fingerprint changes in the 30min window during the upgrade... |
| 67 | // We don't include it anymore as it otherwise may cause new visits to be created when switching between |
| 68 | // cookies disabled and enabled in IE11 or older. Before Matomo 3.13.7 when cookies were disabled, then |
| 69 | // this value was set to 0. For people with cookies enabled the fingerprint is not as relevant as the visitorId |
| 70 | // is used to identify a visitor |
| 71 | $plugin_Cookie = '0'; |
| 72 | } |
| 73 | |
| 74 | $browserLang = substr($request->getBrowserLanguage(), 0, 20); // limit the length of this string to match db |
| 75 | $trackerConfig = Config::getInstance()->Tracker; |
| 76 | |
| 77 | $fingerprintSalt = ''; |
| 78 | |
| 79 | // fingerprint salt won't work when across multiple sites since all sites could have different timezones |
| 80 | // also cant add fingerprint salt for a specific day when we dont create new visit after midnight |
| 81 | if (!$this->isSameFingerprintsAcrossWebsites && !empty($trackerConfig['create_new_visit_after_midnight'])) { |
| 82 | $cache = Cache::getCacheWebsiteAttributes($request->getIdSite()); |
| 83 | $date = Date::factory((int) $request->getCurrentTimestamp()); |
| 84 | $fingerprintSaltKey = new FingerprintSalt(); |
| 85 | $dateString = $fingerprintSaltKey->getDateString($date, $cache['timezone']); |
| 86 | |
| 87 | if (!empty($cache[FingerprintSalt::OPTION_PREFIX . $dateString])) { |
| 88 | $fingerprintSalt = $cache[FingerprintSalt::OPTION_PREFIX . $dateString]; |
| 89 | } else { |
| 90 | // we query the DB directly for requests older than 2-3 days... |
| 91 | $fingerprintSalt = $fingerprintSaltKey->getSalt($dateString, $request->getIdSite()); |
| 92 | } |
| 93 | |
| 94 | $fingerprintSalt .= $dateString; |
| 95 | |
| 96 | if (defined('PIWIK_TEST_MODE') && PIWIK_TEST_MODE) { |
| 97 | $fingerprintSalt = ''; // use fixed value so they don't change randomly in tests |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return $this->getConfigHash( |
| 102 | $request, |
| 103 | $os, |
| 104 | $browserName, |
| 105 | $browserVersion, |
| 106 | $plugin_Flash, |
| 107 | $plugin_Java, |
| 108 | $plugin_Director, |
| 109 | $plugin_Quicktime, |
| 110 | $plugin_RealPlayer, |
| 111 | $plugin_PDF, |
| 112 | $plugin_WindowsMedia, |
| 113 | $plugin_Gears, |
| 114 | $plugin_Silverlight, |
| 115 | $plugin_Cookie, |
| 116 | $ipAddress, |
| 117 | $browserLang, |
| 118 | $fingerprintSalt); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Returns a 64-bit hash that attemps to identify a user. |
| 123 | * Maintaining some privacy by default, eg. prevents the merging of several Piwik serve together for matching across instances.. |
| 124 | * |
| 125 | * @param $os |
| 126 | * @param $browserName |
| 127 | * @param $browserVersion |
| 128 | * @param $plugin_Flash |
| 129 | * @param $plugin_Java |
| 130 | * @param $plugin_Director |
| 131 | * @param $plugin_Quicktime |
| 132 | * @param $plugin_RealPlayer |
| 133 | * @param $plugin_PDF |
| 134 | * @param $plugin_WindowsMedia |
| 135 | * @param $plugin_Gears |
| 136 | * @param $plugin_Silverlight |
| 137 | * @param $plugin_Cookie |
| 138 | * @param $ip |
| 139 | * @param $browserLang |
| 140 | * @param $fingerprintHash |
| 141 | * @return string |
| 142 | */ |
| 143 | protected function getConfigHash(Request $request, $os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, |
| 144 | $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, |
| 145 | $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ip, |
| 146 | $browserLang, $fingerprintHash) |
| 147 | { |
| 148 | // prevent the config hash from being the same, across different Piwik instances |
| 149 | // (limits ability of different Piwik instances to cross-match users) |
| 150 | $salt = SettingsPiwik::getSalt(); |
| 151 | |
| 152 | $configString = |
| 153 | $os |
| 154 | . $browserName . $browserVersion |
| 155 | . $plugin_Flash . $plugin_Java . $plugin_Director . $plugin_Quicktime . $plugin_RealPlayer . $plugin_PDF |
| 156 | . $plugin_WindowsMedia . $plugin_Gears . $plugin_Silverlight . $plugin_Cookie |
| 157 | . $ip |
| 158 | . $browserLang |
| 159 | . $salt |
| 160 | . $fingerprintHash; |
| 161 | |
| 162 | if (!$this->isSameFingerprintsAcrossWebsites) { |
| 163 | $configString .= $request->getIdSite(); |
| 164 | } |
| 165 | |
| 166 | $hash = md5($configString, $raw_output = true); |
| 167 | |
| 168 | return substr($hash, 0, Tracker::LENGTH_BINARY_ID); |
| 169 | } |
| 170 | } |
| 171 |