# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/sbin/snappd/scripts/DHCP3EEthernet.pl 1.4 
#  
# 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
# @(#)83        1.4  src/bos/usr/sbin/snappd/scripts/DHCP3EEthernet.pl, snapp, bos720 5/31/02 07:49:32

#---------------------------------------------------------
#------	Name DHCP3EEthernet.pl
#---------------------------------------------------------
#------ Displays list of IEEE Ethernet interfaces 
#------ available for DHCP configuration.
#---------------------------------------------------------
#------ Links to Pages: IPMinConfig.pl
#------                 DHCPSetup.pl
#---------------------------------------------------------

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

$i = 0;
#find the Interfaces of standard type and store them in a array (or possible hash)
foreach $ifname (`/usr/sbin/lsdev -Cc if | /usr/bin/grep IEEE | /usr/bin/grep Ethernet`)
{
   if ($ifname =~ s/([a-z0-9]+).*/\1/)
   {
   	
   	($temp, $t) = split(" ", $ifname);
   	@hshInterfaces[$i] = $temp;
   	$i++;
   }
}

#set some Strings to default values
$ButtonString = "";
$tempX = "<X>10</X>\n";
$tempDY = "<DY>20</DY>\n";
$tempDX = "<DX>75</DX>\n";

#This dynamically builds the page to be displayed.  This creates a button for each interface
#and then displays it on the page as needed.
if($i == 0)
{
	#the lsdev command didn't return any interfaces
	$ButtonString = "<W>150</W> <X>20</X> <DY>25</DY> <LABEL>Sorry, No Available Interfaces</LABEL> <W>35</W> <X>60</X> <DY>35</DY> <BUTTON Name=\"IPMinConfig.pl\">OK</BUTTON>";
}
else
{
	#there are 2 or more interfaces, get all the pairs and put them ijn the xml page row by row
	#whatever is left (if anything) will be caught next
	
        for ($loop_index = 0; ($i - $loop_index) >= 2; $loop_index = $loop_index
 + 2) {
		$tempInterface = @hshInterfaces[$loop_index];
		$tempInterface1 = @hshInterfaces[$loop_index+1];
		$tempString = "<BUTTON Name=\"DHCPSetup.pl $tempInterface\">$tempInterface</BUTTON>";
		$tempString1 = "<BUTTON Name=\"DHCPSetup.pl $tempInterface1\">$tempInterface1</BUTTON>";
		$ButtonString = join ' ', $ButtonString, $tempX, $tempDY, $tempString, $tempDX, $tempString1, "\n";
	}

	#if there is one interface left, put it in the xml page to be displayed
	
	if(($i - $loop_index) == 1)
	{
		$tempInterface = @hshInterfaces[$loop_index];
		$tempString = "<BUTTON Name=\"DHCPSetup.pl $tempInterface\">$tempInterface</BUTTON>";
		$ButtonString = join ' ', $ButtonString, "<X>45</X>", $tempDY, $tempString, "\n";
	}	
}


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

print OUTFILE <<EOXML;
<PAGE> 
 	<TITLE>DHCP Interface Selection</TITLE>
 	<W>100</W> 
 	<H>15</H> 
 	<X>20</X> 
 	<Y>5</Y> 

 	<W>150</W>
 	<X>30</X>
 	<DY>25</DY>
 	<LABEL>Please Choose Interface</LABEL>
 	<DX>25</DX>
 	<DY>15</DY>
 	<LABEL>to Configure</LABEL>
 	<W>65</W>
 	
 	$ButtonString
 	
</PAGE>
EOXML

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