remove bans by ID. Also, show who banned whom
git-svn-id: file:///home/shish/svn/shimmie2/trunk@548 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
2c43a4f420
commit
8d991a14e8
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
// RemoveIPBanEvent {{{
|
// RemoveIPBanEvent {{{
|
||||||
class RemoveIPBanEvent extends Event {
|
class RemoveIPBanEvent extends Event {
|
||||||
var $ip;
|
var $id;
|
||||||
|
|
||||||
public function RemoveIPBanEvent($ip) {
|
public function RemoveIPBanEvent($id) {
|
||||||
$this->ip = $ip;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@ -31,7 +31,7 @@ class IPBan extends Extension {
|
|||||||
|
|
||||||
if(is_a($event, 'InitExtEvent')) {
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
global $config;
|
global $config;
|
||||||
if($config->get_int("ext_ipban_version") < 1) {
|
if($config->get_int("ext_ipban_version") < 2) {
|
||||||
$this->install();
|
$this->install();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ class IPBan extends Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if($event->get_arg(0) == "remove") {
|
else if($event->get_arg(0) == "remove") {
|
||||||
if(isset($_POST['ip'])) {
|
if(isset($_POST['id'])) {
|
||||||
send_event(new RemoveIPBanEvent($_POST['ip']));
|
send_event(new RemoveIPBanEvent($_POST['id']));
|
||||||
|
|
||||||
global $page;
|
global $page;
|
||||||
$page->set_mode("redirect");
|
$page->set_mode("redirect");
|
||||||
@ -65,11 +65,12 @@ class IPBan extends Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'AddIPBanEvent')) {
|
if(is_a($event, 'AddIPBanEvent')) {
|
||||||
$this->add_ip_ban($event->ip, $event->reason, $event->end);
|
global $user;
|
||||||
|
$this->add_ip_ban($event->ip, $event->reason, $event->end, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'RemoveIPBanEvent')) {
|
if(is_a($event, 'RemoveIPBanEvent')) {
|
||||||
$this->remove_ip_ban($event->ip);
|
$this->remove_ip_ban($event->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'AdminBuildingEvent')) {
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
@ -82,15 +83,23 @@ class IPBan extends Extension {
|
|||||||
protected function install() {
|
protected function install() {
|
||||||
global $database;
|
global $database;
|
||||||
global $config;
|
global $config;
|
||||||
$database->Execute("CREATE TABLE bans (
|
|
||||||
id int(11) NOT NULL auto_increment,
|
if($config->get_int("ext_ipban_version") < 1) {
|
||||||
ip char(15) default NULL,
|
$database->Execute("CREATE TABLE bans (
|
||||||
date datetime default NULL,
|
id int(11) NOT NULL auto_increment,
|
||||||
end datetime default NULL,
|
ip char(15) default NULL,
|
||||||
reason varchar(255) default NULL,
|
date datetime default NULL,
|
||||||
PRIMARY KEY (id)
|
end datetime default NULL,
|
||||||
)");
|
reason varchar(255) default NULL,
|
||||||
$config->set_int("ext_ipban_version", 1);
|
PRIMARY KEY (id)
|
||||||
|
)");
|
||||||
|
$config->set_int("ext_ipban_version", 1);
|
||||||
|
}
|
||||||
|
if($config->get_int("ext_ipban_version") < 2) {
|
||||||
|
$database->execute("ALTER TABLE bans CHANGE ip ip CHAR(15) NOT NULL");
|
||||||
|
$database->execute("ALTER TABLE bans ADD COLUMN banner_id INTEGER NOT NULL");
|
||||||
|
$config->set_int("ext_ipban_version", 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// deal with banned person {{{
|
// deal with banned person {{{
|
||||||
@ -98,8 +107,9 @@ class IPBan extends Extension {
|
|||||||
$row = $this->get_ip_ban($_SERVER['REMOTE_ADDR']);
|
$row = $this->get_ip_ban($_SERVER['REMOTE_ADDR']);
|
||||||
if($row) {
|
if($row) {
|
||||||
global $config;
|
global $config;
|
||||||
|
global $database;
|
||||||
print "IP <b>{$row['ip']}</b> has been banned because of <b>{$row['reason']}</b>";
|
$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>";
|
||||||
|
|
||||||
$contact_link = $config->get_string("contact_link");
|
$contact_link = $config->get_string("contact_link");
|
||||||
if(!empty($contact_link)) {
|
if(!empty($contact_link)) {
|
||||||
@ -110,32 +120,28 @@ class IPBan extends Extension {
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// database {{{
|
// database {{{
|
||||||
public function get_bans() {
|
private function get_bans() {
|
||||||
// FIXME: many
|
|
||||||
global $database;
|
global $database;
|
||||||
$bans = $database->db->GetAll("SELECT * FROM bans");
|
$bans = $database->db->GetAll("SELECT * FROM bans");
|
||||||
if($bans) {return $bans;}
|
if($bans) {return $bans;}
|
||||||
else {return array();}
|
else {return array();}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_ip_ban($ip) {
|
private function get_ip_ban($ip) {
|
||||||
global $database;
|
global $database;
|
||||||
// yes, this is "? LIKE var", because ? is the thing with matching tokens
|
|
||||||
// actually, slow
|
|
||||||
// return $database->db->GetRow("SELECT * FROM bans WHERE ? LIKE ip AND date < now() AND (end > now() OR isnull(end))", array($ip));
|
|
||||||
return $database->db->GetRow("SELECT * FROM bans WHERE ip = ? AND date < now() AND (end > now() OR isnull(end))", array($ip));
|
return $database->db->GetRow("SELECT * FROM bans WHERE ip = ? AND date < now() AND (end > now() OR isnull(end))", array($ip));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_ip_ban($ip, $reason, $end) {
|
private function add_ip_ban($ip, $reason, $end, $user) {
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute(
|
$database->Execute(
|
||||||
"INSERT INTO bans (ip, reason, date, end) VALUES (?, ?, now(), ?)",
|
"INSERT INTO bans (ip, reason, date, end, banner_id) VALUES (?, ?, now(), ?, ?)",
|
||||||
array($ip, $reason, $end));
|
array($ip, $reason, $end, $user->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove_ip_ban($ip) {
|
private function remove_ip_ban($id) {
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute("DELETE FROM bans WHERE ip = ?", array($ip));
|
$database->Execute("DELETE FROM bans WHERE id = ?", array($id));
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class IPBanTheme extends Themelet {
|
|||||||
<td>{$ban['end']}</td>
|
<td>{$ban['end']}</td>
|
||||||
<td>
|
<td>
|
||||||
<form action='".make_link("ip_ban/remove")."' method='POST'>
|
<form action='".make_link("ip_ban/remove")."' method='POST'>
|
||||||
<input type='hidden' name='ip' value='{$ban['ip']}'>
|
<input type='hidden' name='id' value='{$ban['id']}'>
|
||||||
<input type='submit' value='Remove'>
|
<input type='submit' value='Remove'>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user