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
2003-10-09 18:53:22 +00:00
function watchdog_help($section = "admin/help#watchdog") {
2003-09-30 15:10:48 +00:00
$output = "";
2003-08-19 19:59:33 +00:00
switch ($section) {
2003-10-09 18:53:22 +00:00
case 'admin/help#watchdog':
2003-10-07 18:16:41 +00:00
$output .= "<p>Watchdog module monitors your web site, capturing system events in a log to be reviewed by an authorized individual at a later time. The Watchdog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information. It is vital to %watchdog on a regular basis as it is often the only way to tell what is going on.</p>";
$output .= "<p>To ease administration, the watchdog will automatically discard old log entries, %log-entry. Needs \"cron.php\" to discard the entries.</p>";
$output = t($output, array("%watchdog" => l(t("check the Watchdog report"), "admin/watchdog"), "%log-entry" => l(t("as configured"), "admin/system/modules/watchdog")));
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog':
$output = t("The watchdog module monitors your web site, 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.");
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog/user':
$output = t("Watchdog events that have to do with users.");
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog/regular':
$output = t("Watchdog events that are \"normal\" and have no other classification.");
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog/httpd':
$output = t("Watchdog events that are from the web server.");
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog/special':
$output = t("Watchdog events about adding, changing, and moderating nodes and comments.");
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog/error':
$output = t("Watchdog general error events, such as invalid login, permission denied, and database errors.");
2003-08-19 19:59:33 +00:00
break;
2003-10-07 18:16:41 +00:00
case 'admin/watchdog/warning':
2003-10-07 19:06:04 +00:00
$output = t("Watchdog warning events. These events don't stop Drupal from running, but are things you should know.");
2003-10-07 18:16:41 +00:00
break;
case 'admin/system/modules#description':
$output = t("Logs and records system events.");
break;
case 'admin/system/modules/watchdog':
$output = t("Watchdog logs your system events. To see these logs go to %watchdog. Since these logs can grow out of control if kept around forever, below set how long an item should be kept in the log.<br />Note:<ul><li>To discard entries as set below you must run \"cron.php\" regularly.</li></ul>", array("%watchdog" => l(t("Site monitoring"), "admin/watchdog")));
2003-08-19 19:59:33 +00:00
break;
}
2003-05-29 09:15:00 +00:00
2003-10-07 18:16:41 +00:00
return $output;
2002-06-01 21:57:29 +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) {
2003-09-26 10:04:09 +00:00
if ($type == "system") {
if (user_access("administer watchdog")) {
2003-10-09 18:53:22 +00:00
menu("admin/watchdog", t("messages"), "watchdog_admin", 6);
menu("admin/watchdog/user", t("user"), "watchdog_admin");
menu("admin/watchdog/regular", t("regular"), "watchdog_admin");
menu("admin/watchdog/special", t("special"), "watchdog_admin");
menu("admin/watchdog/warning", t("warning"), "watchdog_admin");
menu("admin/watchdog/error", t("error"), "watchdog_admin");
menu("admin/watchdog/httpd", t("httpd"), "watchdog_admin");
menu("admin/watchdog/view", t("view details"), "watchdog_admin", 0, 1); // hidden menu
2003-09-26 10:04:09 +00:00
}
2001-06-29 22:08:57 +00:00
}
}
2003-02-11 20:01:17 +00:00
function watchdog_settings() {
2002-11-01 10:47:20 +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 => t("Never"));
$output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("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() {
2003-07-10 17:46:44 +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) {
2003-01-04 11:03:15 +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'", "actions" => "WHERE link != ''");
2000-12-14 14:13:37 +00:00
2003-08-21 15:47:50 +00:00
$header = array(
array("data" => t("date"), "field" => "w.timestamp", "sort" => "desc"),
array("data" => t("event"), "field" => "w.message"),
array("data" => t("user"), "field" => "u.name"),
array("data" => t("operations"), "colspan" => "2")
);
2003-09-09 18:18:43 +00:00
$sql = "SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : "");
2003-08-21 15:47:50 +00:00
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);
2001-01-26 13:38:46 +00:00
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]) {
2003-08-21 15:47:50 +00:00
$rows[] = array(
array("data" => format_date($watchdog->timestamp, "small"), "style" => "background-color: $background"),
array("data" => substr(strip_tags($watchdog->message), 0, 64), "style" => "background-color: $background"),
array("data" => format_name($watchdog), "style" => "background-color: $background"),
array("data" => $watchdog->link, "style" => "background-color: $background"),
array("data" => l(t("view details"), "admin/watchdog/view/$watchdog->wid"), "style" => "background-color: $background")
);
2001-04-06 14:14:16 +00:00
}
2000-12-14 14:13:37 +00:00
}
2002-12-29 18:31:46 +00:00
2003-08-21 15:47:50 +00:00
if (!$rows) {
2003-10-02 08:35:33 +00:00
$rows[] = array(array("data" => t("No log messages available."), "colspan" => "5"));
2003-08-21 15:47:50 +00:00
}
2003-10-02 08:35:33 +00:00
2003-08-21 15:47:50 +00:00
$pager = pager_display(NULL, 50, 0, "admin", tablesort_pager());
if (!empty($pager)) {
$rows[] = array(array("data" => $pager, "colspan" => "5"));
}
return table($header, $rows);
2000-12-14 14:13:37 +00:00
}
function watchdog_view($id) {
2002-12-29 18:31:46 +00:00
2003-09-09 18:18:43 +00:00
$result = db_query("SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d", $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\">";
2002-12-31 12:34:07 +00:00
$output .= " <tr><th>". t("Type") ."</th><td>$watchdog->type</td></tr>";
$output .= " <tr><th>". t("Date") ."</th><td>". format_date($watchdog->timestamp, "large") ."</td></tr>";
$output .= " <tr><th>". t("User") ."</th><td>". format_name($watchdog) ."</td></tr>";
$output .= " <tr><th>". t("Location") ."</th><td>$watchdog->location</td></tr>";
$output .= " <tr><th>". t("Message") ."</th><td>$watchdog->message</td></tr>";
$output .= " <tr><th>". t("Hostname") ."</th><td>$watchdog->hostname</td></tr>";
2001-11-11 23:24:26 +00:00
$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-20 20:00:40 +00:00
2001-06-30 09:50:36 +00:00
if (user_access("administer watchdog")) {
2003-01-06 19:51:01 +00:00
switch (arg(2)) {
2001-06-20 20:00:40 +00:00
case "help":
2003-09-19 07:41:55 +00:00
$output = watchdog_help();
2001-06-20 20:00:40 +00:00
break;
case "view":
2003-09-19 07:41:55 +00:00
$output = watchdog_view(arg(3));
2001-06-20 20:00:40 +00:00
break;
default:
2003-09-19 07:41:55 +00:00
$output = watchdog_overview(arg(2));
2001-06-20 20:00:40 +00:00
}
2003-09-19 07:41:55 +00:00
return $output;
2001-06-20 20:00:40 +00:00
}
else {
2003-09-19 07:41:55 +00:00
return 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
?>