drupal/includes/watchdog.inc

33 lines
1.3 KiB
PHP
Raw Normal View History

<?php
$watchdog = array("comment" => array("0", $submission_rate["comment"]),
"node" => array("1", $submission_rate["node"]),
"message" => array("3", "0"),
"warning" => array("4", "0"),
"error" => array("5", "0"));
function watchdog($id, $message) {
global $user, $watchdog, $watchdog_history;
// flood protection:
if ($watchdog[$id][1] && !user_access($user, "watchdog")) {
if ($log = db_fetch_object(db_query("SELECT * FROM watchdog WHERE hostname = '". getenv("REMOTE_ADDR") ."' AND level = '". $watchdog[$id][0] ."'"))) {
2001-01-26 13:38:46 +00:00
if (time() - $log->timestamp < $watchdog[$id][1]) {
watchdog("warning", "'". getenv("REMOTE_ADDR") ."' exceeded '$id' submission rate");
header("Location: error.php?op=flood");
exit();
}
}
}
// perform query to add new watchdog entry:
2001-03-08 17:44:10 +00:00
db_query("INSERT INTO watchdog (level, timestamp, user, message, location, hostname) VALUES ('". $watchdog[$id][0] ."', '". time() ."', '". check_input($user->id) ."', '". check_input(check_output($message)) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."')");
}
function watchdog_clean($history = 302400) {
$timestamp = time() - $history;
db_query("DELETE FROM watchdog WHERE timestamp < $timestamp");
}
2001-01-26 13:38:46 +00:00
?>