From 8a636465767fc47f37a0768d45b86ca53a722085 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 4 Jan 2003 11:03:15 +0000 Subject: [PATCH] - 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. --- admin.php | 7 ++++++- database/database.mysql | 1 + database/database.pgsql | 3 ++- includes/common.inc | 4 ++-- modules/comment.module | 6 +++--- modules/comment/comment.module | 6 +++--- modules/node.module | 4 ++-- modules/node/node.module | 4 ++-- modules/user.module | 16 ++++------------ modules/user/user.module | 16 ++++------------ modules/watchdog.module | 8 ++++---- modules/watchdog/watchdog.module | 8 ++++---- update.php | 7 ++++++- 13 files changed, 43 insertions(+), 47 deletions(-) diff --git a/admin.php b/admin.php index 7531c2c750c..e90d0e482e3 100644 --- a/admin.php +++ b/admin.php @@ -62,8 +62,13 @@ function admin_page($mod) { print "$help

"; } + if ($mod) { + print module_invoke($mod, "admin"); + } + else { + print watchdog_overview("actions"); + } - module_invoke($mod, "admin"); print ""; db_query("DELETE FROM menu"); diff --git a/database/database.mysql b/database/database.mysql index abe4366013e..d84761b4bb8 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -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', diff --git a/database/database.pgsql b/database/database.pgsql index 62c7ae03d9e..7c0c04c589e 100644 --- a/database/database.pgsql +++ b/database/database.pgsql @@ -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', diff --git a/includes/common.inc b/includes/common.inc index db5bc459142..d9470bb3ca2 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -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) { diff --git a/modules/comment.module b/modules/comment.module index b4f1971ecf7..8ac83dde815 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -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"]))); } /* diff --git a/modules/comment/comment.module b/modules/comment/comment.module index b4f1971ecf7..8ac83dde815 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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"]))); } /* diff --git a/modules/node.module b/modules/node.module index 56dbd2d2e8b..f9ea17b3834 100644 --- a/modules/node.module +++ b/modules/node.module @@ -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."); } } diff --git a/modules/node/node.module b/modules/node/node.module index 56dbd2d2e8b..f9ea17b3834 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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."); } } diff --git a/modules/user.module b/modules/user.module index 1f1493385d5..a788b1dc148 100644 --- a/modules/user.module +++ b/modules/user.module @@ -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" => "$name@$server")); @@ -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"] ."' <". $edit["mail"] .">"); + watchdog("user", "new user: '". $edit["name"] ."' <". $edit["mail"] .">", 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"] ."' <". $edit["mail"] .">"); 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 && !stristr($result->serialize(), "fault")) { - // watchdog("user", "Success Blogger Auth. Response: " . $result->serialize()); return 1; } else if ($result) { - // watchdog("user", "Blogger Auth failure. Response was " . $result->serialize()); return 0; } else { - // watchdog("user", "Blogger Auth failure. Could not connect."); return 0; } } @@ -1778,15 +1774,12 @@ function user_help_devel_da() { to the user.module if your registration database has become inoperable or unreachable.

   if ($result && !stristr($result->serialize(), "fault")) {
-    // watchdog("user", "Success Blogger auth. Response was " . $result->serialize());
     return 1;
   }
   else if ($result) {
-    // watchdog("user", "Blogger auth failure.  Response was " . $result->serialize());
     return 0;
   }
   else {
-    // watchdog("user", "Blogger auth failure.  Could not connect.");
return 0; }
@@ -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.

function blogger_page() {
   global $theme;
diff --git a/modules/user/user.module b/modules/user/user.module
index 1f1493385d5..a788b1dc148 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -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" => "$name@$server"));
@@ -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"] ."' <". $edit["mail"] .">");
+    watchdog("user", "new user: '". $edit["name"] ."' <". $edit["mail"] .">", 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"] ."' <". $edit["mail"] .">");
 
     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 && !stristr($result->serialize(), "fault")) {
-    // watchdog("user", "Success Blogger Auth. Response: " .
     $result->serialize());
     return 1;
   }
   else if ($result) {
-    // watchdog("user", "Blogger Auth failure. Response was " . $result->serialize());
     return 0;
   }
   else {
-    // watchdog("user", "Blogger Auth failure. Could not connect.");
     return 0;
   }
 }
@@ -1778,15 +1774,12 @@ function user_help_devel_da() { to the user.module if your registration database has become inoperable or unreachable.

   if ($result && !stristr($result->serialize(), "fault")) {
-    // watchdog("user", "Success Blogger auth. Response was " . $result->serialize());
     return 1;
   }
   else if ($result) {
-    // watchdog("user", "Blogger auth failure.  Response was " . $result->serialize());
     return 0;
   }
   else {
-    // watchdog("user", "Blogger auth failure.  Could not connect.");
return 0; }
@@ -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.

function blogger_page() {
   global $theme;
diff --git a/modules/watchdog.module b/modules/watchdog.module
index 396351953ef..eeabdd453e1 100644
--- a/modules/watchdog.module
+++ b/modules/watchdog.module
@@ -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 .= "";
-  $output .= " ";
+  $output .= " ";
   while ($watchdog = db_fetch_object($result)) {
     if ($background = $color[$watchdog->type]) {
-      $output .= " ";
+      $output .= " ";
     }
   }
 
diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module
index 396351953ef..eeabdd453e1 100644
--- a/modules/watchdog/watchdog.module
+++ b/modules/watchdog/watchdog.module
@@ -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 .= "
" . t("date") . "" . t("message") . "" . t("user") . "" . t("operations") . "
" . t("date") . "" . t("event") . "" . t("user") . "" . t("operations") . "
". format_date($watchdog->timestamp, "small") ."". substr(strip_tags($watchdog->message), 0, 64) ."". format_name($watchdog) ."". la(t("details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."
". format_date($watchdog->timestamp, "small") ."". substr(strip_tags($watchdog->message), 0, 64) ."". format_name($watchdog) ."$watchdog->link". la(t("view details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."
"; - $output .= " "; + $output .= " "; while ($watchdog = db_fetch_object($result)) { if ($background = $color[$watchdog->type]) { - $output .= " "; + $output .= " "; } } diff --git a/update.php b/update.php index 8b5362c5def..a07f641a778 100644 --- a/update.php +++ b/update.php @@ -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)");
" . t("date") . "" . t("message") . "" . t("user") . "" . t("operations") . "
" . t("date") . "" . t("event") . "" . t("user") . "" . t("operations") . "
". format_date($watchdog->timestamp, "small") ."". substr(strip_tags($watchdog->message), 0, 64) ."". format_name($watchdog) ."". la(t("details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."
". format_date($watchdog->timestamp, "small") ."". substr(strip_tags($watchdog->message), 0, 64) ."". format_name($watchdog) ."$watchdog->link". la(t("view details"), array("mod" => "watchdog", "op" => "view", "id" => $watchdog->wid)) ."