#!/usr/local/bin/perl -P
#
# Copyright (C) 1992 by Gustaf Neumann, Stefan Nusser
#
#      Wirtschaftsuniversitaet Wien,
#      Abteilung fuer Wirtschaftsinformatik
#      Augasse 2-6,
#      A-1090 Vienna, Austria
#      neumann@wu-wien.ac.at, nusser@wu-wien.ac.at
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appears in all copies and that both that
# copyright notice and this permission notice appear in all supporting
# documentation.  This software is provided "as is" without expressed or
# implied warranty.
#
# Date: Mon, Apr 13 1992
# Author: Gustaf Neumann
# Version: 0.9
#
# inspired by xping (Michiel Huisjes (huisjes@cs.vu.nl), 
# bitmaps from Jan Mark Wams (jms@cs.vu.nl)

$ping = '/etc/ping';

$options = "u:";
$WafeLib = $ENV{'WAFELIB'} || "/usr/lib/X11/wafe";
require "$WafeLib/perl/wafe.pl";

$opt_u = $opt_u ||  90; # 90 seconds per default
if ($#ARGV == -1) { @ARGV = @ftpServers; }

&Xui("form top topLevel defaultDistance 0");
&Xui("action top override {<Key>q : exec(quit)}");

sub setBitmap {
	&Xui("sV $_[0] bitmap $WafeBitmaps/$_[1].xbm width [gV label_$_[0] width]");
}

foreach (@ARGV) {
    $lh = $1 if /^ftp\.([^\.]+)/ || /([^\.]+)/;
    $lh = substr(length($lh)<4?substr("$lh    ",0,4):$lh,0,10);
    ($h = $_) =~ tr/./-/;
    &Xui("box box_$h top borderWidth 0 horizDistance 0 hSpace 0 vSpace 0;"
              ."label label_$h box_$h label {$lh} borderWidth 0 $backGround;"
              ."label $h box_$h borderWidth 0 internalWidth 1 width [gV label_$h width] "
                     ."bitmap $WafeBitmaps/level.xbm $backGround");
    &Xui("sV box_$h fromHoriz $last_chart") if $last_chart;
    $last_chart = "box_$h";
}
&Xui("realize");

while (1) {
    foreach (@ARGV) {
	($h = $_) =~ tr/./-/;
        &setBitmap($h,"level");

#ifdef hpux
        $answer = `ping $_ 64 1`;
	&setBitmap($h,("up","down")[($answer !~ /100\% packet loss/)]);
#else
        $answer = `ping $_`;
	&setBitmap($h,("up","down")[($answer !~ /is alive/)]);
#endif
    }
    select(undef, undef, undef, $opt_u);
}












