From b4aa39ca2def14eb1f6521eeb9e6f0a76b3720f5 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 31 Mar 2011 00:12:36 +1100 Subject: IP range bans --- inc/functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 4ee5b4ae..e2a2454b 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -195,9 +195,14 @@ return; } - $query = prepare("SELECT * FROM `bans` WHERE `ip` = :ip LIMIT 1"); + $query = prepare("SELECT * FROM `bans` WHERE `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1"); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $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->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->execute() or error(db_error($query)); + } if($ban = $query->fetch()) { if($ban['expires'] && $ban['expires'] < time()) { -- cgit v1.3