summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-06-13 21:37:19 +0000
committerDries Buytaert <dries@buytaert.net>2001-06-13 21:37:19 +0000
commitdb92d73b6eb8ed3b0d40a9deaf50c3ad680dd872 (patch)
treea5fdab2dcfb9927b178291d0cacebe1b8ab704be /includes
parent7d631fb606b816c8bfefb448a5708e44e8c0e932 (diff)
downloadbrdo-db92d73b6eb8ed3b0d40a9deaf50c3ad680dd872.tar.gz
brdo-db92d73b6eb8ed3b0d40a9deaf50c3ad680dd872.tar.bz2
- Improved watchdog and submission throttle: removed redundant code,
streamlined the existing code, added new watchdog type called "httpd" for Apache errors. The latter should make it easier to add watchdog filters later on. - Clarified some watchdog messages.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc18
-rw-r--r--includes/node.inc9
2 files changed, 15 insertions, 12 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 1702ccb32..54e19bd6c 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -19,21 +19,19 @@ function error_handler($errno, $message, $filename, $line, $variables) {
}
function watchdog($type, $message) {
- global $user, $watchdog, $PHP_SELF;
- $link = ($mod) ? $mod : substr(strrchr($PHP_SELF, "/"), 1, strrchr($PHP_SELF, "/") - 4);
- db_query("INSERT INTO watchdog (user, type, link, message, location, hostname, timestamp) VALUES ('$user->id', '". check_input($type) ."', '". check_input($link) ."', '". check_input($message) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."', '". time() ."')");
+ global $user;
+ db_query("INSERT INTO watchdog (user, type, message, location, hostname, timestamp) VALUES ('$user->id', '". check_input($type) ."', '". check_input($message) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."', '". time() ."')");
}
function throttle($type, $rate) {
global $user;
- if (!(user_access($user, "watchdog") || user_access($user, "comment") || user_access($user, "node"))) {
+ if (!user_access($user)) {
if ($throttle = db_fetch_object(db_query("SELECT * FROM watchdog WHERE type = '$type' AND hostname = '". getenv("REMOTE_ADDR") ."' AND ". time() ." - timestamp < $rate"))) {
watchdog("warning", "throttle: '". getenv("REMOTE_ADDR") ."' exceeded submission rate - $throttle->type");
- header("Location: error.php?op=throttle");
- die("submission rate exceeded");
+ die(message_throttle());
}
else {
- watchdog($type, "throttle control");
+ watchdog($type, "throttle");
}
}
}
@@ -48,10 +46,14 @@ function path_img() {
return "./images/";
}
-function notice_account() {
+function message_account() {
return t("This page requires a valid user account. Please <A HREF=\"account.php\">create a user account</A> and <A HREF=\"account.php\">login</A> prior to accessing it.");
}
+function message_throttle() {
+ return t("You exceeded the submission rate exceeded. Please wait a few minutes and try again.");
+}
+
function check_form($text) {
return htmlspecialchars(stripslashes($text));
}
diff --git a/includes/node.inc b/includes/node.inc
index 892dde6aa..94972461f 100644
--- a/includes/node.inc
+++ b/includes/node.inc
@@ -94,7 +94,7 @@ function node_save($node, $filter) {
}
else {
// verify submission rate:
- throttle("post node", variable_get("max_node_rate", 900));
+ throttle("node", variable_get("max_node_rate", 900));
// prepare queries:
foreach ($filter as $field=>$value) {
@@ -126,18 +126,19 @@ function node_save($node, $filter) {
if (($node[pid]) && ($node[status] == node_status("posted"))) {
db_query("UPDATE node SET status = '". node_status(expired) ."' WHERE nid = '$node[pid]'");
}
+ watchdog("special", "node: added $filter[type] '$node[title]'");
}
else {
- watchdog("warning", "node: added '$node[title]' - failed");
+ watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
}
}
else {
db_query("DELETE FROM node WHERE nid = '$nid'");
- watchdog("warning", "node: added '$node[title]' - failed");
+ watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
}
}
else {
- watchdog("warning", "node: added '$node[title]' - failed");
+ watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
}
}