From 4c1935a6b6ec8d8cb95c6b5af3399927d30fbe66 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 27 Jul 2011 13:40:27 +1000 Subject: per-board bans --- inc/functions.php | 19 +++++++++++++------ inc/mod.php | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/functions.php b/inc/functions.php index 91b68bfc..c8d52160 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -400,7 +400,12 @@ $body = '

You are banned! ;_;

-

You have been banned ' . +

You have been banned from ' . + (!isset($ban['uri']) ? + 'all boards': + '' . sprintf($config['board_abbreviation'], $ban['uri']) . '' + ) . + ' ' . ($ban['reason'] ? 'for the following reason:' : 'for an unspecified reason.') . '

' . ($ban['reason'] ? @@ -464,7 +469,7 @@ )); } - function checkBan() { + function checkBan($board = 0) { global $config, $memcached; if(!isset($_SERVER['REMOTE_ADDR'])) { @@ -474,17 +479,19 @@ if($config['memcached']['enabled']) { // Cached ban? - if($ban = $memcached->get("ban_${_SERVER['REMOTE_ADDR']}")) { + if($ban = $memcached->get("ban_${board}_${_SERVER['REMOTE_ADDR']}")) { displayBan($ban); } } - $query = prepare("SELECT * FROM `bans` WHERE `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1"); + $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1"); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':board', $board); $query->execute() or error(db_error($query)); if($query->rowCount() < 1 && $config['ban_range']) { - $query = prepare("SELECT * FROM `bans` WHERE :ip REGEXP CONCAT('^', REPLACE(REPLACE(`ip`, '.', '\\.'), '*', '[0-9]*'), '$') ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1"); + $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) AND :ip REGEXP CONCAT('^', REPLACE(REPLACE(`ip`, '.', '\\.'), '*', '[0-9]*'), '$') ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1"); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':board', $board); $query->execute() or error(db_error($query)); } @@ -506,7 +513,7 @@ } if($config['memcached']['enabled']) - $memcached->set("ban_${_SERVER['REMOTE_ADDR']}", $ban, $ban['expires']); + $memcached->set("ban_${board}_${_SERVER['REMOTE_ADDR']}", $ban, $ban['expires']); displayBan($ban); } } diff --git a/inc/mod.php b/inc/mod.php index 0887cd07..8691317b 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -174,6 +174,23 @@ function form_newBan($ip=null, $reason='', $continue=false, $delete=false, $board=false, $allow_public = false) { global $config, $mod; + + $boards = listBoards(); + $__boards = '
  • '; + foreach($boards as &$_board) { + $__boards .= '
  • ' . + '' . + '' . + '
  • '; + } + return '
    New ban' . '
    ' . ($continue ? '' : '') . @@ -214,6 +231,12 @@ '' . ' (eg. "2d1h30m" or "2 days")' . '' . + + '' . + 'Board' . + '
      ' . $__boards . '' . + '' . + '' . '' . '' . -- cgit v1.3