From d4cf4c7afb975cead41768c9e0d1960a46183409 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sun, 8 Sep 2013 15:07:55 +1000 Subject: [PATCH] flood-count condition --- inc/config.php | 19 ++++++++++++++++--- inc/filters.php | 8 ++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/inc/config.php b/inc/config.php index 0cdbe709..0eac92b6 100644 --- a/inc/config.php +++ b/inc/config.php @@ -342,7 +342,20 @@ // 'message' => &$config['error']['flood'] // ); - // An example of blocking an imaginary known spammer, who keeps posting a reply with the name "surgeon", + // Example: Use the "flood-count" condition to only match if the user has made at least two posts with + // the same content and IP address in the past 2 minutes. + // $config['filters'][] = array( + // 'condition' => array( + // 'flood-match' => array('ip', 'body'), // Match IP address and post body + // 'flood-time' => 60 * 2, // 2 minutes + // 'flood-count' => 2 // At least two recent posts + // ), + // '!body' => '/^$/', + // 'action' => 'reject', + // 'message' => &$config['error']['flood'] + // ); + + // Example: Blocking an imaginary known spammer, who keeps posting a reply with the name "surgeon", // ending his posts with "regards, the surgeon" or similar. // $config['filters'][] = array( // 'condition' => array( @@ -354,7 +367,7 @@ // 'message' => 'Go away, spammer.' // ); - // Same as above, but issuing a 3-hour ban instead of just reject the post. + // Example: Same as above, but issuing a 3-hour ban instead of just reject the post. // $config['filters'][] = array( // 'condition' => array( // 'name' => '/^surgeon$/', @@ -366,7 +379,7 @@ // 'reason' => 'Go away, spammer.' // ); - // PHP 5.3+ (anonymous functions) + // Example: PHP 5.3+ (anonymous functions) // There is also a "custom" condition, making the possibilities of this feature pretty much endless. // This is a bad example, because there is already a "name" condition built-in. // $config['filters'][] = array( diff --git a/inc/filters.php b/inc/filters.php index d2802264..d5353afb 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -73,6 +73,14 @@ class Filter { } } return false; + case 'flood-count': + $count = 0; + foreach ($this->flood_check as $flood_post) { + if (time() - $flood_post['time'] <= $this->condition['flood-time']) { + ++$count; + } + } + return $count >= $match; case 'name': return preg_match($match, $post['name']); case 'trip':