diff options
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/inc/functions.php b/inc/functions.php index 74e94ea6..7934a53a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -537,8 +537,7 @@ if(!isset($_SERVER['REMOTE_ADDR'])) { // Server misconfiguration return; - } - + } $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` 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']); @@ -550,6 +549,21 @@ $query->bindValue(':board', $board); $query->execute() or error(db_error($query)); } + if($query->rowCount() < 1 && $config['ban_cidr']) { + // my most insane SQL query yet + $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) + AND ( + `ip` REGEXP '^(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+\)\/(\[0-9]+)$' + AND + :ip >= INET_ATON(SUBSTRING_INDEX(`ip`, '/', 1)) + AND + :ip < INET_ATON(SUBSTRING_INDEX(`ip`, '/', 1)) + POW(2, 32 - SUBSTRING_INDEX(`ip`, '/', -1)) + ) + ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1"); + $query->bindValue(':ip', ip2long($_SERVER['REMOTE_ADDR'])); + $query->bindValue(':board', $board); + $query->execute() or error(db_error($query)); + } if($ban = $query->fetch()) { if($ban['expires'] && $ban['expires'] < time()) { |
