From 3429d293d3ba0426924b5da488147e4f3b223c9f Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 8 Jun 2021 06:37:27 +0200 Subject: [PATCH] remove configurable dir for traffic & purge limiters --- CHANGELOG.md | 1 + cfg/conf.sample.php | 6 ------ lib/Configuration.php | 2 -- lib/Controller.php | 1 - lib/Persistence/PurgeLimiter.php | 3 +-- lib/Persistence/TrafficLimiter.php | 1 - tst/ConfigurationTest.php | 2 -- tst/ConfigurationTestGenerator.php | 4 ---- tst/ControllerTest.php | 3 --- tst/JsonApiTest.php | 2 -- tst/Persistence/PurgeLimiterTest.php | 1 - 11 files changed, 2 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c4321ad..c546bd11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * CHANGED: Language selection cookie only transmitted over HTTPS (#472) * CHANGED: Upgrading libraries to: random_compat 2.0.20 * CHANGED: Removed automatic `.ini` configuration file migration (#808) + * CHANGED: Removed configurable `dir` for `traffic` & `purge` limiters (#419) * **1.3.5 (2021-04-05)** * ADDED: Translation for Hebrew, Lithuanian, Indonesian and Catalan * ADDED: Make the project info configurable (#681) diff --git a/cfg/conf.sample.php b/cfg/conf.sample.php index a4b7f6b5..d362f3f2 100644 --- a/cfg/conf.sample.php +++ b/cfg/conf.sample.php @@ -143,9 +143,6 @@ limit = 10 ; set the HTTP header containing the visitors IP address, i.e. X_FORWARDED_FOR ; header = "X_FORWARDED_FOR" -; directory to store the traffic limits in -dir = PATH "data" - [purge] ; minimum time limit between two purgings of expired pastes, it is only ; triggered when pastes are created @@ -157,9 +154,6 @@ limit = 300 ; site batchsize = 10 -; directory to store the purge limit in -dir = PATH "data" - [model] ; name of data model class to load and directory for storage ; the default model "Filesystem" stores everything in the filesystem diff --git a/lib/Configuration.php b/lib/Configuration.php index 1185440c..7c4eb106 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -80,13 +80,11 @@ class Configuration 'traffic' => array( 'limit' => 10, 'header' => null, - 'dir' => 'data', 'exemptedIp' => null, ), 'purge' => array( 'limit' => 300, 'batchsize' => 10, - 'dir' => 'data', ), 'model' => array( 'class' => 'Filesystem', diff --git a/lib/Controller.php b/lib/Controller.php index 2df522a2..72bd5b2e 100644 --- a/lib/Controller.php +++ b/lib/Controller.php @@ -162,7 +162,6 @@ class Controller $this->_model = new Model($this->_conf); $this->_request = new Request; $this->_urlBase = $this->_request->getRequestUri(); - ServerSalt::setPath($this->_conf->getKey('dir', 'traffic')); // set default language $lang = $this->_conf->getKey('languagedefault'); diff --git a/lib/Persistence/PurgeLimiter.php b/lib/Persistence/PurgeLimiter.php index 19b83e2d..6b608170 100644 --- a/lib/Persistence/PurgeLimiter.php +++ b/lib/Persistence/PurgeLimiter.php @@ -52,7 +52,6 @@ class PurgeLimiter extends AbstractPersistence public static function setConfiguration(Configuration $conf) { self::setLimit($conf->getKey('limit', 'purge')); - self::setPath($conf->getKey('dir', 'purge')); } /** @@ -71,7 +70,7 @@ class PurgeLimiter extends AbstractPersistence } $now = time(); - $pl = (int) self::$_store->getValue('purge_limiter'); + $pl = (int) self::$_store->getValue('purge_limiter'); if ($pl + self::$_limit >= $now) { return false; } diff --git a/lib/Persistence/TrafficLimiter.php b/lib/Persistence/TrafficLimiter.php index be76b8cd..299c7a6d 100644 --- a/lib/Persistence/TrafficLimiter.php +++ b/lib/Persistence/TrafficLimiter.php @@ -85,7 +85,6 @@ class TrafficLimiter extends AbstractPersistence public static function setConfiguration(Configuration $conf) { self::setLimit($conf->getKey('limit', 'traffic')); - self::setPath($conf->getKey('dir', 'traffic')); self::setExemptedIp($conf->getKey('exemptedIp', 'traffic')); if (($option = $conf->getKey('header', 'traffic')) !== null) { diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index 246618cc..312b7997 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -17,8 +17,6 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]'; $this->_options = Configuration::getDefaults(); $this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir']; - $this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir']; - $this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir']; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_cfg'; if (!is_dir($this->_path)) { mkdir($this->_path); diff --git a/tst/ConfigurationTestGenerator.php b/tst/ConfigurationTestGenerator.php index 284fa5f2..945fc479 100755 --- a/tst/ConfigurationTestGenerator.php +++ b/tst/ConfigurationTestGenerator.php @@ -428,8 +428,6 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase Helper::confBackup(); $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_model = Filesystem::getInstance(array('dir' => $this->_path)); - ServerSalt::setPath($this->_path); - TrafficLimiter::setPath($this->_path); $this->reset(); } @@ -449,8 +447,6 @@ class ConfigurationCombinationsTest extends PHPUnit_Framework_TestCase if ($this->_model->exists(Helper::getPasteId())) $this->_model->delete(Helper::getPasteId()); $configuration['model_options']['dir'] = $this->_path; - $configuration['traffic']['dir'] = $this->_path; - $configuration['purge']['dir'] = $this->_path; Helper::createIniFile(CONF, $configuration); } diff --git a/tst/ControllerTest.php b/tst/ControllerTest.php index b00f2ce6..6e7ec4c0 100644 --- a/tst/ControllerTest.php +++ b/tst/ControllerTest.php @@ -37,11 +37,8 @@ class ControllerTest extends PHPUnit_Framework_TestCase $this->_data->delete(Helper::getPasteId()); } $options = parse_ini_file(CONF_SAMPLE, true); - $options['purge']['dir'] = $this->_path; - $options['traffic']['dir'] = $this->_path; $options['model_options']['dir'] = $this->_path; Helper::createIniFile(CONF, $options); - ServerSalt::setPath($this->_path); } /** diff --git a/tst/JsonApiTest.php b/tst/JsonApiTest.php index 9655e609..17b699f1 100644 --- a/tst/JsonApiTest.php +++ b/tst/JsonApiTest.php @@ -25,8 +25,6 @@ class JsonApiTest extends PHPUnit_Framework_TestCase $this->_model->delete(Helper::getPasteId()); } $options = parse_ini_file(CONF_SAMPLE, true); - $options['purge']['dir'] = $this->_path; - $options['traffic']['dir'] = $this->_path; $options['model_options']['dir'] = $this->_path; Helper::confBackup(); Helper::createIniFile(CONF, $options); diff --git a/tst/Persistence/PurgeLimiterTest.php b/tst/Persistence/PurgeLimiterTest.php index e8cedc0a..adb96ffd 100644 --- a/tst/Persistence/PurgeLimiterTest.php +++ b/tst/Persistence/PurgeLimiterTest.php @@ -14,7 +14,6 @@ class PurgeLimiterTest extends PHPUnit_Framework_TestCase if (!is_dir($this->_path)) { mkdir($this->_path); } - PurgeLimiter::setPath($this->_path); PurgeLimiter::setStore( Filesystem::getInstance(array('dir' => $this->_path)) );