/** * @internal */ public function setAnonymizeIpSettings($anonymizeIPEnable, $maskLength, $useAnonymizedIpForVisitEnrichment) { Piwik::checkUserHasSuperUserAccess(); if ($anonymizeIPEnable == '1') { IPAnonymizer::activate(); } else { if ($anonymizeIPEnable == '0') { IPAnonymizer::deactivate(); } else { // pass } } $privacyConfig = new Config(); $privacyConfig->ipAddressMaskLength = (int) $maskLength; $privacyConfig->useAnonymizedIpForVisitEnrichment = (bool) $useAnonymizedIpForVisitEnrichment; return true; }
public function setUp() { self::downloadGeoIpDbs(); parent::setUp(); self::updateDatabase(); // make sure site has an early enough creation date (for period selector tests) Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1"); // for proper geolocation LocationProvider::setCurrentProvider(LocationProvider\GeoIp\Php::ID); IPAnonymizer::deactivate(); $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); SitesManagerAPI::getInstance()->updateSite(1, null, null, true); // create non super user UsersManagerAPI::getInstance()->addUser('oliverqueen', 'smartypants', '*****@*****.**'); UsersManagerAPI::getInstance()->setUserAccess('oliverqueen', 'view', array(1)); }
public function saveSettings() { Piwik::checkUserHasSuperUserAccess(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $this->checkTokenInUrl(); switch (Common::getRequestVar('form')) { case "formMaskLength": $enable = Common::getRequestVar("anonymizeIPEnable", 0); if ($enable == 1) { IPAnonymizer::activate(); } else { if ($enable == 0) { IPAnonymizer::deactivate(); } else { // pass } } $privacyConfig = new Config(); $privacyConfig->ipAddressMaskLength = Common::getRequestVar("maskLength", 1); $privacyConfig->useAnonymizedIpForVisitEnrichment = Common::getRequestVar("useAnonymizedIpForVisitEnrichment", 1); break; case "formDeleteSettings": $this->checkDataPurgeAdminSettingsIsEnabled(); $settings = $this->getPurgeSettingsFromRequest(); PrivacyManager::savePurgeDataSettings($settings); break; default: //do nothing break; } } $notification = new Notification(Piwik::translate('General_YourChangesHaveBeenSaved')); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('PrivacyManager_ChangesHaveBeenSaved', $notification); $this->redirectToIndex('PrivacyManager', 'privacySettings', null, null, null, array('updated' => 1)); }
public function performSetUp($setupEnvironmentOnly = false) { try { if ($this->createConfig) { Config::getInstance()->setTestEnvironment(); } $this->dbName = $this->getDbName(); if ($this->persistFixtureData) { $this->dropDatabaseInSetUp = false; $this->dropDatabaseInTearDown = false; $this->overwriteExisting = false; $this->removeExistingSuperUser = false; Config::getInstance()->database_tests['dbname'] = Config::getInstance()->database['dbname'] = $this->dbName; $this->getTestEnvironment()->dbName = $this->dbName; } if ($this->dbName === false) { // must be after test config is created $this->dbName = Config::getInstance()->database['dbname']; } static::connectWithoutDatabase(); if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) { $this->dropDatabase(); } DbHelper::createDatabase($this->dbName); DbHelper::disconnectDatabase(); // reconnect once we're sure the database exists Config::getInstance()->database['dbname'] = $this->dbName; Db::createDatabaseObject(); Db::get()->query("SET wait_timeout=28800;"); DbHelper::createTables(); \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); } catch (Exception $e) { static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); } include "DataFiles/SearchEngines.php"; include "DataFiles/Socials.php"; include "DataFiles/Languages.php"; include "DataFiles/Countries.php"; include "DataFiles/Currencies.php"; include "DataFiles/LanguageToCountry.php"; include "DataFiles/Providers.php"; if (!$this->isFixtureSetUp()) { DbHelper::truncateAllTables(); } static::createAccessInstance(); // We need to be SU to create websites for tests Piwik::setUserHasSuperUserAccess(); Cache::deleteTrackerCache(); static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass, $this->extraPluginsToLoad); self::updateDatabase(); self::installAndActivatePlugins(); $_GET = $_REQUEST = array(); $_SERVER['HTTP_REFERER'] = ''; // Make sure translations are loaded to check messages in English if ($this->loadTranslations) { Translate::reloadLanguage('en'); APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en'); } FakeAccess::$superUserLogin = '******'; \Piwik\SettingsPiwik::$cachedKnownSegmentsToArchive = null; \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true; if ($this->configureComponents) { \Piwik\Plugins\PrivacyManager\IPAnonymizer::deactivate(); \Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker::deactivate(); } if ($this->createSuperUser) { self::createSuperUser($this->removeExistingSuperUser); } if ($setupEnvironmentOnly) { return; } $this->getTestEnvironment()->save(); $this->getTestEnvironment()->executeSetupTestEnvHook(); Piwik_TestingEnvironment::addSendMailHook(); if ($this->overwriteExisting || !$this->isFixtureSetUp()) { $this->setUp(); $this->markFixtureSetUp(); $this->log("Database {$this->dbName} marked as successfully set up."); } else { $this->log("Using existing database {$this->dbName}."); } }
public function performSetUp($setupEnvironmentOnly = false) { // TODO: don't use static var, use test env var for this TestingEnvironmentManipulator::$extraPluginsToLoad = $this->extraPluginsToLoad; $this->dbName = $this->getDbName(); if ($this->persistFixtureData) { $this->dropDatabaseInSetUp = false; $this->dropDatabaseInTearDown = false; $this->overwriteExisting = false; $this->removeExistingSuperUser = false; } $testEnv = $this->getTestEnvironment(); $testEnv->testCaseClass = $this->testCaseClass; $testEnv->fixtureClass = get_class($this); $testEnv->dbName = $this->dbName; $testEnv->extraDiEnvironments = $this->extraDiEnvironments; foreach ($this->extraTestEnvVars as $name => $value) { $testEnv->{$name} = $value; } $testEnv->save(); $this->createEnvironmentInstance(); if ($this->dbName === false) { // must be after test config is created $this->dbName = self::getConfig()->database['dbname']; } try { static::connectWithoutDatabase(); if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) { $this->dropDatabase(); } DbHelper::createDatabase($this->dbName); DbHelper::disconnectDatabase(); Tracker::disconnectCachedDbConnection(); // reconnect once we're sure the database exists self::getConfig()->database['dbname'] = $this->dbName; Db::createDatabaseObject(); Db::get()->query("SET wait_timeout=28800;"); DbHelper::createTables(); self::getPluginManager()->unloadPlugins(); } catch (Exception $e) { static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); } include "DataFiles/Providers.php"; if (!$this->isFixtureSetUp()) { DbHelper::truncateAllTables(); } // We need to be SU to create websites for tests Access::getInstance()->setSuperUserAccess(); Cache::deleteTrackerCache(); self::resetPluginsInstalledConfig(); $testEnvironment = $this->getTestEnvironment(); static::loadAllPlugins($testEnvironment, $this->testCaseClass, $this->extraPluginsToLoad); self::updateDatabase(); self::installAndActivatePlugins($testEnvironment); $_GET = $_REQUEST = array(); $_SERVER['HTTP_REFERER'] = ''; FakeAccess::$superUserLogin = '******'; File::$invalidateOpCacheBeforeRead = true; if ($this->configureComponents) { IPAnonymizer::deactivate(); $dntChecker = new DoNotTrackHeaderChecker(); $dntChecker->deactivate(); } if ($this->createSuperUser) { self::createSuperUser($this->removeExistingSuperUser); if (!Access::getInstance() instanceof FakeAccess) { $this->loginAsSuperUser(); } APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en'); } SettingsPiwik::overwritePiwikUrl(self::getTestRootUrl()); if ($setupEnvironmentOnly) { return; } PiwikCache::getTransientCache()->flushAll(); if ($this->overwriteExisting || !$this->isFixtureSetUp()) { $this->setUp(); $this->markFixtureSetUp(); $this->log("Database {$this->dbName} marked as successfully set up."); } else { $this->log("Using existing database {$this->dbName}."); } }
protected function handlePluginState($state = 0) { if ($state == 1) { IPAnonymizer::activate(); } else { if ($state == 0) { IPAnonymizer::deactivate(); } else { // pass } } }
/** * Process the submit on the Installation "default settings" form. * * @param FormDefaultSettings $form */ public function installationFormSubmit(FormDefaultSettings $form) { $doNotTrack = (bool) $form->getSubmitValue('do_not_track'); $dntChecker = new DoNotTrackHeaderChecker(); if ($doNotTrack) { $dntChecker->activate(); } else { $dntChecker->deactivate(); } $anonymiseIp = (bool) $form->getSubmitValue('anonymise_ip'); if ($anonymiseIp) { IPAnonymizer::activate(); } else { IPAnonymizer::deactivate(); } }