More work on log search and annotation
authorJamie Cameron <jcameron@webmin.com>
Wed, 14 Nov 2007 06:13:45 +0000 (06:13 +0000)
committerJamie Cameron <jcameron@webmin.com>
Wed, 14 Nov 2007 06:13:45 +0000 (06:13 +0000)
blue-theme/lang/en
blue-theme/left.cgi
webminlog/CHANGELOG
webminlog/images/star.gif [new file with mode: 0755]
webminlog/index.cgi
webminlog/lang/en
webminlog/rollback.cgi
webminlog/search.cgi
webminlog/view.cgi
webminlog/webminlog-lib.pl

index d4e8208..61142de 100644 (file)
@@ -5,7 +5,7 @@ left_feedback=Send Feedback
 left_search_webmin=Search Webmin:
 left_search_usermin=Search Usermin:
 left_search=Search:
-left_logs=View Webmin logs
+left_logs=View Module's Logs
 
 right_header0=System Information
 right_host=System hostname
index 653067e..4d8ccc1 100755 (executable)
@@ -49,7 +49,7 @@ function show_logs() {
     }
   }
 if (mod) {
-  window.parent.frames[1].location = 'webminlog/search.cgi?tall=4&uall=1&fall=1&module='+mod;
+  window.parent.frames[1].location = 'webminlog/search.cgi?tall=4&uall=1&fall=1&mall=0&module='+mod;
   }
 else {
   alert('No Webmin module is selected to show logs for');
index 4b597f5..8324d17 100644 (file)
@@ -13,3 +13,6 @@ When rolling back changed files, you can now select which ones to revert rather
 A description of the search is now shown for searches that didn't match anything.
 ---- Changes since 1.350 ----
 Rollback actions can themselves now be rolled back.
+---- Changes since 1.380 ----
+Re-designed the UI to use Webmin standard layout and functions.
+Added a field for searching based on the contents of commands run or file changes made.
diff --git a/webminlog/images/star.gif b/webminlog/images/star.gif
new file mode 100755 (executable)
index 0000000..3da7e41
Binary files /dev/null and b/webminlog/images/star.gif differ
index fc3b87d..aed4df0 100755 (executable)
@@ -61,13 +61,19 @@ print &ui_table_row($text{'index_stimes'},
                          [ 0, &text('index_time', &time_input('from'),
                                                   &time_input('to')) ] ]));
 
-# Search modified files
+# Search modified files and diff contents
 if ($gconfig{'logfiles'}) {
        print &ui_table_row($text{'index_sfile'},
                &ui_radio("fall", 1,
                          [ [ 1, $text{'index_fall'}."<br>" ],
                            [ 0, $text{'index_file'}." ".
                                 &ui_textbox("file", undef, 40) ] ]));
+
+       print &ui_table_row($text{'index_sdiff'},
+               &ui_radio("dall", 1,
+                         [ [ 1, $text{'index_dall'}."<br>" ],
+                           [ 0, $text{'index_diff'}." ".
+                                &ui_textbox("diff", undef, 40) ] ]));
        }
 
 # Remote host
index 788ffa4..e5057c9 100644 (file)
@@ -21,6 +21,9 @@ index_whost=From server
 index_susers=Actions by Webmin users
 index_smods=Actions in module
 index_sfile=Actions that modified file
+index_sdiff=File change or command run
+index_dall=Any change
+index_diff=Changes containing
 index_stimes=Actions on dates
 index_shost=Source Webmin server
 
@@ -73,6 +76,7 @@ view_ecannot=You are not allowed to view this log entry
 view_rollback2=Roll Back Selected Files
 view_return=action details
 view_input=Input to command
+view_anno=Log entry annotation
 
 acl_mods=Can view logs in modules
 acl_all=All
index 1ef2c92..9b36fde 100755 (executable)
@@ -4,8 +4,15 @@
 
 require './webminlog-lib.pl';
 &ReadParse();
-
 $act = &get_action($in{'id'});
+
+if ($in{'annosave'}) {
+       # Just saving an annotation
+       $in{'anno'} =~ s/\r//g;
+       &save_annotation($act, $in{'anno'});
+       &redirect($ENV{'HTTP_REFERER'} || "view.cgi?id=$in{'id'}");
+       }
+
 $access{'rollback'} ||  &error($text{'rollback_ecannot'});
 &can_user($act->{'user'}) || &error($text{'view_ecannot'});
 &can_mod($act->{'module'}) || &error($text{'view_ecannot'});
index 5ac0fad..914b177 100755 (executable)
@@ -7,6 +7,13 @@ require 'timelocal.pl';
 &ReadParse();
 &error_setup($text{'search_err'});
 
+# Use sensible defaults
+$in{'tall'} = 2 if (!defined($in{'tall'}));
+$in{'uall'} = 1 if (!defined($in{'uall'}));
+$in{'mall'} = 1 if (!defined($in{'mall'}));
+$in{'fall'} = 1 if (!defined($in{'fall'}));
+$in{'dall'} = 1 if (!defined($in{'dall'}));
+
 # Parse entered time ranges
 if ($in{'tall'} == 2) {
        # Today
@@ -58,12 +65,16 @@ while(($id, $idx) = each %index) {
                next if (!$in{'wall'} && $in{'webmin'} ne $act->{'webmin'});
 
                # Check modified files
-               if ($gconfig{'logfiles'} && !$in{'fall'}) {
+               if ($gconfig{'logfiles'} && (!$in{'fall'} || !$in{'dall'})) {
                        # Make sure the specified file was modified
                        local $found = 0;
                        foreach $d (&list_diffs($act)) {
-                               if ($d->{'object'} &&
-                                   $d->{'object'} eq $in{'file'}) {
+                               local $filematch = $in{'fall'} ||
+                                       $d->{'object'} &&
+                                       $d->{'object'} eq $in{'file'};
+                               local $diffmatch = $in{'dall'} ||
+                                       $d->{'diff'} =~ /\Q$in{'diff'}\E/i;
+                               if ($filematch && $diffmatch) {
                                        $found++;
                                        last;
                                        }
@@ -136,10 +147,14 @@ if (@match) {
 
                local @cols;
                local $desc = &get_action_description($act, 0);
+               local $anno = &get_annotation($act);
                push(@cols, "<a href='view.cgi?id=$act->{'id'}".
                      "&return=".&urlize($in{'return'}).
                      "&returndesc=".&urlize($in{'returndesc'}).
                      "'>$desc</a>");
+               if ($anno) {
+                       $cols[$#cols] .= "&nbsp;<img src=images/star.gif>";
+                       }
                push(@cols, $minfo->{'desc'}, $act->{'user'}, $act->{'ip'});
                if ($config{'host_search'}) {
                        push(@cols, $act->{'webmin'});
index 7c11060..55e3da6 100755 (executable)
@@ -14,13 +14,11 @@ $act = &get_action($in{'id'});
 &ui_print_header(undef, $text{'view_title'}, "");
 
 @files = &list_files($act);
-if (@files) {
-       print &ui_form_start("rollback.cgi");
-       print &ui_hidden("id", $in{'id'});
-       }
+print &ui_form_start("rollback.cgi");
+print &ui_hidden("id", $in{'id'});
 
-print &ui_table_start(&text('view_header', $act->{'id'}),
-                     "width=100%", 4);
+print &ui_hidden_table_start(&text('view_header', $act->{'id'}),
+                            "width=100%", 4, "main", 1);
 
 # This "" is needed to make the label show properly!
 print &ui_table_row($text{'view_action'}."",
@@ -54,11 +52,21 @@ if ($act->{'webmin'}) {
        print &ui_table_row($text{'view_host'},
                            $act->{'webmin'});
        }
-
-print &ui_table_end(),"<p>\n";
+print &ui_hidden_table_end("main"),"<p>\n";
+
+# Annotations for this log entry
+$text = &get_annotation($act);
+print &ui_hidden_table_start($text{'view_anno'}, "width=100%", 1, "anno",
+                            $text ? 1 : 0);
+print &ui_table_row(undef,
+       &ui_textarea("anno", $text, 10, 80, "auto", 0,
+                    "style='width:100%'")."<br>".
+       &ui_submit($text{'save'}, "annosave"));
+print &ui_hidden_table_end("anno"),"<p>\n";
 
 # display modified files
 $rbcount = 0;
+$i = 0;
 foreach $d (&list_diffs($act)) {
        local $t = $text{"view_type_".$d->{'type'}};
        local $rb;
@@ -71,18 +79,18 @@ foreach $d (&list_diffs($act)) {
        $rbcount++ if ($rb);
        if ($t =~ /\$2/ || !$d->{'diff'}) {
                # Diff is just a single line message
-               print &ui_table_start($cbox.
+               print &ui_hidden_table_start($cbox.
                      &text("view_type_".$d->{'type'},
                            "<tt>$d->{'object'}</tt>",
                            "<tt>".&html_escape($d->{'diff'})."</tt>"),
-                     "width=100%", 2);
-               print &ui_table_end();
+                     "width=100%", 2, "diff$i", 1);
                }
        else {
                # Show multi-line diff
-               print &ui_table_start($cbox.&text("view_type_".$d->{'type'},
-                                                 "<tt>$d->{'object'}</tt>"),
-                                     "width=100%", 2);
+               print &ui_hidden_table_start(
+                       $cbox.&text("view_type_".$d->{'type'},
+                                   "<tt>$d->{'object'}</tt>"),
+                       "width=100%", 2, "diff$i", 1);
                print &ui_table_row(undef,
                        "<pre>".&html_escape($d->{'diff'})."</pre>", 2);
                if ($d->{'input'}) {
@@ -91,8 +99,9 @@ foreach $d (&list_diffs($act)) {
                                "<b>".&text('view_input')."</b><br>".
                                "<pre>".&html_escape($d->{'input'})."</pre>",2);
                        }
-               print &ui_table_end();
                }
+       print &ui_hidden_table_end("diff$i");
+       $i++;
        $anydiffs++;
        }
 if ($rbcount) {
@@ -106,6 +115,9 @@ print "<b>$text{'view_nofiles'}</b><p>\n" if (!$anydiffs);
 if (@files && $rbcount) {
        print &ui_form_end([ [ "rollback", $text{'view_rollback2'} ] ]);
        }
+else {
+       print &ui_form_end();
+       }
 
 &ui_print_footer($ENV{'HTTP_REFERER'}, $text{'search_return'},
        "", $text{'index_return'});
index 69f948a..cd187d5 100644 (file)
@@ -114,6 +114,32 @@ foreach my $file (@files) {
 return @rv;
 }
 
+# get_annotation(&action)
+# Returns the text of the log annotation for this action
+sub get_annotation
+{
+local ($act) = @_;
+return &read_file_contents("$ENV{'WEBMIN_VAR'}/annotations/$act->{'id'}");
+}
+
+# save_annotation(&action, text)
+# Updates the annotation for some action
+sub save_annotation
+{
+local ($act, $text) = @_;
+local $dir = "$ENV{'WEBMIN_VAR'}/annotations";
+local $file = "$dir/$act->{'id'}";
+if ($text eq '') {
+       unlink($file);
+       }
+else {
+       &make_dir($dir, 0700) if (!-d $dir);
+       &open_tempfile(ANNO, ">$file");
+       &print_tempfile(ANNO, $text);
+       &close_tempfile(ANNO);
+       }
+}
+
 # expand_base_dir(base)
 # Finds files either under some dir, or starting with some path
 sub expand_base_dir