# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/sbin/snappd/scripts/IPDoPing.pl 1.6 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2000,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#
#!/usr/bin/perl -T
# @(#)91        1.6  src/bos/usr/sbin/snappd/scripts/IPDoPing.pl, snapp, bos720 5/31/02 07:49:59


#---------------------------------------------------------------------
#--------Do Ping for Snapp Program	------------------------------
#---------------------------------------------------------------------
#--------This page takes value from field in previous 	--------------
#--------screen, tries to ping that value, and returns results	------
#---------------------------------------------------------------------
#--------Links to Pages: IPMain.pl, IPPing.pl 		--------------
#---------------------------------------------------------------------

$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin';

# this function may take a while, so send out please wait page
#-------------------------------------------------------------

open(ENFILE, "/var/snapp/snapp.eni");
$en = <ENFILE>;
close(ENFILE);

open(OUTFILE,">/var/snapp/snapp.fres.tmp");

print OUTFILE <<EOXML;
<PAGE>
<TITLE>Test Ping:</TITLE>

<W>150</W>
<H>12</H>
<X>5</X>
<Y>35</Y>
<LABEL>Sending out ping...</LABEL>
<DY>12</DY>
<LABEL>Please wait.</LABEL>

</PAGE>
EOXML

close(OUTFILE);
system("/usr/bin/cp /var/snapp/snapp.fres.tmp /var/snapp/snapp.fres");

#-------------------------------------------------------------
# get info to ping for
#-------------------------------------------------------------

%hshIPToTest = @ARGV;

$strIPToTest = $hshIPToTest{"ToPingValue"};


#-------------------------------------------------------------
# attempt ping of value
#-------------------------------------------------------------

#----- loopback
$intLoopback    = `/usr/sbin/ping  -c 1 $strIPToTest 2>/dev/null | /usr/bin/grep icmp | /usr/bin/wc | /usr/bin/cut -c1-8`;
if ($intLoopback == 1)
{
  $strPingResult = "SUCCESS";
}
else
{
  $strPingResult = "FAILED";
}


#-------------------------------------------------------------
# output results
#-------------------------------------------------------------

open(OUTFILE,">/var/snapp/snapp.fres.tmp");

print OUTFILE <<EOXML;
<PAGE>
<TITLE>Test Ping Results</TITLE>

<W>150</W>
<H>15</H>
<X>47</X>
<Y>45</Y>
<LABEL>Results:</LABEL>

<DX>35</X>
<LABEL>$strPingResult</LABEL>

<W>25</W>
<X>65</X>
<Y>130</Y>
<BUTTON Name="IPPing.pl">OK</BUTTON>

</PAGE>
EOXML

close(OUTFILE);
for($i=0;$i<10 && `ls /var/snapp/snapp.fres | wc -l` == 1;$i++)
{
	sleep 1;
}
system("/usr/bin/cp /var/snapp/snapp.fres.tmp /var/snapp/snapp.fres");