From fe8ab4290111f4ba62be161c0291a1173c2dbd4f Mon Sep 17 00:00:00 2001 From: shish Date: Mon, 31 Mar 2008 02:49:40 +0000 Subject: [PATCH] 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 --- ext/ipban/main.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/ext/ipban/main.php b/ext/ipban/main.php index 0bf157f5..565354cf 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -91,18 +91,21 @@ 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; - $admin = $database->get_user_by_id($row['banner_id']); - print "IP {$row['ip']} has been banned by {$admin->name} because of {$row['reason']}"; + global $config; + global $database; - $contact_link = $config->get_string("contact_link"); - if(!empty($contact_link)) { - print "

Contact The Admin"; + $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 {$row['ip']} has been banned by {$admin->name} because of {$row['reason']}"; + + $contact_link = $config->get_string("contact_link"); + if(!empty($contact_link)) { + print "

Contact The Admin"; + } + exit; } - exit; } } // }}} @@ -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));