IP ban expiry times
git-svn-id: file:///home/shish/svn/shimmie2/trunk@140 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
3be41b687a
commit
93bb05abaf
1 changed files with 13 additions and 9 deletions
|
@ -13,10 +13,12 @@ class RemoveIPBanEvent extends Event {
|
|||
class AddIPBanEvent extends Event {
|
||||
var $ip;
|
||||
var $reason;
|
||||
var $end;
|
||||
|
||||
public function AddIPBanEvent($ip, $reason) {
|
||||
public function AddIPBanEvent($ip, $reason, $end) {
|
||||
$this->ip = $ip;
|
||||
$this->reason = $reason;
|
||||
$this->end = $end;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
@ -37,8 +39,8 @@ class IPBan extends Extension {
|
|||
global $user;
|
||||
if($user->is_admin()) {
|
||||
if($event->get_arg(0) == "add") {
|
||||
if(isset($_POST['ip']) && isset($_POST['reason'])) {
|
||||
send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason']));
|
||||
if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) {
|
||||
send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $_POST['end']));
|
||||
|
||||
global $page;
|
||||
$page->set_mode("redirect");
|
||||
|
@ -58,7 +60,7 @@ class IPBan extends Extension {
|
|||
}
|
||||
|
||||
if(is_a($event, 'AddIPBanEvent')) {
|
||||
$this->add_ip_ban($event->ip, $event->reason);
|
||||
$this->add_ip_ban($event->ip, $event->reason, $event->end);
|
||||
}
|
||||
|
||||
if(is_a($event, 'RemoveIPBanEvent')) {
|
||||
|
@ -114,14 +116,14 @@ class IPBan extends Extension {
|
|||
public function get_ip_ban($ip) {
|
||||
global $database;
|
||||
// yes, this is "? LIKE var", because ? is the thing with matching tokens
|
||||
return $database->db->GetRow("SELECT * FROM bans WHERE ? LIKE ip", array($ip));
|
||||
return $database->db->GetRow("SELECT * FROM bans WHERE ? LIKE ip AND date < now() AND (end > now() OR isnull(end))", array($ip));
|
||||
}
|
||||
|
||||
public function add_ip_ban($ip, $reason) {
|
||||
public function add_ip_ban($ip, $reason, $end) {
|
||||
global $database;
|
||||
$database->Execute(
|
||||
"INSERT INTO bans (ip, reason, date) VALUES (?, ?, now())",
|
||||
array($ip, $reason));
|
||||
"INSERT INTO bans (ip, reason, date, end) VALUES (?, ?, now(), ?)",
|
||||
array($ip, $reason, $end));
|
||||
}
|
||||
|
||||
public function remove_ip_ban($ip) {
|
||||
|
@ -139,6 +141,7 @@ class IPBan extends Extension {
|
|||
<tr>
|
||||
<td>{$ban['ip']}</td>
|
||||
<td>{$ban['reason']}</td>
|
||||
<td>{$ban['end']}</td>
|
||||
<td>
|
||||
<form action='".make_link("ip_ban/remove")."' method='POST'>
|
||||
<input type='hidden' name='ip' value='{$ban['ip']}'>
|
||||
|
@ -150,12 +153,13 @@ class IPBan extends Extension {
|
|||
}
|
||||
$html = "
|
||||
<table border='1'>
|
||||
<thead><td>IP</td><td>Reason</td><td>Action</td></thead>
|
||||
<thead><td>IP</td><td>Reason</td><td>Until</td><td>Action</td></thead>
|
||||
$h_bans
|
||||
<tr>
|
||||
<form action='".make_link("ip_ban/add")."' method='POST'>
|
||||
<td><input type='text' name='ip'></td>
|
||||
<td><input type='text' name='reason'></td>
|
||||
<td><input type='text' name='end'></td>
|
||||
<td><input type='submit' value='Ban'></td>
|
||||
</form>
|
||||
</tr>
|
||||
|
|
Reference in a new issue