diff options
author | Dries Buytaert <dries@buytaert.net> | 2000-06-11 13:26:51 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2000-06-11 13:26:51 +0000 |
commit | c8b214483347305966e1ffc1c913bcda991fbeb7 (patch) | |
tree | 47837ddf479134bc3f5442a879caac30acb2b4d5 | |
parent | f66120de0576cd3b19ba329ed4976d7d9e6d7d6f (diff) | |
download | brdo-c8b214483347305966e1ffc1c913bcda991fbeb7.tar.gz brdo-c8b214483347305966e1ffc1c913bcda991fbeb7.tar.bz2 |
Updates:
* Fixed (hopefully) the bugs earlier reported by Jeroen. :o)
* Revamped the code to be more efficient as well as easier to use and
maintain.
-rw-r--r-- | ban.class.php | 19 | ||||
-rw-r--r-- | ban.inc | 34 | ||||
-rw-r--r-- | ban.php | 56 |
3 files changed, 56 insertions, 53 deletions
diff --git a/ban.class.php b/ban.class.php deleted file mode 100644 index 93a7eaf24..000000000 --- a/ban.class.php +++ /dev/null @@ -1,19 +0,0 @@ -<? - -$type = array("addresses" => 0x01, - "profanity" => 0x02, - "hostnames" => 0x03, - "usernames" => 0x04); - -function ban_match($mask, $category) { - ### Connect to database: - db_connect(); - - ### Perform query: - $result = db_query("SELECT * FROM bans WHERE type = $category AND '$mask' LIKE mask"); - - ### Return result: - return db_fetch_object($result); -} - -?> diff --git a/ban.inc b/ban.inc new file mode 100644 index 000000000..72f6f2ce0 --- /dev/null +++ b/ban.inc @@ -0,0 +1,34 @@ +<? + +$type = array("addresses" => 0x01, + "profanity" => 0x02, + "hostnames" => 0x03, + "usernames" => 0x04); + +function ban_match($mask, $category) { + ### Perform query: + $result = db_query("SELECT * FROM bans WHERE type = $category AND LOWER('$mask') LIKE LOWER(mask)"); + + ### Return result: + return db_fetch_object($result); +} + +function ban_add($mask, $category, $reason, $message = "") { + if (empty($mask)) { + $message = "Failed: empty banmasks are not allowed.<P>\n"; + } + else if ($ban = db_fetch_object(db_query("SELECT * FROM bans WHERE type = $category AND '$mask' LIKE mask"))) { + $message = "Failed: ban is already matched by '$ban->mask'.<P>\n"; + } + else { + $result = db_query("INSERT INTO bans (mask, type, reason, timestamp) VALUES ('$mask', '$category', '$reason', '". time() ."')"); + $message = "Added new ban with mask `$mask'.<P>\n"; + } +} + +function ban_delete($id) { + ### Perform query: + $result = db_query("DELETE FROM bans WHERE id = $id"); +} + +?> @@ -1,52 +1,41 @@ <? +////////////////////////////////////////////////// // This code should go in the admin pages and is only a temporary -// placeholder untill we are going to rewrite the admin pages. +// placeholder untill we are going to rewrite the admin pages. If +// you have the sudden urge to integrate it into admin.php or if +// you have some time to kill ... I won't stop you. A rewrite of +// admin.php is sheduled for v0.20 anyway ... +// Like this the ban.php code I just queued it to be included into +// the new admin pages. After proper integration, this file can +// be removed. +// +// -- Dries +////////////////////////////////////////////////// + +include "database.inc"; +include "ban.inc"; function ban_check($mask, $category) { - include "ban.class.php"; - $ban = ban_match($mask, $category); print "<H3>Status:</H3>\n"; print "". ($ban ? "Matched ban '<B>$ban->mask</B>' with reason: <I>$ban->reason</I>.<P>\n" : "No matching bans for '$mask'.<P>\n") .""; } -function ban_add($mask, $category, $reason) { - ### Connect to database and perform query: - include "database.inc"; - db_connect(); +function ban_new($mask, $category, $reason) { + ban_add($mask, $category, $reason, &$message); print "<H3>Status:</H3>\n"; - if (empty($mask)) { - print "Failed: empty banmasks are not allowed.<P>\n"; - } - else if ($ban = db_fetch_object(db_query("SELECT * FROM bans WHERE type = $category AND '$mask' LIKE mask"))) { - print "Failed: ban is already matched by '$ban->mask'.<P>\n"; - } - else { - $result = db_query("INSERT INTO bans (mask, type, reason, timestamp) VALUES ('$mask', '$category', '$reason', '". time() ."')"); - print "Added new ban with mask `$mask'.<P>\n"; - } -} - -function ban_delete($id) { - ### Connect to database and perform query: - include "database.inc"; - db_connect(); - $result = db_query("DELETE FROM bans WHERE id = $id"); + print "$message\n"; } function ban_display($category = "") { - global $PHP_SELF; - - include "ban.class.php"; + global $PHP_SELF, $type; ### initialize variable: $category = $category ? $category : 1; - ### Connect to database and perform query: - include "database.inc"; - db_connect(); + ### Perform query: $result = db_query("SELECT * FROM bans WHERE type = $category ORDER BY mask"); ### Generate output: @@ -62,7 +51,7 @@ function ban_display($category = "") { print " <OPTION VALUE=\"$cur\"". ($cur == $category ? " SELECTED" : "") .">". key($type) ."</OPTION>\n"; } print " </SELECT>\n"; - print " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Display\">\n"; + print " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Refresh\">\n"; print " </FORM>\n"; print " </TH>\n"; print " </TR>\n"; @@ -111,12 +100,11 @@ function ban_display($category = "") { } include "admin.inc"; - admin_header(); switch ($op) { case "Add ban": - ban_add($mask, $category, $reason); + ban_new($mask, $category, $reason); ban_display($category); break; case "Check ban": @@ -125,7 +113,7 @@ switch ($op) { break; case "delete": ban_delete($id); - displayBans($category); + ban_display($category); break; default: ban_display($category); |