92 lines
4.6 KiB
Plaintext
92 lines
4.6 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
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>
|
|
<P>To ease administration, the watchdog will automatically discard old log entries.</P>
|
|
<?php
|
|
}
|
|
|
|
function watchdog_perm() {
|
|
return array("administer watchdog");
|
|
}
|
|
|
|
function watchdog_link($type) {
|
|
if ($type == "admin" && user_access("administer watchdog")) {
|
|
$links[] = "<a href=\"admin.php?mod=watchdog\">watchdog</a>";
|
|
}
|
|
|
|
return $links ? $links : array();
|
|
}
|
|
|
|
function watchdog_conf_options() {
|
|
$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.");
|
|
return $output;
|
|
}
|
|
|
|
function watchdog_cron() {
|
|
db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
|
|
}
|
|
|
|
function watchdog_overview($type) {
|
|
$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'");
|
|
|
|
$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");
|
|
|
|
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
|
|
$output .= " <tr><th>date</th><th>message</th><th>user</th><th>operations</th></tr>";
|
|
while ($watchdog = db_fetch_object($result)) {
|
|
if ($background = $color[$watchdog->type]) {
|
|
$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\"><a href=\"admin.php?mod=watchdog&op=view&id=$watchdog->wid\">details</a></td></tr>";
|
|
}
|
|
}
|
|
$output .= "</table>";
|
|
|
|
return $output;
|
|
}
|
|
|
|
function watchdog_view($id) {
|
|
$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'");
|
|
|
|
if ($watchdog = db_fetch_object($result)) {
|
|
$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>";
|
|
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
function watchdog_admin() {
|
|
global $op, $id, $type, $order;
|
|
|
|
if (user_access("administer watchdog")) {
|
|
|
|
print "<small><a href=\"admin.php?mod=watchdog&type=user\">user messages</a> | <a href=\"admin.php?mod=watchdog&type=regular\">regular messages</a> | <a href=\"admin.php?mod=watchdog&type=special\">special messages</a> | <a href=\"admin.php?mod=watchdog&type=warning\">warning messages</a> | <a href=\"admin.php?mod=watchdog&type=error\">error messages</a> | <a href=\"admin.php?mod=watchdog&type=httpd\">httpd messages</a> | <a href=\"admin.php?mod=watchdog\">overview</a> | <a href=\"admin.php?mod=watchdog&op=help\">help</a></small><hr />";
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
?>
|