Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1611 from mariansollmann/issue-1611
Browse files Browse the repository at this point in the history
IP block delete older should be configurable
  • Loading branch information
Marian Sollmann committed Jan 28, 2015
2 parents b329097 + b337bd3 commit 2ce9494
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion library/CM/Maintenance/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function _registerCallbacks() {
CM_SVM_Model::deleteOldTrainings(3000);
},
'CM_Paging_Ip_Blocked::deleteOlder' => function () {
CM_Paging_Ip_Blocked::deleteOlder(7 * 86400);
CM_Paging_Ip_Blocked::deleteOld();
},
'CM_Captcha::deleteOlder' => function () {
CM_Captcha::deleteOlder(3600);
Expand Down
11 changes: 7 additions & 4 deletions library/CM/Paging/Ip/Blocked.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ public function remove($ip) {
CM_Db_Db::delete('cm_ipBlocked', array('ip' => $ip));
}

public static function deleteOld() {
CM_Db_Db::delete('cm_ipBlocked', '`createStamp` < ' . (time() - self::_getMaxAge()));
}

/**
* @param int $age
* @return int
*/
public static function deleteOlder($age) {
$age = (int) $age;
CM_Db_Db::delete('cm_ipBlocked', '`createStamp` < ' . (time() - $age));
protected static function _getMaxAge() {
return (int) self::_getConfig()->maxAge;
}
}
12 changes: 7 additions & 5 deletions resources/config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
array('host' => 'localhost', 'port' => 11211),
);

$config->CM_Paging_Ip_Blocked->maxAge = (7 * 86400);

$config->classConfigCacheEnabled = true;

$config->CM_Stream_Message->enabled = true;
Expand Down Expand Up @@ -105,11 +107,11 @@
'class' => 'CM_Db_Client',
'arguments' => array(
array(
'host' => 'localhost',
'port' => 3306,
'username' => 'root',
'password' => '',
'db' => 'cm',
'host' => 'localhost',
'port' => 3306,
'username' => 'root',
'password' => '',
'db' => 'cm',
)
)
);
Expand Down
6 changes: 4 additions & 2 deletions tests/library/CM/Paging/Ip/BlockedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
class CM_Paging_Ip_BlockedTest extends CMTest_TestCase {

public function testAdd() {
CM_Config::get()->CM_Paging_Ip_Blocked->maxAge = (3 * 86400);
$ip = '127.0.0.1';
$ip2 = '127.0.0.2';

$paging = new CM_Paging_Ip_Blocked();
$paging->add(ip2long($ip));
$this->assertEquals(1, $paging->getCount());
Expand All @@ -16,12 +18,12 @@ public function testAdd() {
$paging->_change();
$this->assertEquals(2, $paging->getCount());
CMTest_TH::timeDaysForward(2);
CM_Paging_Ip_Blocked::deleteOlder(3 * 86400);
CM_Paging_Ip_Blocked::deleteOld();
CM_Cache_Local::getInstance()->flush();
$paging->_change();
$this->assertEquals(1, $paging->getCount());
CMTest_TH::timeDaysForward(2);
CM_Paging_Ip_Blocked::deleteOlder(3 * 86400);
CM_Paging_Ip_Blocked::deleteOld();
CM_Cache_Local::getInstance()->flush();
$this->assertEquals(1, $paging->getCount());
$paging->_change();
Expand Down

0 comments on commit 2ce9494

Please sign in to comment.