summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@n0v4.com>2011-03-31 00:12:36 +1100
committerSavetheinternet <savetheinternet@n0v4.com>2011-03-31 00:12:36 +1100
commitb4aa39ca2def14eb1f6521eeb9e6f0a76b3720f5 (patch)
treee5c5170a68878393391ad4461c48c2f2ac4d7b93 /inc
parent6f62e038d48a341cac989d363603cb2d3780acd1 (diff)
IP range bans
Diffstat (limited to 'inc')
-rw-r--r--inc/config.php4
-rw-r--r--inc/functions.php7
2 files changed, 10 insertions, 1 deletions
diff --git a/inc/config.php b/inc/config.php
index c1f8dbc5..13370614 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -462,6 +462,10 @@
// Characters used to generate a random password (with Javascript)
$config['genpassword_chars'] = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+';
+ // Enable IP range bans (eg. "127.*.0.1", "127.0.0.*", and "12*.0.0.1" all match "127.0.0.1").
+ // A little more load on the database
+ $config['ban_range'] = true;
+
// Custom stylesheets available. The prefix for each stylesheet URI is defined below.
$config['stylesheets'] = Array(
// Stylesheet name => URI
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()) {