MatthewF
asked on
My varibales from html are not passed to oerl
use CGI;
$cgi = CGI->new;
%FORM = $cgi->Vars;
$host_file=$FORM{'hostfile
$day=$FORM{'dr_day'};
$start_hr=$FORM{'dr_start_
When I use this the html returns a blank page and the perl is not excuted. However, when I hard code the varaible as below, the html return a completed message the perl runs
$host_file = "hosts.both";
$day = "2";
$start_hr = "03";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I know it not exucted because the perl script ftp files to $server
ASKER
perl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use Net::FTP;
use CGI;
$cgi = CGI->new;
%FORM = $cgi->Vars;
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst) =localtime;
$current_time = localtime();
$ht=`hostname`;
$addy = "msmith\@yahoo.com";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g; # replace newlines with spaces
$value =~ s/\r//g; # remove hard returns
$value =~ s/\cM//g; # delete ^M's
$FORM{$name} = $value;
}
$log="dr.log"; ### location of DR logged info
$output="dr_output.log";
$done="/completed/";
$dir="/files/"; ### location of stored files
$dir2="/dr_login";
open(OUT_LOG,">> $output") || die "Can't open $log $!\n";
#$host_file = "$FORM{'hostfile'}";
#$day = "$FORM{'dr_day'}";
#$start_hr = "$FORM{'dr_start_hr'}";
$host_file=$FORM{'hostfile'};
$day=$FORM{'dr_day'};
$start_hr=$FORM{'dr_start_hr'};
$server = "trd004";
$host_file = "hosts.both";
$day = "2";
$start_hr = "03";
$server = "fd00p71";
if ($host_file =~ /^Mainframe/) {
system("cp $dir2/hosts.mainframe $dir2/hosts");
}
elsif ($host_file =~ /^Mainframe/) {
system("cp $dir2/hosts.distributed $dir2/hosts");
}
else {
system("cp $dir2/hosts.both $dir2/hosts");
}
##########&put_files;
@get_day=`cat $log | grep "#$day#$start_hr"`;
&put_files;
sub put_files {
foreach $get_day (@get_day) {
($username,$passwd, $file )=split(/ /,$get_day);
$file =~ s/#$day#$start_hr//gi;
chop $file;
###print "file is $file and time is $day#$start_hr\n\n";
$mv_it=`cp $dir$file#$day#$start_hr $dir$file`; ###change to mv during actual test
#sleep 2;
$newfile="$dir$file";
$f = Net::FTP->new($server, Debug => 0);
$f->login($username, $passwd) or &fail;
$msg = "".$f->message."";
$f->binary();
$f->put($newfile) or &fail;
&pass;
};
sub fail {
if ($msg !~ /^Virtual user/) {
print OUT_LOG "$current_time $username Connection to $server failed. $file not sent.\n";
$MSG="$current_time\n\n User $username connection to $server failed. File $file not sent.";
$SUB = "\"DR Restoration Failure\"";
open MAIL,"|/usr/bin/mailx -s $SUB $addy";
print MAIL $MSG;
close MAIL;
}
}
sub pass {
if ($msg =~ /^Virtual user/) {
print OUT_LOG "$current_time Processing $file to $server.\n";
#system("mv $dir$file#$day#$start_hr $done$file#$day#$start_hr");
#system("rm $dir$file");
}
}
print OUT_LOG "$current_time All files from date $day hour $start_hr were sent to ST server
$server\n";
close OUT_LOG;
print <<EndHTML;
<html><head><title>Thank You</title></head>
<body>
<h2>Thank You! </h2>
Your request has been submitted.<p>
All $host_file files from date $day hour $start_hr were sent to ST server $server .
<br><br>
See $output for details.
<br><br>
<a href="https://$ht:444/brules/CUSTOM/Tools/dr_restore.html">Return to the DR Restore Page
</a><p>
<a href="https://$ht:444/admin/">Return to the Secure Transport Admin Page</a><p>
</body></html>
EndHTML
$message="$current_time\n\nAll files from date $day hour $start_hr to ST server $server.";
$sub = "\"DR Restoration Status\"";
open MAIL,"|/usr/bin/mailx -s $sub $addy";
print MAIL $message;
close MAIL;
exit;
HTML
<html><head><title> Restore Data</title></head>
<body text=#000000 vLink=#6699ff aLink=#00ff00 link=#6666ff
bgColor=#CCFFFF>
<center><h2>Restore Data</h2></center>
<br>
<form method="POST" action="/cgi/Tools/restore.cgi.pl" name="result" onsubmit="return validateForm(this);">
What day do you need to restore ?</br>
<select name="dr_day">
<OPTION VALUE="Please Select">Please Select</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<br>
<br>
What is the hour you need to restore ? </br>
<select name="dr_start_hr">
<OPTION VALUE="Please Select">Please Select</option>
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
</select>
<br>
<br>
What Files are you restoring?</br>
<select name="hostfile">
<OPTION VALUE="Please Select">Please Select</option>
<option value="Mainframe">Mainframe</option>
<option value="Distributed">Distributed</option>
<option value="Both">Both</option>
</select>
<br>
<br>
<INPUT type=submit value="Submit Your Data"> <sp><sp>
<INPUT type=reset value="Reset Values">
</<br>
<br>
<br>
<a href="javascript:location.href='https://'+window.location.hostname+':444/admin'">Click here to cancel your submission</a><p>
</form>
</body></html>
That doesn't necessarily mean that it didn't execute. It could have executed but failed at some point.
Are there any error messages in the web server log file?
Are there any error messages in the web server log file?
First, get rid of this and don't use it in any of your scripts:
ALWAYS use the strict and warnings pragmas, as shown in my earlier example', and while developing/debugging cgi scripts include the CG::Carp module as well.
Use the File::Copy module instead of the system calls. The module will provide the capability of better error handling, which currently you're not doing any error handling on those cp calls.
There's no need/reason to do the piped cat/grep system call since Perl already has methods for doing the exact same thing with error handling.
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g; # replace newlines with spaces
$value =~ s/\r//g; # remove hard returns
$value =~ s/\cM//g; # delete ^M's
$FORM{$name} = $value;
}
The CGI module handles that in a much better way and the '%FORM = $cgi->Vars;' line above that already did it for you.ALWAYS use the strict and warnings pragmas, as shown in my earlier example', and while developing/debugging cgi scripts include the CG::Carp module as well.
Use the File::Copy module instead of the system calls. The module will provide the capability of better error handling, which currently you're not doing any error handling on those cp calls.
There's no need/reason to do the piped cat/grep system call since Perl already has methods for doing the exact same thing with error handling.
Does your script actually begin with these 3 lines?
perl
#!/usr/bin/perl
If so, then that would explain why the script doesn't execute. Remove those first 2 lines. That 3rd line is the 'shebang line' and it needs to be the first line in the script.
ASKER
The firsy line is the /usr/bin/perl. The single word perl was to denote the perl script
ASKER
The debugginh provide me the answer. Thanks
Have you tried dumping %FORM to see what it holds?