Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change a console script to cgi

Status
Not open for further replies.

msingle

MIS
Jul 15, 2002
22
0
0
US
How would I make the following script for use in a web page, rather than the console script that it is?

=== start ===
## Creation Date: 02-25-02
## Mike Singleton
use XML::parser;

print "Enter Servername or IP Address:";

SERVER: chomp($server=<STDIN>);

print &quot;Enter User Name:&quot;;

USER: $user=<STDIN>;

chomp($user);

PASSWORD: print &quot;Enter Password:&quot;;

$password=<STDIN>;

chomp($password);

while ($input ne &quot;x&quot;) {

MENU:

print &quot;\n\nRILOE Menu for $server - Username - $user\n\n&quot;;

print <<EOF;

1 - Get All Users

2 - Get Firmware Info

3 - Get Host Power Status

4 - Get User Info

5 - Get Virtual Floppy Status

6 - Get Virtual Power Button Cable Status

7 - Add User

8 - Remove User

9 - RESET Server

e - Exit



Enter Selection:

EOF



$input=<STDIN>;

$inputfile=&quot;input.file&quot;;

$logfile=&quot;riloe.log&quot;;

$xmlout=&quot;riloe.xml&quot;;



open(LF, &quot;>>$logfile&quot;) || die &quot;Can't open $logfile($!)\n&quot;;

open(XML, &quot;>$xmlout&quot;) || die &quot;Can't open $xmlout($!)\n&quot;;



## Write Header for input file

open(INPUT, &quot;>$inputfile&quot;) || die &quot;Can't open $inputfile($!)\n&quot;;

print INPUT &quot;<RIBCL VERSION=\&quot;1.2\&quot;>\n&quot;;

print INPUT &quot;<LOGIN USER_LOGIN=\&quot;$user\&quot; PASSWORD=\&quot;$password\&quot;>\n&quot;;

##



if ($input==1) { ## All Users



print INPUT &quot;<USER_INFO MODE=\&quot;read\&quot;>\n&quot;;

print INPUT &quot;<GET_ALL_USERS />\n&quot;;

print INPUT &quot;</USER_INFO>\n&quot;;



}elsif ($input==2) { ## Firmware Info



print INPUT &quot;<RIB_INFO MODE = \&quot;read\&quot;>\n&quot;;

print INPUT &quot;<GET_FW_VERSION/>\n&quot;;

print INPUT &quot;</RIB_INFO>\n&quot;;



}elsif ($input==3) { ## Host Power Status



print INPUT &quot;<SERVER_INFO MODE = \&quot;read\&quot;>\n&quot;;

print INPUT &quot;<GET_HOST_POWER_STATUS/>\n&quot;;

print INPUT &quot;</SERVER_INFO>\n&quot;;



}elsif ($input==4) { ## User Info

print &quot;Enter User name:&quot;;

chomp($user_login=<STDIN>);



print INPUT &quot;<USER_INFO MODE=\&quot;read\&quot;>\n&quot;;

print INPUT &quot;<GET_USER USER_LOGIN=\&quot;$user_login\&quot; />\n&quot;;

print INPUT &quot;</USER_INFO>\n&quot;;



}elsif ($input==5) { ## VF Status



print INPUT &quot;<RIB_INFO MODE=\&quot;read\&quot;>\n&quot;;

print INPUT &quot;<GET_VF_STATUS/>\n&quot;;

print INPUT &quot;</RIB_INFO>\n&quot;;



}elsif ($input==6) { ## VPB Cable Status



print INPUT &quot;<SERVER_INFO MODE = \&quot;read\&quot;>\n&quot;;

print INPUT &quot;<GET_VPB_CABLE_STATUS/>\n&quot;;

print INPUT &quot;</SERVER_INFO>\n&quot;;



}elsif ($input==7) { ## Add User

print &quot;Enter User Display Name:&quot;;

chomp($user_name=<STDIN>);

print &quot;Enter Login:&quot;;

chomp($user_login=<STDIN>);



#----------------------------------------------------------------------------------------------------------------------------------------#

# Strong Password Enforcement code

PASSWORD:print &quot;Enter Password:&quot;;

chomp($user_pw=<STDIN>);

$pwlength=length($user_pw);

if ($pwlength <9) {

print &quot;Invalid Password - Must be at least 8 characters in length\n&quot;;

goto PASSWORD;

}

if ($user_pw =~ /.{1,}\d+[~!@#\$%^&*()_+=`~]/) {

#print &quot;Valid\n&quot;;

} elsif ($user_pw =~ /[~!@#\$%^&*()_+=`~]+.{1,}\d/) { ## Comment this item... and also check for length between 8 and 48 characters

#print &quot;Valid\n&quot;;

## Also check max allowed password length...



} else {

print &quot;$user_pw is not a valid Password - Must include characters,numbers and special characters\n&quot;;

goto PASSWORD;

}

#----------------------------------------------------------------------------------------------------------------------------------------#

print &quot;*Enter SNMP Address:&quot;;

chomp($snmp_addr=<STDIN>);

print &quot;*Enter SUPERVISOR_PRIV(Y/N):&quot;;

chomp($SUPERVISOR_PRIV=<STDIN>);

print &quot;*Enter Client Range . value1:(xxx.xxx.xxx.xxx)&quot;;

chomp($client_range1=<STDIN>);

print &quot;*Enter Client Range . value2:(xxx.xxx.xxx.xxx)&quot;;

chomp($client_range2=<STDIN>);



print INPUT &quot;<USER_INFO MODE=\&quot;write\&quot;>\n&quot;;

print INPUT &quot;<ADD_USER USER_NAME=\&quot;$user_name\&quot; USER_LOGIN=\&quot;$user_login\&quot; PASSWORD=
\&quot;$user_pw\&quot;>\n&quot;;

if ($snmp_addr ne &quot;&quot;) {print INPUT &quot;<SNMP_ADDRESS value =\&quot;$snmp_addr\&quot;/>\n&quot;;}

if ($SUPERVISOR_PRIV ne &quot;&quot;) {print INPUT &quot;<SUPERVISOR_PRIV value =\&quot;$SUPERVISOR_PRIV\&quot;/>\n&quot;;}

print INPUT &quot;<LOGIN_PRIV value =\&quot;Y\&quot;/>\n&quot;;

print INPUT &quot;<REMOTE_CONS_PRIV value =\&quot;Y\&quot;/>\n&quot;;

print INPUT &quot;<RESET_SERVER_PRIV value =\&quot;N\&quot;/>\n&quot;;

print INPUT &quot;<OS_TRAPS value =\&quot;Y\&quot;/>\n&quot;;

print INPUT &quot;<RIB_TRAPS value =\&quot;N\&quot;/>\n&quot;;

if ($client_range1 ne &quot;&quot;) {print INPUT &quot;<CLIENT_RANGE value =\&quot;$client_range1 - $client_range2\&quot;/>\n&quot;;}



print INPUT &quot;</ADD_USER>\n&quot;;

print INPUT &quot;<GET_ALL_USERS />\n&quot;;

print INPUT &quot;</USER_INFO>\n&quot;;



}elsif ($input==8) { ## Remove User

print &quot;Enter User Name to Remove:&quot;;

chomp($user_login=<STDIN>);



print INPUT &quot;<USER_INFO MODE=\&quot;write\&quot;>\n&quot;;

print INPUT &quot;<DELETE_USER USER_LOGIN=\&quot;$user_login\&quot;/>\n&quot;;

print INPUT &quot;<GET_ALL_USERS />\n&quot;;

print INPUT &quot;</USER_INFO>\n&quot;;



}elsif ($input==9) { ## RESET SERVER

print &quot;Are you sure you want to reset $server?(Y/N)&quot;;

$reboot=<STDIN>;

if ($reboot==&quot;Y&quot;) {

print INPUT &quot;<SERVER_INFO MODE = \&quot;write\&quot;>\n&quot;;

print INPUT &quot;<RESET_SERVER/>\n&quot;;

print INPUT &quot;</SERVER_INFO>\n&quot;;

} else {

print &quot;NOT RESETTING $server\n&quot;;

goto MENU;

}



}elsif ($input =~ /e/) { ## Exit

print &quot;Goodbye...\n&quot;;

exit;

} else {

print &quot;Invalid Entry&quot;;

goto MENU;

}

## Write Footer for INPUT file

print INPUT &quot;</LOGIN>\n&quot;;

print INPUT &quot;</RIBCL>\n&quot;;



close(INPUT);

## RUN XML INTERPRETER ON INPUT FILE

print &quot;Processing input...\n&quot;;

if ($input<10) {$output=`cpqlocfg -s $server -l $logfile -f $inputfile`;}

#exit;

print $output;
#$_=get($output=xml);
#while (m/<article id=&quot;/) { #Find start of new field

print XML $output;

close(XML);

goto MENU;

}

=== end ====
 
That doesn't look like a cgi-friendly script if you ask me. There are two types of perl programming, cgi/web-based and for commandline. Commandline is more like an active language in a sense where you can do continuous loops asking for information. Using CGI you'd need to use forms, submit the information, see the information on the next screen, add more information on this screen, ...

Some programs are better off for command line. It takes time to convert into CGI but it's not really that hard, you just need to change all your chomp lines to form fields/elements and probably stick them in tables. This way you can begin collecting data from forms and processing them this way.

You can read up on CGI.pm by going to and typing in the module name.

Hope this helps. &quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top