Browse Source

Improve default filters

pull/40/head
discomrade 3 years ago
parent
commit
c9bb2c5f42
  1. 96
      inc/config.php
  2. 43
      inc/filters.php

96
inc/config.php

@ -343,53 +343,67 @@
* Read more: http://tinyboard.org/docs/index.php?p=Config/Filters
*/
// Minimum time between between each opening post.
$config['flood_time_any'] = 40;
// Minimum time between between each post by the same IP address.
$config['flood_time'] = 10;
// Minimum time between between each post with the exact same content AND same IP address.
$config['flood_time_ip'] = 120;
// Same as above but by a different IP address. (Same content, not necessarily same IP address.)
$config['flood_time_same'] = 30;
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('isreply'), // Only match IP address
'OP' => true,
'flood-time-any' => &$config['flood_time_any']
),
'noip' => true,
'find-time' => 60 * 60 * 1,
'action' => 'reject',
'message' => 'New threads are being created too quickly. Hmmm'
);
// Minimum time between between each post by the same IP address.
$config['flood_time_ip'] = 10;
// Minimum time between between each post with the exact same content
$config['flood_time_repost'] = 30;
// Minimum time between between each post with the exact same content AND same IP address.
$config['flood_time_ip_repost'] = 120;
// Minimum time between between any opening post on the same board.
$config['flood_time_board_op'] = 30;
// Minimum time between between opening posts by the same IP address.
$config['flood_time_ip_op'] = 180;
// Minimum time between posts by the same IP address (all boards).
$config['filters'][] = array(
'condition' => array(
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('ip'), // Only match IP address
'flood-time' => &$config['flood_time']
),
'action' => 'reject',
'flood-time' => &$config['flood_time_ip']
),
'action' => 'reject',
'message' => &$config['error']['flood']
);
// Minimum time between posts by the same IP address with the same text.
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('ip', 'body'), // Match IP address and post body
'flood-time' => &$config['flood_time_ip'],
'!body' => '/^$/', // Post body is NOT empty
),
'action' => 'reject',
'message' => &$config['error']['flood']
);
// Minimum time between posts with the same text. (Same content, but not always the same IP address.)
);
// Minimum time between between each post with the exact same content (all boards)
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('body'), // Only match post body
'flood-time' => &$config['flood_time_repost']
),
'action' => 'reject',
'message' => &$config['error']['flood']
);
// Minimum time between posts by the same IP address with the same text (all boards)
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('ip', 'body'), // Only match IP address and post body
'flood-time' => &$config['flood_time_ip_repost'],
'!body' => '/^$/', // Post body is NOT empty
),
'action' => 'reject',
'message' => &$config['error']['flood']
);
// Minimum time between between each opening post (same board)
$config['filters'][] = array(
'condition' => array(
'OP' => true,
'flood-match' => array('board'), // Only match OPs on the same board
'flood-match' => array('isop'),
'flood-time' => &$config['flood_time_board_op']
),
'action' => 'reject',
'message' => 'New threads are being created too quickly.'
);
// Minimum time between opening posts by the same IP address (all boards)
$config['filters'][] = array(
'condition' => array(
'flood-match' => array('body'), // Match only post body
'flood-time' => &$config['flood_time_same']
'OP' => true,
'flood-match' => array('ip'), // Only match IP address of OPs
'flood-match' => array('isop'),
'flood-time' => &$config['flood_time_ip_op']
),
'action' => 'reject',
'message' => &$config['error']['flood']

43
inc/filters.php

@ -58,8 +58,12 @@ class Filter {
if ($flood_post['board'] != $post['board'])
continue 3;
break;
case 'isop':
if ($flood_post['isreply'] != '0')
continue 3;
break;
case 'isreply':
if ($flood_post['isreply'] == $post['op'])
if ($flood_post['isreply'] != '1')
continue 3;
break;
default:
@ -73,14 +77,6 @@ class Filter {
$this->flood_check = $flood_check_matched;
return !empty($this->flood_check);
case 'flood-time-any':
foreach ($this->flood_check as $flood_post) {
if (time() - $flood_post['time'] <= $match) {
print_err("rejecting post with flood id: " . $flood_post['id']);
return true;
}
}
return false;
case 'flood-time':
foreach ($this->flood_check as $flood_post) {
if (time() - $flood_post['time'] <= $match) {
@ -228,37 +224,14 @@ function do_filters(array $post) {
if (!isset($config['filters']) || empty($config['filters']))
return;
// look at the flood table regardless of IP
$noip = false;
foreach ($config['filters'] as $filter) {
if (isset($filter['condition']['flood-match']) && (!isset($filter['noip']) || $filter['noip'] == false)) {
if (isset($filter['condition']['flood-match'])) {
$has_flood = true;
break;
} else if ($filter['noip'] == true) {
print_err("filters noip is true");
$noip = true;
$find_time = time() - $filter['find-time'];
}
}
if ($noip) {
print_err("SELECT * FROM flood WHERE time > " . strval($find_time));
$query = prepare("SELECT * FROM ``flood`` WHERE `time` > $find_time");
$query->execute() or error(db_error($query));
$flood_check = $query->fetchAll(PDO::FETCH_ASSOC);
} else if (isset($has_flood)) {
if ($post['has_file']) {
$query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash OR `filehash` = :filehash");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':posthash', make_comment_hex($post['body_nomarkup']));
$query->bindValue(':filehash', $post['filehash']);
} else {
$query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':posthash', make_comment_hex($post['body_nomarkup']));
}
if (isset($has_flood)) {
$query = prepare("SELECT * FROM ``flood``");
$query->execute() or error(db_error($query));
$flood_check = $query->fetchAll(PDO::FETCH_ASSOC);
} else {

Loading…
Cancel
Save