2001-03-10 11:07:52 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2000-12-14 14:13:37 +00:00
2001-02-25 17:17:26 +00:00
function watchdog_help() {
?>
<P>The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time. The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.</P>
2001-05-19 13:41:52 +00:00
<P>To ease administration, the watchdog will automatically discard old log entries.</P>
2001-03-10 11:07:52 +00:00
<?php
2001-02-25 17:17:26 +00:00
}
2001-06-20 20:00:40 +00:00
function watchdog_perm() {
2001-06-30 09:50:36 +00:00
return array("administer watchdog");
2001-06-20 20:00:40 +00:00
}
2001-06-29 22:08:57 +00:00
function watchdog_link($type) {
2001-06-30 09:50:36 +00:00
if ($type == "admin" && user_access("administer watchdog")) {
2002-04-20 11:52:50 +00:00
$links[] = la(t("watchdog"), array("mod" => "watchdog"));
2001-06-29 22:08:57 +00:00
}
return $links ? $links : array();
}
2001-05-20 13:51:40 +00:00
function watchdog_conf_options() {
2001-07-02 20:30:32 +00:00
$period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200), 1000000000 => "Never");
$output .= form_select("Discard entries older than", "watchdog_clear", variable_get("watchdog_clear", 604800), $period, "The time watchdog entries should be kept. Older entries will be automatically discarded. Requires crontab.");
2001-05-19 13:41:52 +00:00
return $output;
}
2000-12-16 08:39:01 +00:00
function watchdog_cron() {
2001-05-19 13:41:52 +00:00
db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
2000-12-16 08:39:01 +00:00
}
2000-12-14 14:13:37 +00:00
2001-06-15 10:43:39 +00:00
function watchdog_overview($type) {
2001-09-16 11:33:14 +00:00
$color = array(user => "#FFEEAA", message => "#FFFFFF", special => "#A49FFF", warning => "#FFAA22", httpd => "#99DD99", error => "#EE4C4C");
$query = array(user => "WHERE type = 'user'", regular => "WHERE type = 'message'", special => "WHERE type = 'special'", warning => "WHERE type = 'warning'", error => "WHERE type = 'error'", httpd => "WHERE type = 'httpd'");
2000-12-14 14:13:37 +00:00
2001-10-14 15:27:00 +00:00
$result = db_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY timestamp DESC LIMIT 1000");
2001-01-26 13:38:46 +00:00
2001-11-11 23:24:26 +00:00
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
$output .= " <tr><th>date</th><th>message</th><th>user</th><th>operations</th></tr>";
2000-12-14 14:13:37 +00:00
while ($watchdog = db_fetch_object($result)) {
2001-06-15 10:43:39 +00:00
if ($background = $color[$watchdog->type]) {
2002-04-22 09:05:36 +00:00
$output .= " <tr bgcolor=\"$background\"><td>". format_date($watchdog->timestamp, "small") ."</td><td>". substr(check_output($watchdog->message), 0, 64) ."</td><td align=\"center\">". format_name($watchdog) ."</a></td><td align=\"center\">". la(t("details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."</td></tr>";
2001-04-06 14:14:16 +00:00
}
2000-12-14 14:13:37 +00:00
}
2001-11-11 23:24:26 +00:00
$output .= "</table>";
2000-12-14 14:13:37 +00:00
2001-04-06 14:14:16 +00:00
return $output;
2000-12-14 14:13:37 +00:00
}
function watchdog_view($id) {
2001-10-14 15:27:00 +00:00
$result = db_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid WHERE w.wid = '$id'");
2000-12-14 14:13:37 +00:00
if ($watchdog = db_fetch_object($result)) {
2001-11-11 23:24:26 +00:00
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
$output .= " <tr><th>Type:</th><td>". check_output($watchdog->type) ."</td></tr>";
$output .= " <tr><th>Date:</th><td>". format_date($watchdog->timestamp, "large") ."</td></tr>";
$output .= " <tr><th>User:</th><td>". format_name($watchdog) ."</td></tr>";
$output .= " <tr><th>Location:</th><td>". check_output($watchdog->location) ."</td></tr>";
$output .= " <tr><th>Message:</th><td>". check_output($watchdog->message) ."</td></tr>";
$output .= " <tr><th>Hostname:</th><td>". check_output($watchdog->hostname) ."</td></tr>";
$output .= "</table>";
2001-04-05 20:33:36 +00:00
2001-04-06 14:14:16 +00:00
return $output;
}
2001-04-05 20:33:36 +00:00
}
2000-12-14 14:13:37 +00:00
function watchdog_admin() {
2001-06-29 22:08:57 +00:00
global $op, $id, $type, $order;
2001-06-20 20:00:40 +00:00
2001-06-30 09:50:36 +00:00
if (user_access("administer watchdog")) {
2001-06-20 20:00:40 +00:00
2002-04-20 11:52:50 +00:00
$links[] = la(t("user messages"), array("mod" => "watchdog", "type" => "user"));
$links[] = la(t("regular messages"), array("mod" => "watchdog", "type" => "regular"));
$links[] = la(t("special messages"), array("mod" => "watchdog", "type" => "special"));
$links[] = la(t("warning messages"), array("mod" => "watchdog", "type" => "warning"));
$links[] = la(t("error messages"), array("mod" => "watchdog", "type" => "error"));
$links[] = la(t("httpd messages"), array("mod" => "watchdog", "type" => "httpd"));
$links[] = la(t("overview"), array("mod" => "watchdog"));
$links[] = la(t("help"), array("mod" => "watchdog", "op" => "help"));
2002-04-22 09:05:36 +00:00
print "<small>". implode(" | ", $links) ."</small><hr />";
2001-06-20 20:00:40 +00:00
switch ($op) {
case "help":
watchdog_help();
break;
case "view":
print watchdog_view(check_input($id));
break;
default:
print watchdog_overview($type);
}
}
else {
print message_access();
2000-12-14 14:13:37 +00:00
}
}
2001-11-01 11:00:51 +00:00
2001-10-09 21:01:47 +00:00
?>