IP range ban
git-svn-id: file:///home/shish/svn/shimmie2/trunk@746 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
e469ebcb38
commit
89df1557f0
@ -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 *
|
||||
|
@ -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 <b>{$row['ip']}</b> has been banned by <b>{$admin->name}</b> because of <b>{$row['reason']}</b>";
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<table name="bans">
|
||||
<field name="id" type="I"><key/><autoincrement/></field>
|
||||
<field name="banner_id" type="I"><notnull/></field>
|
||||
<field name="ip" type="C" size="15"><notnull/></field>
|
||||
<field name="ip" type="C" size="20"><notnull/></field>
|
||||
<field name="date" type="D"><notnull/></field>
|
||||
<field name="end" type="D"><notnull/></field>
|
||||
<field name="reason" type="C" size="255"><notnull/></field>
|
||||
@ -14,6 +14,6 @@
|
||||
|
||||
<sql>
|
||||
<query>DELETE FROM config WHERE name='ext_ipban_version'</query>
|
||||
<query>INSERT INTO config(name, value) VALUES('ext_ipban_version', 4)</query>
|
||||
<query>INSERT INTO config(name, value) VALUES('ext_ipban_version', 5)</query>
|
||||
</sql>
|
||||
</schema>
|
||||
|
Loading…
x
Reference in New Issue
Block a user