summaryrefslogtreecommitdiffstats
path: root/logdrake
diff options
context:
space:
mode:
Diffstat (limited to 'logdrake')
-rwxr-xr-xlogdrake388
1 files changed, 181 insertions, 207 deletions
diff --git a/logdrake b/logdrake
index eb373bef..031b38e1 100755
--- a/logdrake
+++ b/logdrake
@@ -1,4 +1,4 @@
-#! /usr/bin/perl -w
+#! /usr/bin/perl
# $Id$
# Copyright (C) 2001 MandrakeSoft
@@ -18,15 +18,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
use lib qw(/usr/lib/libDrakX);
use interactive;
use standalone;
use common qw(:common :file :functional :system);
use any;
-#use log;
-#use c;
use Gtk;
use Config;
@@ -42,13 +39,13 @@ if ($::isEmbedded) {
print "mcc pid\t$::CCPID\n";
}
+my $in = vnew interactive('su');
+
local $_ = join '', @ARGV;
/-h/ and die "usage: logdrake [--version]\n";
/-version/ and die 'version: $Id$ '."\n";
-$expert_mode = 0;
-
my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel;
$window->signal_connect( delete_event => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) });
$window->set_title( _("logdrake") );
@@ -88,38 +85,64 @@ my $menubar = get_main_menu( $window );
########## font and colors
-my $fixed_font = Gtk::Gdk::Font->load("-misc-Fixed-Medium-r-*-*-*-140-*-*-*-*-*-*,*");
+my $n = Gtk::Gdk::Font->load("-misc-fixed-medium-r-*-*-*-100-*-*-*-*-*-*");
+my $b = Gtk::Gdk::Font->load("-misc-fixed-bold-r-*-*-*-100-*-*-*-*-*-*");
+
# Get the system color map and allocate the color red
my $cmap = Gtk::Gdk::Colormap->get_system();
-my $color;
-$color->{red} = 0xFFFF;
-$color->{green} = 0;
-$color->{blue} = 0;
-warn _("Couldn't allocate color\n")
- unless (defined($cmap->color_alloc($color)));
+my $white = { red => 0xFFFF, green => 0xFFFF, blue =>0xFFFF};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($white)));
+my $black = { red => 0, green => 0, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($black)));
+my $red = { red => 0xFFFF, green => 0, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($red)));
+my $green = { red => 0xF, green => 0xFFF, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($green)));
+my $yellow = { red => 0xF, green => 0, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($yellow)));
+my $blue = { red => 0, green => 0, blue =>0xFFFF};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($blue)));
+my $magenta = { red => 0xF, green => 0, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($magenta)));
+my $purple = { red => 0xF, green => 0, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($purple)));
+my $cyan = { red => 0, green => 0xFFF, blue =>0xFFF};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($cyan)));
+my $darkgray = { red => 0xFFF, green => 0x, blue =>0};warn _("Couldn't allocate color\n") unless (defined($cmap->color_alloc($darkgray)));
+
######### font and colors end
my $global_vbox = new Gtk::VBox();
$::isEmbedded or $global_vbox->pack_start (new Gtk::Label(_("see your log")), 0, 0, 0);
+
+
#### far from window
+### the tree
+
+# Create a ScrolledWindow for the tree
+my $tree_scrolled_win = new Gtk::ScrolledWindow();
+$tree_scrolled_win->set_usize(300, $::isEmbedded ? 0 : 175);
+$global_vbox->pack_start( $tree_scrolled_win,0,0,0 );
+$tree_scrolled_win->set_policy('automatic', 'automatic');
+
+# Create root tree
+my $tree = new Gtk::Tree();
+my $leaf;
+my $root_dir;
+$tree_scrolled_win->add_with_viewport($tree);
+$tree->set_selection_mode('single');
+$tree->set_view_mode('item');
+
+fill_tree ("");
+
my $log_frame = new Gtk::Frame( _("log") );
-my $log = new Gtk::Text( undef, undef );
+my $log = new Gtk::Text(undef, undef);
my $vscrollbar = new Gtk::VScrollbar( $log->vadj );
my $log_hbox = new Gtk::HBox (0, 0);
$log_hbox->border_width (5);
-$log_hbox->set_usize( 30, 75 );
+$log_hbox->set_usize(300, 275);
$log_hbox->pack_start($log, 1, 1, 0);
$log_hbox->pack_start($vscrollbar, 0, 0, 0 );
$log_frame->add ($log_hbox);
$global_vbox->pack_start ($log_frame, 0, 0, 0);
-
-
+# $text->insert( $font, $foreground, $background, $string );
### back to window
-$window->add( $global_vbox );
+$window->add($global_vbox);
$window->show_all();
Gtk->main_iteration while Gtk->events_pending;
@@ -134,8 +157,7 @@ Gtk->main;
### Subroutines
sub fill_tree {
- ($root_dir) = @_;
- $root_dir = "/lib/modules/" . $root_dir;
+ my $root_dir = "/var/log/" . $_[0];
# Create root tree item widget
$leaf = new_with_label Gtk::TreeItem( $root_dir );
$tree->append( $leaf );
@@ -143,7 +165,7 @@ sub fill_tree {
$leaf->set_user_data( $root_dir );
# Create the subtree
- if ( has_sub_trees( $root_dir ) ) {
+ if (-d $root_dir) {
my $subtree = new Gtk::Tree();
$leaf->set_subtree( $subtree );
$leaf->signal_connect( 'expand', \&expand_tree, $subtree );
@@ -159,21 +181,13 @@ sub change_tree {
}
# Callback for expanding a tree - find subdirectories, files and add them to tree
-sub expand_tree
- {
- my ( $item, $subtree ) = @_;
-
- my $dir_entry;
- my $path;
- my $item_new;
- my $new_subtree;
-
+sub expand_tree {
+ my ($item, $subtree) = @_;
+ my ($dir_entry, $path, $item_new, $new_subtree);
my $dir = $item->get_user_data();
- chdir( $dir );
-
+ chdir($dir);
foreach $dir_entry ( <*> ) {
- if (( -d $dir_entry ) or ( $dir_entry =~ /\.o(\.gz)?$/)) {
$path = $dir . "/" . $dir_entry;
$path =~ s|//|/|g;
$item_new = new_with_label Gtk::TreeItem( $dir_entry );
@@ -182,59 +196,155 @@ sub expand_tree
$subtree->append($item_new);
$item_new->show();
- if ( has_sub_trees( $path ) ) {
+ if (-d $path) {
$new_subtree = new Gtk::Tree();
$item_new->set_subtree( $new_subtree );
$item_new->signal_connect('expand', \&expand_tree, $new_subtree);
$item_new->signal_connect('collapse', \&collapse_tree);
}
- }
}
chdir( ".." );
- }
+}
# Callback for collapsing a tree -- removes the subtree
-sub collapse_tree
- {
- my ( $item ) = @_;
+sub collapse_tree {
+ my ($item) = @_;
my $subtree = new Gtk::Tree();
-
+
$item->remove_subtree();
$item->set_subtree( $subtree );
$item->signal_connect( 'expand', \&expand_tree, $subtree );
+}
+
+# Called whenever an item is clicked on the tree widget.
+sub select_item {
+ my ( $widget, $file ) = @_;
+ return if (-d $file);
+ $log->backward_delete($log->get_length());
+ $file =~ s/\.gz$//;
+ $log->freeze();
+
+ foreach (catMaybeCompressed ($file)){
+ logcolorize($_);
}
+ $log->thaw();
+}
-# Test whether a directory has subdirectories
-sub has_sub_trees
- {
- my ( $dir ) = @_;
- my $file;
+sub log_output {
+ $log->insert($_[2],$_[0], undef,$_[1]);
+}
- foreach $file ( <$dir/*> ) {
- return 1 if ( -d $file ) or ($file =~ /\.o(\.gz)?$/);
+##########################################################################################
+sub logcolorize {
+
+ my ($thisline)=@_;
+
+ # logcolorize.pl 1.0.8 - A PERL script to colorize log viewing
+ # distributed under the GPL
+ # Copyright: (C) 1999, Michael T. Babcock
+ # <mikebabcock@pobox.com>
+ # http://www.linuxsupportline.com/~pgp/linux/
+ #
+
+ # Define global terms:
+ # Define good notables:
+ my @word_good=("starting\n", "Freeing", "Detected", "starting.", "accepted.\n", "authenticated.\n", "Ready", "active", "reloading", "saved;", "restarting", "ONLINE\n");
+ my @word_warn=("dangling", "closed.\n", "Assuming", "root", "root\n", "exiting\n", "missing", "Ignored", "adminalert:", "deleting", "OFFLINE\n");
+ my @word_bad=("bad");
+my @word_note=("LOGIN", "DHCP_OFFER", "optimized", "reset:", "unloaded", "disconnected", "connect", "Successful", "registered\n");
+ my @line_good=("up", "DHCP_ACK", "Cleaned", "Initializing", "Starting", "success", "successfully", "alive", "found", "ONLINE\n");
+ my @line_warn=("warning:", "WARNING:", "invalid", "obsolete", "bad", "Password", "detected", "timeout", "timeout:", "attackalert:", "wrong", "Lame", "FAILED", "failing", "unknown", "obsolete", "stopped.\n", "terminating.", "disabled\n", "disabled", "Lost");
+ my @line_bad=("DENY", "lost", "shutting", "dead", "DHCP_NAK", "failure;", "Unable", "inactive", "terminating", "refused", "rejected", "down", "OFFLINE\n", "error\n", "ERROR\n", "ERROR:", "error", "ERROR", "error:", "failed:");
+
+ # Define specifics:
+ my @daemons=("named");
+
+ # Now define what we want to use when:
+ my $col_good = $green;
+ my $col_warn = $yellow;
+ my $col_bad = $red;
+ my $col_note = $purple;
+ my $col=$cyan;
+
+ my $col_norm = "\033[00m";
+ my $col_background = "\033[07m";
+ my $col_brighten = "\033[01m";
+ my $col_underline = "\033[04m";
+ my $col_blink = "\033[05m";
+
+ # Resets to normal colours and moves to the left one column ...
+ my $col_default = "$col_norm$white";
+ my $datespace=0;
+ s/(.{16})//;
+ $timestamp=$1;
+
+ @rec = split;# (/ /, $_);
+
+ log_output($cyan,$timestamp,$b); # date & time
+ log_output($blue,"$rec[0] ",$b); # hostname
+ if ($rec[1] eq "last") {
+ log_output($green," last message repeated ",$n);
+ log_output($green, $rec[4], $b);
+ log_output($green," times\n",$n);
+ return;
+ }
+ # Extract PID if present
+ if ($rec[1] =~ /\[(\d+)\]\:/) {
+ my($pid) = $1;
+ $rec[1]=~s/\[$1\]\:// ;
+ log_output ($green, $rec[1] ."[",$n);
+ log_output ($black, $pid,$b);
+ log_output ($green, "]: ",$n);
+ }
+ else {
+ log_output($green, $rec[1] ." ",$n);
}
- return (0);
- }
+
+ for ($therest=(2); $therest<=$#rec; $therest++) {
-# Called whenever an item is clicked on the tree widget.
-sub select_item {
- my ( $widget, $file ) = @_;
- return if (-d $file);
- my $size = ( lstat( $file ) )[ 7 ];
- my $lr = $list->rows();
- my $i;
- $file =~ s|/lib/modules/.*?/||g;
- for ($i=0; $i < $lr; $i++) {
- last if ($file eq $list->get_text($i, 0));
- }
- print $file,"\n";
-
- $list->append($file, $size) if ($i == $lr) or ($lr == 0);
+ # Check for keywords to highlight
+ for ($i=0; $i<=$#word_good; $i++) {
+ $col=$col_good if ($word_good[$i] eq $rec[$therest]);
+ }
+ for ($i=0; $i<=$#word_warn; $i++) {
+ $col=$col_warn if ($word_warn[$i] eq $rec[$therest]);
+ }
+ for ($i=0; $i<=$#word_bad; $i++) {
+ $col=$col_bad if ($word_bad[$i] eq $rec[$therest]);
+ }
+ for ($i=0; $i<=$#word_note; $i++) {
+ $col=$col_note if ($word_note[$i] eq $rec[$therest]);
+ }
+
+# # Watch for words that indicate entire lines should be highlighted
+# for ($i=0; $i<=$#line_good; $i++) {
+# if ($line_good[$i] eq $rec[$therest]) {
+# $restcolor="$col_norm$col_good";
+# $restoftheline.="$col_brighten$col_good"; $highlight=1;
+# }
+# }
+# for ($i=0; $i<=$#line_warn; $i++) {
+# if ($line_warn[$i] eq $rec[$therest]) {
+# $restcolor="$col_norm$col_warn";
+# $restoftheline.="$col_brighten$col_warn"; $highlight=1;
+# }
+# }
+# for ($i=0; $i<=$#line_bad; $i++) {
+# if ($line_bad[$i] eq $rec[$therest]) {
+# $restcolor="$col_norm$col_bad";
+# $restoftheline.="$col_brighten$col_bad"; $highlight=1;
+# }
+# }
+
+ log_output($col,"$rec[$therest] ",$n);
+ }
+ log_output($black,"\n",$n);
}
+
#-------------------------------------------------------------
# menu callback functions
#-------------------------------------------------------------
@@ -244,7 +354,7 @@ sub print_hello {
}
sub get_main_menu {
- my ( $window ) = @_;
+ my ($window) = @_;
my $accel_group = new Gtk::AccelGroup();
my $item_factory = new Gtk::ItemFactory( 'Gtk::MenuBar', '<main>', $accel_group );
@@ -253,24 +363,23 @@ sub get_main_menu {
return ( $item_factory->get_widget( '<main>' ) );
}
-
sub create_dialog {
- my ( $label, $c ) = @_;
+ my ($label, $c) = @_;
my $ret = 0;
my $dialog = new Gtk::Dialog;
$dialog->signal_connect ( delete_event => sub {Gtk->main_quit();});
- $dialog->set_title(I_("drakfloppy"));
+ $dialog->set_title(_("logdrake"));
$dialog->border_width(10);
$dialog->vbox->pack_start(new Gtk::Label($label),1,1,0);
- my $button = new Gtk::Button I_("OK");
+ my $button = new Gtk::Button _("OK");
$button->can_default(1);
$button->signal_connect(clicked => sub { $ret = 1; $dialog->destroy(); Gtk->main_quit(); });
$dialog->action_area->pack_start($button, 1, 1, 0);
$button->grab_default;
if ($c) {
- my $button2 = new Gtk::Button I_("Cancel");
+ my $button2 = new Gtk::Button _("Cancel");
$button2->signal_connect(clicked => sub { $ret = 0; $dialog->destroy(); Gtk->main_quit(); });
$button2->can_default(1);
$dialog->action_area->pack_start($button2, 1, 1, 0);
@@ -289,148 +398,13 @@ sub destroy_window {
}
-##########################################################################################
-sub logcolorize {
-
-# logcolorize.pl 1.0.8 - A PERL script to colorize log viewing
-# distributed under the GPL
-# Copyright: (C) 1999, Michael T. Babcock
-# <mikebabcock@pobox.com>
-# http://www.linuxsupportline.com/~pgp/linux/
-#
-$black = "\033[30m";
-$red = "\033[31m";
-$green = "\033[32m";
-$yellow = "\033[33m";
-$blue = "\033[34m";
-$magenta = "\033[35m";
-$purple = "\033[35m";
-$cyan = "\033[36m";
-$white = "\033[37m";
-$darkgray = "\033[30m";
-
-# Define global terms:
-# Define good notables:
-@word_good=("starting\n", "Freeing", "Detected", "starting.", "accepted.\n", "authenticated.\n", "Ready", "active", "reloading", "saved;", "restarting", "ONLINE\n");
-@word_warn=("dangling", "closed.\n", "Assuming", "root", "root\n", "exiting\n", "missing", "Ignored", "adminalert:", "deleting", "OFFLINE\n");
-@word_bad=("bad");
-@word_note=("LOGIN", "DHCP_OFFER", "optimized", "reset:", "unloaded", "disconnected", "connect", "Successful", "registered\n");
-@line_good=("up", "DHCP_ACK", "Cleaned", "Initializing", "Starting", "success", "successfully", "alive", "found", "ONLINE\n");
-@line_warn=("warning:", "WARNING:", "invalid", "obsolete", "bad", "Password", "detected", "timeout", "timeout:", "attackalert:", "wrong", "Lame", "FAILED", "failing", "unknown", "obsolete", "stopped.\n", "terminating.", "disabled\n", "disabled", "Lost");
-@line_bad=("DENY", "lost", "shutting", "dead", "DHCP_NAK", "failure;", "Unable", "inactive", "terminating", "refused", "rejected", "down", "OFFLINE\n", "error\n", "ERROR\n", "ERROR:", "error", "ERROR", "error:", "failed:");
-
-# Define specifics:
-@daemons=("named");
-
-# Now define what we want to use when:
-$col_good = $green;
-$col_warn = $yellow;
-$col_bad = $red;
-$col_note = $purple;
-
-$col_norm = "\033[00m";
-$col_background = "\033[07m";
-$col_brighten = "\033[01m";
-$col_underline = "\033[04m";
-$col_blink = "\033[05m";
-
-# Resets to normal colours and moves to the left one column ...
-$col_default = "$col_norm$white";
-print "\n$col_norm$cyan";
-print "logcolorize.pl 1.0.8 by$col_brighten$cyan Michael T. Babcock$col_norm$cyan <$col_brighten$green";
-print "mikebabcock\@pobox.com$col_norm$cyan";
-print ">\n";
-
-$datespace=0;
-
-mainloop: while (<>)
-{
- $thisline = $_;
-
- $timestamp = substr($_,0,15);
- s/................//;
-
- @rec = split (/ /, $_);
-
- $output="$col_brighten$cyan$timestamp"; # date & time
- $output.=" $col_brighten$blue$rec[0]"; # hostname
- if ($rec[1] eq "last")
- {
- $output.="$col_norm$green last message repeated ";
- $output.="$col_brighten$rec[4]$col_norm$green times\n";
- print "$output$col_default";
- next mainloop;
- }
- # Extract PID if present
- if ($rec[1] =~ /\[(\d+)\]\:/)
- {
- my($pid) = $1;
- $rec[1]=~s/\[$1\]\:// ;
- $output .= "$col_norm$green $rec[1]" .
- "$col_brighten$green\[";
- $output .= "$col_brighten$white$pid" .
- "$col_brighten$green\]: ";
- }
- else {
- $output .= "$col_norm$green $rec[1] ";
- }
-
- $restcolor="$col_norm$cyan";
- $restoftheline="";
- for ($therest=(2); $therest<=$#rec; $therest++)
- { $highlight=0;
-
- # Check for keywords to highlight
-
- for ($i=0; $i<=$#word_good; $i++)
- { if ($word_good[$i] eq $rec[$therest])
- { $restoftheline.="$col_brighten$col_good"; $highlight=1; }
- }
- for ($i=0; $i<=$#word_warn; $i++)
- { if ($word_warn[$i] eq $rec[$therest])
- { $restoftheline.="$col_brighten$col_warn"; $highlight=1; }
- }
- for ($i=0; $i<=$#word_bad; $i++)
- { if ($word_bad[$i] eq $rec[$therest])
- { $restoftheline.="$col_brighten$col_bad"; $highlight=1; }
- }
- for ($i=0; $i<=$#word_note; $i++)
- { if ($word_note[$i] eq $rec[$therest])
- { $restoftheline.="$col_brighten$col_note"; $highlight=1; }
- }
-
- # Watch for words that indicate entire lines should be highlighted
-
- for ($i=0; $i<=$#line_good; $i++)
- { if ($line_good[$i] eq $rec[$therest])
- { $restcolor="$col_norm$col_good";
- $restoftheline.="$col_brighten$col_good"; $highlight=1; }
- }
- for ($i=0; $i<=$#line_warn; $i++)
- { if ($line_warn[$i] eq $rec[$therest])
- { $restcolor="$col_norm$col_warn";
- $restoftheline.="$col_brighten$col_warn"; $highlight=1; }
- }
- for ($i=0; $i<=$#line_bad; $i++)
- { if ($line_bad[$i] eq $rec[$therest])
- { $restcolor="$col_norm$col_bad";
- $restoftheline.="$col_brighten$col_bad"; $highlight=1; }
- }
-
- $restoftheline.="$rec[$therest] ";
- if ($highlight == 1)
- { $restoftheline.=$restcolor; }
- }
- $output.="$restcolor$restoftheline";
- print "$output$col_default\033[1G";
-}
-
-#exit(0);
-}
# log
# $Log$
+# Revision 1.2 2001/06/28 10:50:27 yduret
+# full support of color
+#
# Revision 1.1 2001/06/27 09:22:59 yduret
# added it..
#