#!/usr/bin/perl #----------------------------------------------------------------------------- # # convoy # # http://www.remote.org/jochen/software/convoy/ # #----------------------------------------------------------------------------- # # 2003-11-19 version 0.1 # #----------------------------------------------------------------------------- # # Copyright (C) 2003 Jochen Topf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA # #----------------------------------------------------------------------------- use strict; use Tk; use IO::File; my $SIZEFACTOR = 4; my $OFFSET = 10; my $SCROLLFACTOR = 4; my $MAXX = 640; my $MAXY = 400; my $REPEATINT = 400; my $TIMEINTERVAL = 10*60; #----------------------------------------------------------------------------- # GUI stuff #----------------------------------------------------------------------------- my $main = MainWindow->new(); my $menu = $main->Frame(-borderwidth => 1, -relief => 'raised'); $menu->pack(-side => 'top', -fill => 'x', -expand => 0); my $m_file = $menu->Menubutton(-text => 'File', -tearoff => 0); $m_file->pack(-side => 'left', -padx => 2); #my $m_edit = $menu->Menubutton(-text => 'Edit', -tearoff => 0); #$m_edit->pack(-side => 'left', -padx => 2); $m_file->command(-label => 'Quit', -command => sub { end(); }); $main->Tk::bind('all', '', sub { end(); }); my $canvas = $main->Canvas( -width => $MAXX, -height => $MAXY, -background => '#000000' ); $canvas->pack(); $main->repeat($REPEATINT, sub { rep_callback() }); Watch::File->new('/var/log/uucp/Log'); MainLoop(); exit(0); #----------------------------------------------------------------------------- # sub end { exit(0); } #----------------------------------------------------------------------------- my @rects = (); sub print_line { my ($length, $color) = @_; my $rect = $canvas->createRectangle($OFFSET, $MAXY-$OFFSET, $OFFSET+$length*$SIZEFACTOR, $MAXY-$OFFSET-$SIZEFACTOR, -fill => $color); push(@rects, $rect); } sub scroll { foreach my $rect (@rects) { $canvas->move($rect, 0, -$SCROLLFACTOR); } if ($#rects > $MAXY/$SCROLLFACTOR) { my $rect = shift(@rects); $canvas->delete($rect); } } sub rep_callback { Watch::doall(); } #----------------------------------------------------------------------------- package Watch; use vars qw(@watchlist); @watchlist = (); sub add { my ($self) = @_; push(@watchlist, $self); } my $lasttime=0; sub doall { if (time()-$lasttime > $TIMEINTERVAL) { $lasttime = time(); main::scroll(); } foreach my $item (@watchlist) { $item->doit(); } } #----------------------------------------------------------------------------- package Watch::File; use base 'Watch'; sub new { my ($class, $name) = @_; my $fh = IO::File->new($name, 'r'); my $self = { name => $name , fh => $fh }; bless($self, $class); $self->add(); $fh->seek(0, 2); # end of file return $self; } sub doit { my ($self) = @_; my $fh = $self->{'fh'}; $fh->seek(0, 1); # seek to current position while (! $fh->eof()) { $_ = $fh->getline(); if (/Calling system/) { main::print_line(6, '#808080'); } elsif (/Login successful/) { main::print_line(8, '#a0a0a0'); } elsif (/Handshake successful/) { main::print_line(10, '#c0c0c0'); } elsif (/Call complete/) { main::print_line(6, '#404040'); } elsif (/Sending rmail .* \(([0-9]+) bytes\)/) { main::print_line(calc_len($1), '#00ff00'); } elsif (/Receiving rmail .* \(([0-9]+) bytes\)/) { main::print_line(calc_len($1), '#ffff00'); } elsif (/Queuing rmail/) { main::print_line(4, '#008000'); } elsif (/Executing/) { main::print_line(4, '#808000'); } elsif (/ERROR/) { main::print_line(10, '#ff0000'); } else { main::print_line(10, '#ffffff'); } main::scroll(); $lasttime = time(); } } sub calc_len { my ($bytes) = @_; my $len = int($bytes/2000)+1; return $len > 200 ? 200 : $len; } #-- THE END ------------------------------------------------------------------