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,10 +91,12 @@ class IPBan extends Extension {
// }}}
// deal with banned person {{{
private function check_ip_ban() {
$row = $this->get_ip_ban($_SERVER['REMOTE_ADDR']);
if($row) {
global $config;
global $database;
$bans = $this->get_active_bans();
foreach($bans as $row) {
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>";
@ -105,6 +107,7 @@ class IPBan extends Extension {
exit;
}
}
}
// }}}
// database {{{
private function get_bans() {
@ -114,6 +117,13 @@ class IPBan extends Extension {
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) {
global $database;
return $database->db->GetRow("SELECT * FROM bans WHERE ip = ? AND date < now() AND (end > now() OR isnull(end))", array($ip));