download all bans, then compare in PHP; saves DB effort and allows more flexible ban matching

git-svn-id: file:///home/shish/svn/shimmie2/trunk@738 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-03-31 02:49:40 +00:00
parent abc2fe278a
commit fe8ab42901

View File

@ -91,18 +91,21 @@ class IPBan extends Extension {
// }}} // }}}
// deal with banned person {{{ // deal with banned person {{{
private function check_ip_ban() { private function check_ip_ban() {
$row = $this->get_ip_ban($_SERVER['REMOTE_ADDR']); global $config;
if($row) { global $database;
global $config;
global $database;
$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"); $bans = $this->get_active_bans();
if(!empty($contact_link)) { foreach($bans as $row) {
print "<p><a href='$contact_link'>Contact The Admin</a>"; if($row['ip'] == $_SERVER['REMOTE_ADDR']) {
$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");
if(!empty($contact_link)) {
print "<p><a href='$contact_link'>Contact The Admin</a>";
}
exit;
} }
exit;
} }
} }
// }}} // }}}
@ -114,6 +117,13 @@ class IPBan extends Extension {
else {return array();} else {return array();}
} }
private function get_active_bans() {
global $database;
$bans = $database->get_all("SELECT * FROM bans WHERE (date < now()) AND (end > now() OR isnull(end))");
if($bans) {return $bans;}
else {return array();}
}
private function get_ip_ban($ip) { private function get_ip_ban($ip) {
global $database; global $database;
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));