From 8213f5b2627a6b63db9f84b572918bd7e3254dff Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 6 Apr 2001 14:14:16 +0000 Subject: A lot of small changes (search-n-replace) make a big commit: - fixed update bug in book.module - provide a log message when both adding and updating book pages - all configurable variables are now accessed through "variable_get()": - rewrote watchdog and submission throttle and removed watchdog.inc - improved robustness of sections.inc - imporved story.module - updated ./database/database.sql --- includes/comment.inc | 10 ++++++---- includes/common.inc | 20 ++++++++++++++++++- includes/function.inc | 2 +- includes/hostname.conf | 12 ----------- includes/node.inc | 4 +++- includes/search.inc | 2 +- includes/section.inc | 18 ++++++++--------- includes/theme.inc | 6 +++--- includes/variable.inc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ includes/watchdog.inc | 32 ------------------------------ 10 files changed, 96 insertions(+), 64 deletions(-) create mode 100644 includes/variable.inc delete mode 100644 includes/watchdog.inc (limited to 'includes') diff --git a/includes/comment.inc b/includes/comment.inc index 4e1a74f2c..23c79717a 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -124,6 +124,8 @@ function comment_preview($pid, $id, $subject, $comment) { function comment_post($pid, $id, $subject, $comment) { global $theme, $user; + throttle("post comment", variable_get(max_comment_rate, 60)); + // Check for duplicate comments: $duplicate = db_result(db_query("SELECT COUNT(cid) FROM comments WHERE pid = '$pid' AND lid = '$id' AND subject = '$subject' AND comment = '$comment'"), 0); @@ -135,7 +137,7 @@ function comment_post($pid, $id, $subject, $comment) { $subject = ($subject) ? $subject : substr($comment, 0, 29); // Add watchdog entry: - watchdog("comment", "comment: added '$subject'"); + watchdog("special", "comment: added '$subject'"); // Add comment to database: db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('$id', '$pid', '$user->id', '$subject', '$comment', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')"); @@ -281,9 +283,9 @@ function comment_render($lid, $cid) { // Pre-process variables: $lid = empty($lid) ? 0 : $lid; $cid = empty($cid) ? 0 : $cid; - $mode = ($user->id) ? $user->mode : variable_get("default_comment_mode", 4); - $order = ($user->id) ? $user->sort : variable_get("default_comment_order", 1); - $threshold = ($user->id) ? $user->threshold : variable_get("default_comment_threshold", 3); + $mode = ($user->id) ? $user->mode : variable_get(default_comment_mode, 4); + $order = ($user->id) ? $user->sort : variable_get(default_comment_order, 1); + $threshold = ($user->id) ? $user->threshold : variable_get(default_comment_threshold, 3); if ($user->id) { // Comment control: diff --git a/includes/common.inc b/includes/common.inc index 3dece2c39..81127c22c 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -9,12 +9,30 @@ function conf_init() { return $file; } +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() ."')"); +} + +function throttle($type, $rate) { + if (!(user_access($user, "watchdog") || user_access($user, "comment") || user_access($user, "node"))) { + 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"); + exit(); + } + else { + watchdog($type, "throttle control"); + } + } +} + $conf = conf_init(); include_once "includes/$conf.conf"; include_once "includes/database.inc"; include_once "includes/variable.inc"; -include_once "includes/watchdog.inc"; include_once "includes/function.inc"; include_once "includes/comment.inc"; include_once "includes/module.inc"; diff --git a/includes/function.inc b/includes/function.inc index 809fd4ed9..00a4a14f7 100644 --- a/includes/function.inc +++ b/includes/function.inc @@ -81,7 +81,7 @@ function format_date($timestamp, $type = "medium") { function format_username($username) { global $user; if ($username) return (user_access($user, "account") ? "$username" : "$username"); - else { global $anonymous; return $anonymous; } + else return variable_get(anonymous, "Anonymous"); } function format_email($address) { diff --git a/includes/hostname.conf b/includes/hostname.conf index 871110493..1c2528323 100644 --- a/includes/hostname.conf +++ b/includes/hostname.conf @@ -8,13 +8,6 @@ $db_user = "username"; $db_pass = "password"; $db_name = "database"; -# -# Administrative information -# -$site_name = "site name"; -$site_url = "http://yourdomain.com/"; // add a trailing slash -$site_email = "info@yourdomain.com"; - # # Comment votes: # The keys of this associative array are displayed in each comment's selection box whereas the corresponding values represent the mathematical calculation to be performed to update a comment's value. @@ -33,11 +26,6 @@ $comment_votes = array("none" => "none", # $allowed_html = "