# IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # bos720 src/bos/usr/sbin/snappd/scripts/IPDoSetTokenRing.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 # @(#)93 1.4 src/bos/usr/sbin/snappd/scripts/IPDoSetTokenRing.pl, snapp, bos720 5/31/02 07:50:07 #----------------------------------------------------------------------------- #--------Token Ring Interface Modification Page for Snapp Program------------- #----------------------------------------------------------------------------- #--------This page is used to execute the command to configure -------------- #--------the selected interface ------------------------------ #----------------------------------------------------------------------------- #--------Links to Pages: IPViewMessage.pl and/or ---------------------- #--------IPSetTokenRing.pl or IPDoneSetTokenRing.pl--------------------------- #----------------------------------------------------------------------------- $ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin'; #----- get the user entered data from the command line %hshObjectTags=@ARGV; #----------------------------------------------------------------------------- #--*Note*-> Minimal Error Checking Done on IP Addresses and also on the Command #----- itself -display of erros is possible on limited scale #----------------------------------------------------------------------------- # getting values is like this --> # 1. get value # 2. remove any newline characters # 3. remove any spaces # 4. generate the flag to be used in the command # 5. Any error checking if applicable #----------------- Hostname ------------------------------ $strHostname = $hshObjectTags{"Hostname"}; $strHostname =~ s/\n//g; $strHostname =~ s/\s+//g; $strFlagHostname = join "", "-h'", $strHostname, "'"; #----------------- IP Address ------------------------------ $error = 0; $strIPAddress = $hshObjectTags{"IPAddress"}; $strIPAddress =~ s/\n//g; $strIPAddress =~ s/\s+//g; $strFlagIPAddress = join "", "-a'", $strIPAddress, "'"; &ErrorCheck($strIPAddress); if($error == 1) { $strMessage = "Invalid IP Address\n"; $error = 0; $wasError = 1; } #----------------- Netmask ------------------------------ $strNetmask = $hshObjectTags{"Netmask"}; $strNetmask =~ s/\n//g; $strNetmask =~ s/\s+//g; $strFlagNetmask = join "", "-m'", $strNetmask, "'"; &ErrorCheck($strNetmask); if($error == 1) { $strMessage = join '', $strMessage, "Invalid Netmask\n"; $error = 0; $wasError = 1; } #----------------- Gateway ------------------------------ $strGateway = $hshObjectTags{"Gateway"}; $strGateway =~ s/\n//g; $strGateway =~ s/\s+//g; $strFlagGateway = ""; if($strGateway ne "") { $strFlagGateway = join "", "-g'", $strGateway, "'"; &ErrorCheck($strGateway); if($error == 1) { $strMessage = join '', $strMessage, "Invalid Gateway Address\n"; $error = 0; $wasError = 1; } } #----------------- Domain and Nameserver ------------------------------ $strDomain = $hshObjectTags{"Domain"}; $strDomain =~ s/\n//g; $strDomain =~ s/\s+//g; $strFlagDomain = ""; $strNameserver = $hshObjectTags{"Nameserver"}; $strNameserver =~ s/\n//g; $strNameserver =~ s/\s+//g; $strFlagNameserver = ""; if(($strDomain ne "") && ($strNameserver ne "")) { $strFlagDomain = join "", "-d'", $strDomain, "'"; $strFlagNameserver = join "", "-n'", $strNameserver, "'"; &ErrorCheck($strNameserver); if($error == 1) { $strMessage = join '', $strMessage, "Invalid Nameserver Address\n"; $error = 0; $wasError = 1; } } elsif(($strDomain ne "") || ($strNameserver ne "")) { $strMessage = join '', $strMessage, "Both the Nameserver and the Domain have to be defined\n"; $wasError = 1; } #----------------- Ring Speed ------------------------------ $strRingSpeed = $hshObjectTags{"RingSpeed"}; $strRingSpeed =~ s/\n//g; $strRingSpeed =~ s/\s+//g; $strFlagSpeed = join "", "-r'", $strRingSpeed, "'"; #------check to make sure ring spped was one of the available ones to choose from if(!( ($strRingSpeed eq "autosense") || ($strRingSpeed eq "4") || ($strRingSpeed eq "16") )) { $wasError = 1; $strMessage = join '', $strMessage, "Invalid Token Ring Speed\n"; } #----------------- Interface Selected ------------------------------ open(ENFILE, "/var/snapp/snapp.eni"); $en = ; close(ENFILE); #------ Check to see if the tcpip Daemons are running, if they're not start them at command ------ if($argdf = `/usr/bin/lssrc -g tcpip | /usr/bin/grep active`) { $startNowFlag = ""; } else { $startNowFlag = "-s"; } if($wasError != 1) { #-------------run command $errorChecking = `/usr/sbin/mktcpip $strFlagHostname $strFlagIPAddress $strFlagNetmask -i'$en' $strFlagNameserver $strFlagDomain $strFlagGateway $strFlagSpeed $startNowFlag\n`; #------- check to see if returned value is correct if($? == 0) { $strLabel = "12 "; $strButton = "30 12 65 130 "; } else { #-------- if return isn't, tell user on screen open(ENFILE, "/var/snapp/snapp.eni"); print OUTFILE "$en"; close(ENFILE); $strLabel = "12 "; $strButton = "30 12 10 120 35 65 "; } $errorChecking =~ s/\n/,/g; #-----save return value in case user wants to view it open(OUTFILE,">/var/snapp/snapp.message"); print OUTFILE "$errorChecking"; close (OUTFILE); #generate page, this page also includes a link to view the message that was returned open(OUTFILE,">/var/snapp/snapp.fres.tmp"); print OUTFILE < Token Ring Configuration: 150 12 5 30 $strLabel $strButton EOXML close(OUTFILE); system("/usr/bin/cp /var/snapp/snapp.fres.tmp /var/snapp/snapp.fres"); } else { #-------this page is printed in case the information entered doesn't pass the loose error checking #-------an option to try again is displayed open(OUTFILE,">/var/snapp/snapp.fres.tmp"); print OUTFILE < Error With Information: 150 12 5 30 150 20 100 60 12 50 50 EOXML close(OUTFILE); system("/usr/bin/cp /var/snapp/snapp.fres.tmp /var/snapp/snapp.fres"); } #------------------------------------------------------------- # Do Error Checking on the inputed data # Only the address fields are being tested for now #------------------------------------------------------------- sub ErrorCheck { my($strIP) = @_; @nums = split(/\./, $strIP); $length = @nums; if ($length != 4) { $error = 1; } foreach $_ (@nums) { if ((length($_) > 3) or (length($_) < 1)) { $error = 1; last; } if (/[^0-9]/) { $error = 1; last; } } }