diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-02-04 05:14:02 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-02-04 05:14:02 +0400 |
commit | e36c5964faa34157f3b01398c997c63918d71897 (patch) | |
tree | f5ddb7d98d6c77e652c3c5733e8e6cf1f07c717f /plugins | |
parent | da093df73c783da880ae1b5d989318341790f9d8 (diff) |
refs #4563 PrivacyManager Settings should be in Config and Option table, also removed some completely from config as described in ticket
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/PrivacyManager/Config.php | 109 | ||||
-rw-r--r-- | plugins/PrivacyManager/Controller.php | 35 | ||||
-rw-r--r-- | plugins/PrivacyManager/DoNotTrackHeaderChecker.php | 36 | ||||
-rw-r--r-- | plugins/PrivacyManager/IPAnonymizer.php | 42 | ||||
-rw-r--r-- | plugins/PrivacyManager/PrivacyManager.php | 85 | ||||
-rw-r--r-- | plugins/Provider/Provider.php | 4 | ||||
m--------- | plugins/SecurityInfo | 0 | ||||
m--------- | plugins/TasksTimetable | 0 | ||||
m--------- | plugins/TreemapVisualization | 0 | ||||
-rw-r--r-- | plugins/UserCountry/UserCountry.php | 6 | ||||
m--------- | plugins/VisitorGenerator | 0 |
11 files changed, 182 insertions, 135 deletions
diff --git a/plugins/PrivacyManager/Config.php b/plugins/PrivacyManager/Config.php new file mode 100644 index 0000000000..3e5c0d5156 --- /dev/null +++ b/plugins/PrivacyManager/Config.php @@ -0,0 +1,109 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\PrivacyManager; + +use Piwik\Option; +use Piwik\Tracker\Cache; + +/** + * @property bool $doNotTrackEnabled Enable / Disable Do Not Track {@see DoNotTrackHeaderChecker} + * @property bool $ipAnonymizerEnabled Enable / Disable IP Anonymizer {@see IPAnonymizer} + * @property bool $useAnonymizedIpForVisitEnrichment Set this setting to 0 to let plugins use the full + * non-anonymized IP address when enriching visitor information. + * When set to 1, by default, Geo Location via geoip and Provider reverse name lookups + * will use the anonymized IP address when anonymization is enabled. + * @property int $ipAddressMaskLength Anonymize a visitor's IP address after testing for "Ip exclude" + * This value is the level of anonymization Piwik will use; if the IP + * anonymization is deactivated, this value is ignored. For IPv4/IPv6 addresses, + * valid values are the number of octets in IP address to mask (from 0 to 4). + * For IPv6 addresses 0..4 means that 0, 64, 80, 104 or all bits are masked. + */ +class Config +{ + private $properties = array( + 'useAnonymizedIpForVisitEnrichment' => array('type' => 'boolean', 'default' => true), + 'ipAddressMaskLength' => array('type' => 'integer', 'default' => 1), + 'doNotTrackEnabled' => array('type' => 'boolean', 'default' => false), + 'ipAnonymizerEnabled' => array('type' => 'boolean', 'default' => false), + ); + + public function __set($name, $value) + { + if (!array_key_exists($name, $this->properties)) { + throw new \Exception(sprintf('Property %s does not exist', $name)); + } + + $this->set($name, $value, $this->properties[$name]); + } + + public function __get($name) + { + if (!array_key_exists($name, $this->properties)) { + throw new \Exception(sprintf('Property %s does not exist', $name)); + } + + return $this->getFromTrackerCache($name, $this->properties[$name]); + } + + private function prefix($optionName) + { + return 'PrivacyManager.' . $optionName; + } + + private function getFromTrackerCache($name, $config) + { + $name = $this->prefix($name); + $cache = Cache::getCacheGeneral(); + + if (array_key_exists($name, $cache)) { + + $value = $cache[$name]; + settype($value, $config['type']); + return $value; + } + + return $config['default']; + } + + private function getFromOption($name, $config) + { + $name = $this->prefix($name); + $value = Option::get($name); + + if (false !== $value) { + settype($value, $config['type']); + } else { + $value = $config['default']; + } + + return $value; + } + + private function set($name, $value, $config) + { + if ('boolean' == $config['type']) { + $value = $value ? '1' : '0'; + } else { + settype($value, $config['type']); + } + + Option::set($this->prefix($name), $value); + Cache::clearCacheGeneral(); + } + + public function setTrackerCacheGeneral($cacheContent) + { + foreach ($this->properties as $name => $config) { + $cacheContent[$this->prefix($name)] = $this->getFromOption($name, $config); + } + + return $cacheContent; + } + +} diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php index bda1c080b1..0ea3dffefd 100644 --- a/plugins/PrivacyManager/Controller.php +++ b/plugins/PrivacyManager/Controller.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\PrivacyManager; use Piwik\Common; -use Piwik\Config; +use Piwik\Config as PiwikConfig; use Piwik\Date; use Piwik\Db; use Piwik\MetricsFormatter; @@ -39,11 +39,9 @@ class Controller extends \Piwik\Plugin\ControllerAdmin switch (Common::getRequestVar('form')) { case("formMaskLength"): $this->handlePluginState(Common::getRequestVar("anonymizeIPEnable", 0)); - $trackerConfig = Config::getInstance()->Tracker; - $trackerConfig['ip_address_mask_length'] = Common::getRequestVar("maskLength", 1); - $trackerConfig['use_anonymized_ip_for_visit_enrichment'] = Common::getRequestVar("useAnonymizedIpForVisitEnrichment", 1); - Config::getInstance()->Tracker = $trackerConfig; - Config::getInstance()->forceSave(); + $privacyConfig = new Config(); + $privacyConfig->ipAddressMaskLength = Common::getRequestVar("maskLength", 1); + $privacyConfig->useAnonymizedIpForVisitEnrichment = Common::getRequestVar("useAnonymizedIpForVisitEnrichment", 1); break; case("formDeleteSettings"): @@ -91,15 +89,14 @@ class Controller extends \Piwik\Plugin\ControllerAdmin $settings['delete_reports_enable'] = Common::getRequestVar("deleteReportsEnable", 0); $deleteReportsOlderThan = Common::getRequestVar("deleteReportsOlderThan", 3); $settings['delete_reports_older_than'] = $deleteReportsOlderThan < 3 ? 3 : $deleteReportsOlderThan; - $settings['delete_reports_keep_basic_metrics'] = Common::getRequestVar("deleteReportsKeepBasic", 0); - $settings['delete_reports_keep_day_reports'] = Common::getRequestVar("deleteReportsKeepDay", 0); - $settings['delete_reports_keep_week_reports'] = Common::getRequestVar("deleteReportsKeepWeek", 0); - $settings['delete_reports_keep_month_reports'] = Common::getRequestVar("deleteReportsKeepMonth", 0); - $settings['delete_reports_keep_year_reports'] = Common::getRequestVar("deleteReportsKeepYear", 0); - $settings['delete_reports_keep_range_reports'] = Common::getRequestVar("deleteReportsKeepRange", 0); + $settings['delete_reports_keep_basic_metrics'] = Common::getRequestVar("deleteReportsKeepBasic", 0); + $settings['delete_reports_keep_day_reports'] = Common::getRequestVar("deleteReportsKeepDay", 0); + $settings['delete_reports_keep_week_reports'] = Common::getRequestVar("deleteReportsKeepWeek", 0); + $settings['delete_reports_keep_month_reports'] = Common::getRequestVar("deleteReportsKeepMonth", 0); + $settings['delete_reports_keep_year_reports'] = Common::getRequestVar("deleteReportsKeepYear", 0); + $settings['delete_reports_keep_range_reports'] = Common::getRequestVar("deleteReportsKeepRange", 0); $settings['delete_reports_keep_segment_reports'] = Common::getRequestVar("deleteReportsKeepSegments", 0); - - $settings['delete_logs_max_rows_per_query'] = PrivacyManager::DEFAULT_MAX_ROWS_PER_QUERY; + $settings['delete_logs_max_rows_per_query'] = PiwikConfig::getInstance()->Deletelogs['delete_logs_max_rows_per_query']; return $settings; } @@ -130,7 +127,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin $view->anonymizeIP = $this->getAnonymizeIPInfo(); $view->dntSupport = DoNotTrackHeaderChecker::isActive(); $view->canDeleteLogActions = Db::isLockPrivilegeGranted(); - $view->dbUser = Config::getInstance()->database['username']; + $view->dbUser = PiwikConfig::getInstance()->database['username']; $view->deactivateNonce = Nonce::getNonce(self::DEACTIVATE_DNT_NONCE); $view->activateNonce = Nonce::getNonce(self::ACTIVATE_DNT_NONCE); } @@ -179,7 +176,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin $settings = PrivacyManager::getPurgeDataSettings(); } - $doDatabaseSizeEstimate = Config::getInstance()->Deletelogs['enable_auto_database_size_estimate']; + $doDatabaseSizeEstimate = PiwikConfig::getInstance()->Deletelogs['enable_auto_database_size_estimate']; // determine the DB size & purged DB size $metadataProvider = new MySQLMetadataProvider(); @@ -230,10 +227,10 @@ class Controller extends \Piwik\Plugin\ControllerAdmin Piwik::checkUserHasSuperUserAccess(); $anonymizeIP = array(); - $trackerConfig = Config::getInstance()->Tracker; + $privacyConfig = new Config(); $anonymizeIP["enabled"] = IpAnonymizer::isActive(); - $anonymizeIP["maskLength"] = $trackerConfig['ip_address_mask_length']; - $anonymizeIP["useAnonymizedIpForVisitEnrichment"] = $trackerConfig['use_anonymized_ip_for_visit_enrichment']; + $anonymizeIP["maskLength"] = $privacyConfig->ipAddressMaskLength; + $anonymizeIP["useAnonymizedIpForVisitEnrichment"] = $privacyConfig->useAnonymizedIpForVisitEnrichment; return $anonymizeIP; } diff --git a/plugins/PrivacyManager/DoNotTrackHeaderChecker.php b/plugins/PrivacyManager/DoNotTrackHeaderChecker.php index a139f0b93c..0b20f32383 100644 --- a/plugins/PrivacyManager/DoNotTrackHeaderChecker.php +++ b/plugins/PrivacyManager/DoNotTrackHeaderChecker.php @@ -11,8 +11,6 @@ namespace Piwik\Plugins\PrivacyManager; use Piwik\Common; use Piwik\Tracker\IgnoreCookie; use Piwik\Tracker\Request; -use Piwik\Tracker\Cache; -use Piwik\Option; /** * Excludes visits where user agent's request contains either: @@ -23,14 +21,12 @@ use Piwik\Option; */ class DoNotTrackHeaderChecker { - const OPTION_NAME = "PrivacyManager.doNotTrackEnabled"; - /** * Checks for DoNotTrack headers and if found, sets `$exclude` to `true`. */ public function checkHeaderInTracker(&$exclude) { - if (!$this->isActiveInTracker() + if (!$this->isActive() || $exclude ) { return; @@ -61,30 +57,12 @@ class DoNotTrackHeaderChecker } /** - * Returns true if DoNotTrack header checking is enabled. This function is called by the - * Tracker. - */ - private function isActiveInTracker() - { - $cache = Cache::getCacheGeneral(); - return !empty($cache[self::OPTION_NAME]); - } - - /** - * Caches the status of DoNotTrack checking (whether it is enabled or not). - */ - public function setTrackerCacheGeneral(&$cacheContent) - { - $cacheContent[self::OPTION_NAME] = Option::get(self::OPTION_NAME); - } - - /** * Deactivates DoNotTrack header checking. This function will not be called by the Tracker. */ public static function deactivate() { - Option::set(self::OPTION_NAME, 0); - Cache::clearCacheGeneral(); + $config = new Config(); + $config->doNotTrackEnabled = false; } /** @@ -92,8 +70,8 @@ class DoNotTrackHeaderChecker */ public static function activate() { - Option::set(self::OPTION_NAME, 1); - Cache::clearCacheGeneral(); + $config = new Config(); + $config->doNotTrackEnabled = true; } /** @@ -103,7 +81,7 @@ class DoNotTrackHeaderChecker */ public static function isActive() { - $active = Option::get(self::OPTION_NAME); - return !empty($active); + $config = new Config(); + return $config->doNotTrackEnabled; } } diff --git a/plugins/PrivacyManager/IPAnonymizer.php b/plugins/PrivacyManager/IPAnonymizer.php index bf639e08c7..9bff7c14d6 100644 --- a/plugins/PrivacyManager/IPAnonymizer.php +++ b/plugins/PrivacyManager/IPAnonymizer.php @@ -9,19 +9,13 @@ namespace Piwik\Plugins\PrivacyManager; use Piwik\Common; -use Piwik\Config; use Piwik\IP; -use Piwik\Tracker\Cache; -use Piwik\Option; /** * Anonymize visitor IP addresses to comply with the privacy laws/guidelines in countries, such as Germany. - * */ class IPAnonymizer { - const OPTION_NAME = "PrivacyManager.ipAnonymizerEnabled"; - /** * Internal function to mask portions of the visitor IP address * @@ -58,33 +52,17 @@ class IPAnonymizer */ public function setVisitorIpAddress(&$ip) { - - if (!$this->isActiveInTracker()) { + if (!$this->isActive()) { Common::printDebug("Visitor IP was _not_ anonymized: ". IP::N2P($ip)); return; } $originalIp = $ip; - $ip = self::applyIPMask($ip, Config::getInstance()->Tracker['ip_address_mask_length']); - Common::printDebug("Visitor IP (was: ". IP::N2P($originalIp) .") has been anonymized: ". IP::N2P($ip)); - } - /** - * Returns true if IP anonymization is enabled. This function is called by the - * Tracker. - */ - private function isActiveInTracker() - { - $cache = Cache::getCacheGeneral(); - return !empty($cache[self::OPTION_NAME]); - } + $privacyConfig = new Config(); - /** - * Caches the status of IP anonymization (whether it is enabled or not). - */ - public function setTrackerCacheGeneral(&$cacheContent) - { - $cacheContent[self::OPTION_NAME] = Option::get(self::OPTION_NAME); + $ip = self::applyIPMask($ip, $privacyConfig->ipAddressMaskLength); + Common::printDebug("Visitor IP (was: ". IP::N2P($originalIp) .") has been anonymized: ". IP::N2P($ip)); } /** @@ -92,8 +70,8 @@ class IPAnonymizer */ public static function deactivate() { - Option::set(self::OPTION_NAME, 0); - Cache::clearCacheGeneral(); + $privacyConfig = new Config(); + $privacyConfig->ipAnonymizerEnabled = false; } /** @@ -101,8 +79,8 @@ class IPAnonymizer */ public static function activate() { - Option::set(self::OPTION_NAME, 1); - Cache::clearCacheGeneral(); + $privacyConfig = new Config(); + $privacyConfig->ipAnonymizerEnabled = true; } /** @@ -112,7 +90,7 @@ class IPAnonymizer */ public static function isActive() { - $active = Option::get(self::OPTION_NAME); - return !empty($active); + $privacyConfig = new Config(); + return $privacyConfig->ipAnonymizerEnabled; } } diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php index 4dc3013df5..d6908a61cd 100644 --- a/plugins/PrivacyManager/PrivacyManager.php +++ b/plugins/PrivacyManager/PrivacyManager.php @@ -10,12 +10,11 @@ namespace Piwik\Plugins\PrivacyManager; use Exception; use Piwik\Common; -use Piwik\Config; +use Piwik\Config as PiwikConfig; use Piwik\DataTable\DataTableInterface; use Piwik\Date; use Piwik\Db; use Piwik\Menu\MenuAdmin; - use Piwik\Metrics; use Piwik\Option; use Piwik\Period\Range; @@ -23,7 +22,6 @@ use Piwik\Period; use Piwik\Piwik; use Piwik\Plugins\Goals\Archiver; use Piwik\ScheduledTask; -use Piwik\ScheduledTime\Daily; use Piwik\ScheduledTime; use Piwik\Site; use Piwik\Tracker\GoalManager; @@ -45,23 +43,23 @@ class PrivacyManager extends \Piwik\Plugin const OPTION_LAST_DELETE_PIWIK_LOGS = "lastDelete_piwik_logs"; const OPTION_LAST_DELETE_PIWIK_REPORTS = 'lastDelete_piwik_reports'; const OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL = "lastDelete_piwik_logs_initial"; - const DEFAULT_MAX_ROWS_PER_QUERY = 100000; - - // default config options for data purging feature - public static $defaultPurgeDataOptions = array( - 'delete_logs_enable' => 0, - 'delete_logs_schedule_lowest_interval' => 7, - 'delete_logs_older_than' => 180, - 'delete_logs_max_rows_per_query' => self::DEFAULT_MAX_ROWS_PER_QUERY, - 'delete_reports_enable' => 0, - 'delete_reports_older_than' => 12, - 'delete_reports_keep_basic_metrics' => 1, - 'delete_reports_keep_day_reports' => 0, - 'delete_reports_keep_week_reports' => 0, - 'delete_reports_keep_month_reports' => 1, - 'delete_reports_keep_year_reports' => 1, - 'delete_reports_keep_range_reports' => 0, - 'delete_reports_keep_segment_reports' => 0, + + // options for data purging feature array[configName => configSection] + public static $purgeDataOptions = array( + 'delete_logs_enable' => 'Deletelogs', + 'delete_logs_schedule_lowest_interval' => 'Deletelogs', + 'delete_logs_older_than' => 'Deletelogs', + 'delete_logs_max_rows_per_query' => 'Deletelogs', + 'enable_auto_database_size_estimate' => 'Deletelogs', + 'delete_reports_enable' => 'Deletereports', + 'delete_reports_older_than' => 'Deletereports', + 'delete_reports_keep_basic_metrics' => 'Deletereports', + 'delete_reports_keep_day_reports' => 'Deletereports', + 'delete_reports_keep_week_reports' => 'Deletereports', + 'delete_reports_keep_month_reports' => 'Deletereports', + 'delete_reports_keep_year_reports' => 'Deletereports', + 'delete_reports_keep_range_reports' => 'Deletereports', + 'delete_reports_keep_segment_reports' => 'Deletereports', ); private $dntChecker = null; @@ -152,8 +150,8 @@ class PrivacyManager extends \Piwik\Plugin public function setTrackerCacheGeneral(&$cacheContent) { - $this->ipAnonymizer->setTrackerCacheGeneral($cacheContent); - $this->dntChecker->setTrackerCacheGeneral($cacheContent); + $config = new Config(); + $cacheContent = $config->setTrackerCacheGeneral($cacheContent); } public function getScheduledTasks(&$tasks) @@ -195,37 +193,20 @@ class PrivacyManager extends \Piwik\Plugin $settings = array(); // load settings from ini config - try { - $oldSettings = array( - 'enable_auto_database_size_estimate', - - // backwards compatibility: load old values in ini config if present - 'delete_logs_enable', - 'delete_logs_schedule_lowest_interval', - 'delete_logs_older_than', - ); - - $deleteLogsSettings = Config::getInstance()->Deletelogs; - foreach ($oldSettings as $settingName) { - $settings[$settingName] = $deleteLogsSettings[$settingName]; - } - } catch (Exception $e) { - // ignore + $config = PiwikConfig::getInstance(); + foreach (self::$purgeDataOptions as $configKey => $configSection) { + $settings[$configKey] = $config->$configSection[$configKey]; + } + + if (!Controller::isDataPurgeSettingsEnabled()) { + return $settings; } // load the settings for the data purging settings - foreach (self::$defaultPurgeDataOptions as $optionName => $defaultValue) { - $value = Option::get($optionName); + foreach (self::$purgeDataOptions as $configName => $configSection) { + $value = Option::get($configName); if ($value !== false) { - $settings[$optionName] = $value; - } else { - // if the option hasn't been set/created, use the default value - if (!isset($settings[$optionName])) { - $settings[$optionName] = $defaultValue; - } - - // option is not saved in the DB, so save it now - Option::set($optionName, $settings[$optionName]); + $settings[$configName] = $value; } } @@ -239,9 +220,9 @@ class PrivacyManager extends \Piwik\Plugin */ public static function savePurgeDataSettings($settings) { - foreach (self::$defaultPurgeDataOptions as $optionName => $defaultValue) { - if (isset($settings[$optionName])) { - Option::set($optionName, $settings[$optionName]); + foreach (self::$purgeDataOptions as $configName => $configSection) { + if (isset($settings[$configName])) { + Option::set($configName, $settings[$configName]); } } } diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index fc737e5158..4e9b2c62cf 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -19,6 +19,7 @@ use Piwik\IP; use Piwik\Menu\MenuMain; use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; +use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; use Piwik\WidgetsList; /** @@ -115,7 +116,8 @@ class Provider extends \Piwik\Plugin return; } - $ip = IP::N2P(Config::getInstance()->Tracker['use_anonymized_ip_for_visit_enrichment'] == 1 ? $visitorInfo['location_ip'] : $request->getIp()); + $privacyConfig = new PrivacyManagerConfig(); + $ip = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp()); // 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') { diff --git a/plugins/SecurityInfo b/plugins/SecurityInfo -Subproject 2d1f5e5a70ddcf5e7a88514c07b9e0ef501051e +Subproject cd98a60c785ce56b45e4d142e9af3a470619a60 diff --git a/plugins/TasksTimetable b/plugins/TasksTimetable -Subproject 2646ac6b7856fc46e20a0213a5467cd6cd7c731 +Subproject f6e252d5dc5e3cf004263f7450c2ca55bd2c5a7 diff --git a/plugins/TreemapVisualization b/plugins/TreemapVisualization -Subproject 19978cb7cd926ec0fba111ce257b8f0450f34ce +Subproject 2cb15300a88f7ff2a1fc27ef633a1a1f4d5fef0 diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index dcfadff81b..d74bde1e34 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -17,9 +17,9 @@ use Piwik\Menu\MenuMain; use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider; - use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; +use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; use Piwik\Url; use Piwik\WidgetsList; @@ -83,7 +83,9 @@ class UserCountry extends \Piwik\Plugin { require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; - $ipAddress = IP::N2P(Config::getInstance()->Tracker['use_anonymized_ip_for_visit_enrichment'] == 1 ? $visitorInfo['location_ip'] : $request->getIp()); + $privacyConfig = new PrivacyManagerConfig(); + + $ipAddress = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp()); $userInfo = array( 'lang' => $visitorInfo['location_browser_lang'], 'ip' => $ipAddress diff --git a/plugins/VisitorGenerator b/plugins/VisitorGenerator -Subproject 6cd5e94ca5cca57ed5132b9f929d7a952e41041 +Subproject 0e0066e5358aea60026b8f53bd7a33e854dbb67 |