#!/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 snarfed 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";
$useXPM = (!defined($noXPM) && $wafe'Packages =~ /\bXPM\b/);

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

&Xui(<<'__');
  mergeResources topLevel *borderWidth 0
  Form top topLevel \
    defaultDistance 0 translations {<Key>q: exec(quit)}
__
sub setBitmap {
    &Xui("sV $_[0] bitmap $_[1].xbm width [gV label_$_[0] width]");
#   &Xui("setIconPixmap topLevel $_[1].xpm ") if $useXPM;
}

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 horizDistance 0 hSpace 0 vSpace 0
      Label label_$h box_$h label {$lh} $backGround
      Label $h box_$h internalWidth 1 width [gV label_$h width] \\
	    bitmap level.xbm $backGround
__
    &Xui("sV box_$h fromHoriz $last_chart") if $last_chart;
    $last_chart = "box_$h";
}
&Xui("realize;deleteWindowProtocol quit");

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

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