#!/usr/bin/perl -w # rcheck $version = "0.0.4"; # # Copyright RealizationSystems, Inc., 2002 # # This program is a status checker for the RealizationEngine. It polls # one or more accounts for one or more RealizationEngines and reports # the status of those accounts. # # RealizationEngine is the trademark of Realization Systems, Inc. # # 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 Tk; use Digest::MD5 qw(md5_hex); use LWP::Simple qw(get); $datafile = ".rcheck2"; $font_size = 10; # font size for buttons. This is a problem when you move # the script over to Windows and the fonts are HUGE! open (DATA, "$datafile"); while () { next if /^#/; next if /^$/; chomp(); (@info) = split(/\t/, $_); $name = $info[0]; $url{$name} = $info[1]; $username{$name} = $info[2]; $md5pass{$name} = $info[3]; } close(DATA); my $mw = MainWindow->new; $mw->title("RCheck - v$version"); &create_buttons(); $update_button->invoke(); Tk::After->new($mw,900000,'repeat',\&update_buttons); MainLoop; sub create_buttons { foreach $name (sort keys (%url)) { $output = "$name: ?"; $button{$name} = $mw->Button(-text => "$output", -justify => "left", -relief => "flat", -command => [ \&launch, $name ], -height => 0, -padx => 0, -pady => 0, -font => "{sans-serif} $font_size {normal}", -foreground => "black", )->pack(-side=>'top', -fill=>'x'); # $button{$name}->bind("", sub { account_maintenance(); } ); $button{$name}->update; } my $setup_button; $setup_button = $mw->Button(-text => "setup", -command => sub {setup_window()}, -font => "{sans-serif} $font_size {normal}", )->pack(-side => "bottom"); $mw->Button(-text => "Quit", -command => sub {exit}, -font => "{sans-serif} $font_size {normal}", )->pack(-side => "bottom"); $update_button = $mw->Button(-text => "update", -command => sub {update_buttons()}, -font => "{sans-serif} $font_size {normal}", )->pack(-side => "bottom"); $mw->update; } sub update_buttons { $total = 0 unless defined($total); $mw->title("*($total)RCheck"); foreach $name (sort keys (%url)) { $button{$name}->configure(-relief => "groove", -font => "{} $font_size {bold}", ); $button{$name}->update; $results = get("http://$url{$name}/cgi-bin/re_status.cgi?status=$username{$name}"); $length = length($results); $short_digest = substr($md5pass{$name}, 0, $length); $results = ($results ^ $short_digest); @results = split(/:/, $results); $output = "$name: $results[2]"; $old_results{$name} = 0 unless defined($old_results{$name}); $old_total{$name} = 0 unless defined($old_total{$name}); $total -= $old_results{$name}; # delete the old results even if results # are 0 if ($results[2] > 0) { $foregroundcolor = "red"; $fontweight = "bold"; $total += $results[2]; $relief = "flat"; $mw->bell if $results[0] != $old_total{$name}; if ($results[0] > $old_total{$name}) { $mw->deiconify(); $mw->raise(); } } else { $foregroundcolor = "black"; $fontweight = "normal"; $relief = "flat"; } $mw->title("*($total)RCheck - v$version"); $old_results{$name} = $results[2]; $old_total{$name} = $results[0]; $button{$name}->configure(-text => "$output", -foreground => "$foregroundcolor", -font => "{} $font_size {$fontweight}", -relief => $relief, ); $button{$name}->update; } $mw->title("($total)RCheck - v$version"); } sub launch { ($name) = @_; # open the browser to the site system ("mozilla http://$url{$name} &"); # wait 2 seconds before resetting the button sleep(2); # reset the button to "0" messages $foregroundcolor = "black"; $button{$name}->configure(-text => "$name: 0", -foreground => "$foregroundcolor", -font => "{} $font_size {$fontweight}", -relief => $relief, ); $button{$name}->update; } sub setup_window { if (! Exists($setup_window) ) { $setup_window = $mw->Toplevel(); $setup_window->title("RCheck Setup - v$version"); $setup_window->Label(-text => "Setup")->pack(-side =>"top"); add_account($account_name); $setup_window->Button(-text => "Finish", -command => sub { $setup_window->destroy })->pack; } else { $setup_window->deiconify(); $setup_window->raise(); $setup_window->update; } } # sub account_maintenance { # if (! Exists($maintenance_window) ) { # $maintenance_window = $mw->Toplevel(); # $maintenance_window->title("Account Maintenance"); # $maintenance_window->Label(-text => "Maintenance: $account_name") # ->pack(-side =>"top"); # foreach $name (sort keys (%url)) { # $maint_button{$name} = $maintenance_window->Button(-text => "$name", # -justify => "left", # -command => sub {edit_account($name)}, # -height => 0, # -font => "{sans-serif} $font_size {normal}", # -foreground => "black", # )->pack(-side=>'top', # -fill=>'x'); # $maint_button{$name}->update; # } # $maintenance_window->Button(-text => "Finish", # -command => sub { $maintenance_window->destroy })->pack; # $maintenance_window->update; # } # else { # $maintenance_window->deiconify(); # $maintenance_window->raise(); # $maintenance_window->update; # } # } # sub edit_account { # my ($account_name) = @_; # $editing_window = $mw->Toplevel(); # $editing_window->title("Edit Account"); # $editing_window->Label(-text => "Editing: $account_name") # ->pack(-side =>"top"); # $editing_window->Button(-text => "Finish", # -command => sub { $editing_window->destroy })->pack; # $editing_window->update; # } sub add_account { my ($account_name) = @_; $setup_window->withdraw; # display name $account_frame = $setup_window->Frame()->pack(-side => "top", -fill=>'x'); $newaccount_name = $account_frame->Entry(-font => "{} $font_size {normal}") ->pack(-side => 'right'); $newaccount_name->insert("end", "$account_name"); $newaccount_name->focus(); my $account_frame; $account_frame->Label(-text => "account name: ")->pack(-side => "right"); $url_frame = $setup_window->Frame()->pack(-side => "top", -fill=>'x'); $newurl = $url_frame->Entry(-font => "{} $font_size {normal}",) ->pack(-side => 'right'); $newurl->insert("end", "$url{$account_name}"); $url_frame->Label(-text => "url: ")->pack(-side => "right"); my $username_frame; $username_frame = $setup_window->Frame()->pack(-side => "top", -fill=>'x'); $newusername = $username_frame->Entry(-font => "{} $font_size {normal}",) ->pack(-side => 'right'); $newusername->insert("end", "$username{$account_name}"); $username_frame->Label(-text => "username: ")->pack(-side => "right"); my $password_frame; $password_frame = $setup_window->Frame()->pack(-side => "top", -fill=>'x'); $newpassword = $password_frame->Entry(-font => "{} $font_size {normal}", -show => "*")->pack(-side => 'right'); $password_frame->Label(-text => "password: ")->pack(-side => "right"); $setup_window->Button(-text => "Enter", -command => sub { create_account(); }, -font => "{} $font_size {normal}", )->pack(-side => 'top'); $setup_window->update; $setup_window->deiconify(); $setup_window->raise(); } sub create_account { $create_newpassword = md5_hex($newpassword->get()); $create_newusername = $newusername->get(); $create_newurl = $newurl->get(); $create_newaccount_name = $newaccount_name->get; $name = "$create_newaccount_name"; $url{$name} = "$create_newurl"; $username{$name} = "$create_newusername"; $md5pass{$name} = "$create_newpassword"; $button{$account_name}->destroy() if ( $account_name && Exists($button{$name}) ); $button{$name} = $mw->Button(-text => "$name = ?", -justify => "left", -relief => "flat", -command => [ \&launch, $url{$name} ], -height => 0, -font => "{sans-serif} $font_size {normal}", -foreground => "black", )->pack(-side=>'top', -fill=>'x'); #update the data file open (DATA, ">$datafile"); print DATA "# RCheck datafile created by RCheck. Make sure you know what ". "# you're doing\n"; print DATA "# format:"; print DATA " account_name account_url account_username account_md5_password_hash\n"; foreach $name (sort keys (%url)) { print DATA "$name $url{$name} $username{$name} $md5pass{$name}\n"; } }