- Added an extra parameter to watchdog() which lets you specifiy an "action"

or "operation" link.

- Made the main page of the administration section show an overview of all
  watchdog entries with such action link.

- Fixed typo in PostgreSQL database scheme.
4.2.x
Dries Buytaert 2003-01-04 11:03:15 +00:00
parent 7a6b8e3d3c
commit 8a63646576
13 changed files with 43 additions and 47 deletions

View File

@ -62,8 +62,13 @@ function admin_page($mod) {
print "<small>$help</small><br /><br />";
}
if ($mod) {
print module_invoke($mod, "admin");
}
else {
print watchdog_overview("actions");
}
module_invoke($mod, "admin");
print "</div>";
db_query("DELETE FROM menu");

View File

@ -554,6 +554,7 @@ CREATE TABLE watchdog (
uid int(10) NOT NULL default '0',
type varchar(16) NOT NULL default '',
message text NOT NULL,
link varchar(255) NOT NULL default '',
location varchar(128) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp int(11) NOT NULL default '0',

View File

@ -192,7 +192,7 @@ CREATE TABLE item (
link varchar(255) NOT NULL default '',
author varchar(255) NOT NULL default '',
description text NOT NULL default '',
timestamp integer default NULL default '',
timestamp integer NOT NULL default '0',
attributes varchar(255) NOT NULL default '',
PRIMARY KEY (iid)
);
@ -554,6 +554,7 @@ CREATE TABLE watchdog (
uid integer NOT NULL default '0',
type varchar(16) NOT NULL default '',
message text NOT NULL default '',
link varchar(255) NOT NULL default '',
location varchar(128) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp integer NOT NULL default '0',

View File

@ -33,9 +33,9 @@ function error_handler($errno, $message, $filename, $line, $variables) {
}
}
function watchdog($type, $message) {
function watchdog($type, $message, $link = NULL) {
global $user;
db_query("INSERT INTO watchdog (uid, type, message, location, hostname, timestamp) VALUES ('$user->uid', '%s', '%s', '%s', '%s', '%s')", $type, $message, request_uri(), getenv("REMOTE_ADDR"), time());
db_query("INSERT INTO watchdog (uid, type, message, link, location, hostname, timestamp) VALUES ('$user->uid', '%s', '%s', '%s', '%s', '%s', '%s')", $type, $message, $link, request_uri(), getenv("REMOTE_ADDR"), time());
}
function throttle($type, $rate) {

View File

@ -201,7 +201,7 @@ function comment_post($edit) {
*/
$edit["subject"] = strip_tags($edit["subject"]);
if ($edit["subject"] == "") {
$edit["subject"] = substr(strip_tags($edit["comment"]), 0, 29);
}
@ -249,7 +249,7 @@ function comment_post($edit) {
** Add entry to the watchdog log:
*/
watchdog("special", "comment: updated '". $edit["subject"] ."'");
watchdog("special", "comment: updated '". $edit["subject"] ."'", l(t("view comment"), array("id" => $edit["nid"], "cid" => $edit["cid"])));
}
else {
/*
@ -282,7 +282,7 @@ function comment_post($edit) {
** Add entry to the watchdog log:
*/
watchdog("special", "comment: added '". $edit["subject"] ."'");
watchdog("special", "comment: added '". $edit["subject"] ."'", l(t("view comment"), array("id" => $edit["nid"], "cid" => $edit["cid"])));
}
/*

View File

@ -201,7 +201,7 @@ function comment_post($edit) {
*/
$edit["subject"] = strip_tags($edit["subject"]);
if ($edit["subject"] == "") {
$edit["subject"] = substr(strip_tags($edit["comment"]), 0, 29);
}
@ -249,7 +249,7 @@ function comment_post($edit) {
** Add entry to the watchdog log:
*/
watchdog("special", "comment: updated '". $edit["subject"] ."'");
watchdog("special", "comment: updated '". $edit["subject"] ."'", l(t("view comment"), array("id" => $edit["nid"], "cid" => $edit["cid"])));
}
else {
/*
@ -282,7 +282,7 @@ function comment_post($edit) {
** Add entry to the watchdog log:
*/
watchdog("special", "comment: added '". $edit["subject"] ."'");
watchdog("special", "comment: added '". $edit["subject"] ."'", l(t("view comment"), array("id" => $edit["nid"], "cid" => $edit["cid"])));
}
/*

View File

@ -1085,7 +1085,7 @@ function node_submit($node) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: updated '$node->title'");
watchdog("special", "$node->type: updated '$node->title'", l("view post", array("id" => $node->nid)));
$output = t("The node has been updated.");
}
}
@ -1127,7 +1127,7 @@ function node_submit($node) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: added '$node->title'");
watchdog("special", "$node->type: added '$node->title'", l("view post", array("id" => $nid)));
$output = t("Thanks for your submission.");
}
}

View File

@ -1085,7 +1085,7 @@ function node_submit($node) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: updated '$node->title'");
watchdog("special", "$node->type: updated '$node->title'", l("view post", array("id" => $node->nid)));
$output = t("The node has been updated.");
}
}
@ -1127,7 +1127,7 @@ function node_submit($node) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: added '$node->title'");
watchdog("special", "$node->type: added '$node->title'", l("view post", array("id" => $nid)));
$output = t("Thanks for your submission.");
}
}

View File

@ -532,7 +532,7 @@ function user_login($edit = array(), $msg = "") {
if (!$user && $server && $result = user_get_authmaps("$name@$server")) {
if (module_invoke(key($result), "auth", $name, $pass, $server)) {
$user = user_external_load("$name@$server");
watchdog("user", "external load: $name@$server, module: " . key($result));
watchdog("user", "external load: $name@$server, module: ". key($result));
}
else {
$error = t("Invalid password for %s.", array("%s" => "<i>$name@$server</i>"));
@ -548,8 +548,8 @@ function user_login($edit = array(), $msg = "") {
if (module_hook($module, "auth")) {
if (module_invoke($module, "auth", $name, $pass, $server)) {
if (variable_get("user_register", 1) == 1 && !user_load(array("name" => "$name@$server"))) { //register this new user
watchdog("user", "new user: $name@$server ($module ID)");
$user = user_save("", array("name" => "$name@$server", "pass" => user_password(), "init" => "$name@$server", "status" => 1, "authname_$module" => "$name@$server", "rid" => _user_authenticated_id()));
watchdog("user", "new user: $name@$server ($module ID)", la("edit user", array("mod" => "user", "op" => "edit", "id" => $user->uid)));
break;
}
}
@ -788,7 +788,7 @@ function user_register($edit = array()) {
// TODO: is this necessary? Won't session_write replicate this?
unset($edit["session"]);
$account = user_save("", array_merge(array("name" => $edit["name"], "pass" => $pass, "init" => $edit["mail"], "mail" => $edit["mail"], "rid" => _user_authenticated_id(), "rating" => 0, "status" => (variable_get("user_register", 1) == 1 ? 1 : 0)), $data));
watchdog("user", "new user: '". $edit["name"] ."' &lt;". $edit["mail"] ."&gt;");
watchdog("user", "new user: '". $edit["name"] ."' &lt;". $edit["mail"] ."&gt;", la("edit user", array("mod" => "user", "op" => "edit", "id" => $account->uid)));
$variables = array("%username" => $edit["name"], "%site" => variable_get("site_name", "drupal"), "%password" => $pass, "%uri" => path_uri(), "%uri_brief" => path_uri(1), "%mailto" => $edit["mail"], "%date" => format_date(time()));
@ -1134,7 +1134,6 @@ function user_admin_create($edit = array()) {
}
if ($success) {
watchdog("user", "new user: '". $edit["name"] ."' &lt;". $edit["mail"] ."&gt;");
user_save("", array("name" => $edit["name"], "pass" => $edit["pass"], "init" => $edit["mail"], "mail" => $edit["mail"], "rid" => _user_authenticated_id(), "status" => 1));
@ -1719,16 +1718,13 @@ function user_help_devel_da() {
// Since Blogger doesn't return a properly formed FaultCode, we just search for the string 'fault'.
if ($result &amp;&amp; !stristr($result-&gt;serialize(), &quot;fault&quot;)) {
// watchdog(&quot;user&quot;, &quot;Success Blogger Auth. Response: &quot; .
$result-&gt;serialize());
return 1;
}
else if ($result) {
// watchdog(&quot;user&quot;, &quot;Blogger Auth failure. Response was &quot; . $result-&gt;serialize());
return 0;
}
else {
// watchdog(&quot;user&quot;, &quot;Blogger Auth failure. Could not connect.&quot;);
return 0;
}
}</pre>
@ -1778,15 +1774,12 @@ function user_help_devel_da() {
to the user.module if your registration database has become inoperable or unreachable.</p>
<pre>
if ($result &amp;&amp; !stristr($result-&gt;serialize(), &quot;fault&quot;)) {
// watchdog(&quot;user&quot;, &quot;Success Blogger auth. Response was &quot; . $result-&gt;serialize());
return 1;
}
else if ($result) {
// watchdog(&quot;user&quot;, &quot;Blogger auth failure. Response was &quot; . $result-&gt;serialize());
return 0;
}
else {
// watchdog(&quot;user&quot;, &quot;Blogger auth failure. Could not connect.&quot;);<br>
return 0;
}
</pre>
@ -1796,8 +1789,7 @@ function user_help_devel_da() {
testing for all cases. In the case of Blogger, we search for the string 'fault'
in the response. If that string is present, or there is no repsonse, our function
returns FALSE. Otherwise, Blogger has returned valid data to our method request
and we return TRUE. There are several watchdog() calls here which are commented
out. These are useful for debugging, so I've left them in the code as comments.
and we return TRUE.
</p>
<pre>function blogger_page() {
global $theme;

View File

@ -532,7 +532,7 @@ function user_login($edit = array(), $msg = "") {
if (!$user && $server && $result = user_get_authmaps("$name@$server")) {
if (module_invoke(key($result), "auth", $name, $pass, $server)) {
$user = user_external_load("$name@$server");
watchdog("user", "external load: $name@$server, module: " . key($result));
watchdog("user", "external load: $name@$server, module: ". key($result));
}
else {
$error = t("Invalid password for %s.", array("%s" => "<i>$name@$server</i>"));
@ -548,8 +548,8 @@ function user_login($edit = array(), $msg = "") {
if (module_hook($module, "auth")) {
if (module_invoke($module, "auth", $name, $pass, $server)) {
if (variable_get("user_register", 1) == 1 && !user_load(array("name" => "$name@$server"))) { //register this new user
watchdog("user", "new user: $name@$server ($module ID)");
$user = user_save("", array("name" => "$name@$server", "pass" => user_password(), "init" => "$name@$server", "status" => 1, "authname_$module" => "$name@$server", "rid" => _user_authenticated_id()));
watchdog("user", "new user: $name@$server ($module ID)", la("edit user", array("mod" => "user", "op" => "edit", "id" => $user->uid)));
break;
}
}
@ -788,7 +788,7 @@ function user_register($edit = array()) {
// TODO: is this necessary? Won't session_write replicate this?
unset($edit["session"]);
$account = user_save("", array_merge(array("name" => $edit["name"], "pass" => $pass, "init" => $edit["mail"], "mail" => $edit["mail"], "rid" => _user_authenticated_id(), "rating" => 0, "status" => (variable_get("user_register", 1) == 1 ? 1 : 0)), $data));
watchdog("user", "new user: '". $edit["name"] ."' &lt;". $edit["mail"] ."&gt;");
watchdog("user", "new user: '". $edit["name"] ."' &lt;". $edit["mail"] ."&gt;", la("edit user", array("mod" => "user", "op" => "edit", "id" => $account->uid)));
$variables = array("%username" => $edit["name"], "%site" => variable_get("site_name", "drupal"), "%password" => $pass, "%uri" => path_uri(), "%uri_brief" => path_uri(1), "%mailto" => $edit["mail"], "%date" => format_date(time()));
@ -1134,7 +1134,6 @@ function user_admin_create($edit = array()) {
}
if ($success) {
watchdog("user", "new user: '". $edit["name"] ."' &lt;". $edit["mail"] ."&gt;");
user_save("", array("name" => $edit["name"], "pass" => $edit["pass"], "init" => $edit["mail"], "mail" => $edit["mail"], "rid" => _user_authenticated_id(), "status" => 1));
@ -1719,16 +1718,13 @@ function user_help_devel_da() {
// Since Blogger doesn't return a properly formed FaultCode, we just search for the string 'fault'.
if ($result &amp;&amp; !stristr($result-&gt;serialize(), &quot;fault&quot;)) {
// watchdog(&quot;user&quot;, &quot;Success Blogger Auth. Response: &quot; .
$result-&gt;serialize());
return 1;
}
else if ($result) {
// watchdog(&quot;user&quot;, &quot;Blogger Auth failure. Response was &quot; . $result-&gt;serialize());
return 0;
}
else {
// watchdog(&quot;user&quot;, &quot;Blogger Auth failure. Could not connect.&quot;);
return 0;
}
}</pre>
@ -1778,15 +1774,12 @@ function user_help_devel_da() {
to the user.module if your registration database has become inoperable or unreachable.</p>
<pre>
if ($result &amp;&amp; !stristr($result-&gt;serialize(), &quot;fault&quot;)) {
// watchdog(&quot;user&quot;, &quot;Success Blogger auth. Response was &quot; . $result-&gt;serialize());
return 1;
}
else if ($result) {
// watchdog(&quot;user&quot;, &quot;Blogger auth failure. Response was &quot; . $result-&gt;serialize());
return 0;
}
else {
// watchdog(&quot;user&quot;, &quot;Blogger auth failure. Could not connect.&quot;);<br>
return 0;
}
</pre>
@ -1796,8 +1789,7 @@ function user_help_devel_da() {
testing for all cases. In the case of Blogger, we search for the string 'fault'
in the response. If that string is present, or there is no repsonse, our function
returns FALSE. Otherwise, Blogger has returned valid data to our method request
and we return TRUE. There are several watchdog() calls here which are commented
out. These are useful for debugging, so I've left them in the code as comments.
and we return TRUE.
</p>
<pre>function blogger_page() {
global $theme;

View File

@ -43,16 +43,16 @@ function watchdog_cron() {
}
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'");
$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 != ''");
$result = pager_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 100);
$output .= "<table>";
$output .= " <tr><th>" . t("date") . "</th><th>" . t("message") . "</th><th>" . t("user") . "</th><th>" . t("operations") . "</th></tr>";
$output .= " <tr><th>" . t("date") . "</th><th>" . t("event") . "</th><th>" . t("user") . "</th><th colspan=\"2\">" . t("operations") . "</th></tr>";
while ($watchdog = db_fetch_object($result)) {
if ($background = $color[$watchdog->type]) {
$output .= " <tr bgcolor=\"$background\"><td nowrap=\"nowrap\">". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($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>";
$output .= " <tr bgcolor=\"$background\"><td nowrap=\"nowrap\">". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($watchdog->message), 0, 64) ."</td><td align=\"center\">". format_name($watchdog) ."</a></td><td align=\"center\">$watchdog->link</td><td align=\"center\">". la(t("view details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."</td></tr>";
}
}

View File

@ -43,16 +43,16 @@ function watchdog_cron() {
}
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'");
$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 != ''");
$result = pager_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 100);
$output .= "<table>";
$output .= " <tr><th>" . t("date") . "</th><th>" . t("message") . "</th><th>" . t("user") . "</th><th>" . t("operations") . "</th></tr>";
$output .= " <tr><th>" . t("date") . "</th><th>" . t("event") . "</th><th>" . t("user") . "</th><th colspan=\"2\">" . t("operations") . "</th></tr>";
while ($watchdog = db_fetch_object($result)) {
if ($background = $color[$watchdog->type]) {
$output .= " <tr bgcolor=\"$background\"><td nowrap=\"nowrap\">". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($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>";
$output .= " <tr bgcolor=\"$background\"><td nowrap=\"nowrap\">". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($watchdog->message), 0, 64) ."</td><td align=\"center\">". format_name($watchdog) ."</a></td><td align=\"center\">$watchdog->link</td><td align=\"center\">". la(t("view details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."</td></tr>";
}
}

View File

@ -60,7 +60,8 @@ $mysql_updates = array(
"2002-11-20" => "update_45",
"2002-12-10" => "update_46",
"2002-12-22" => "update_47",
"2002-12-29" => "update_48"
"2002-12-29" => "update_48",
"2003-01-03" => "update_49"
);
// Update functions
@ -662,6 +663,10 @@ function update_48() {
}
}
function update_49() {
update_sql("ALTER TABLE watchdog ADD link varchar(255) DEFAULT '' NULL");
}
function update_upgrade3() {
update_sql("INSERT INTO system VALUES ('archive.module','archive','module','',1)");
update_sql("INSERT INTO system VALUES ('block.module','block','module','',1)");