diff --git a/core/util.inc.php b/core/util.inc.php index c83bb3db..66abc1b7 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -350,6 +350,19 @@ if(!function_exists('sys_get_temp_dir')) { } } +// from http://uk.php.net/network +function ip_in_range($IP, $CIDR) { + list ($net, $mask) = split ("/", $CIDR); + + $ip_net = ip2long ($net); + $ip_mask = ~((1 << (32 - $mask)) - 1); + + $ip_ip = ip2long ($IP); + + $ip_ip_net = $ip_ip & $ip_mask; + + return ($ip_ip_net == $ip_net); +} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Event API * diff --git a/ext/ipban/main.php b/ext/ipban/main.php index d2e478a8..2c03be6a 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -31,7 +31,7 @@ class IPBan extends Extension { if(is_a($event, 'InitExtEvent')) { global $config; - if($config->get_int("ext_ipban_version") < 4) { + if($config->get_int("ext_ipban_version") < 5) { $this->install(); } @@ -94,9 +94,13 @@ class IPBan extends Extension { global $config; global $database; + $remote = $_SERVER['REMOTE_ADDR']; $bans = $this->get_active_bans(); foreach($bans as $row) { - if($row['ip'] == $_SERVER['REMOTE_ADDR']) { + if( + (strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) || + ($row['ip'] == $remote) + ) { $admin = $database->get_user_by_id($row['banner_id']); print "IP {$row['ip']} has been banned by {$admin->name} because of {$row['reason']}"; diff --git a/ext/ipban/schema.xml b/ext/ipban/schema.xml index 9439b692..168b1cb4 100644 --- a/ext/ipban/schema.xml +++ b/ext/ipban/schema.xml @@ -4,7 +4,7 @@ - + @@ -14,6 +14,6 @@ DELETE FROM config WHERE name='ext_ipban_version' - INSERT INTO config(name, value) VALUES('ext_ipban_version', 4) + INSERT INTO config(name, value) VALUES('ext_ipban_version', 5)