M
Me
I'm looking for some insight to the following code. I don't understand why
when I uncomment the #$command="/usr/local/apache/cgi-bin/port-reset.exp
$portnumber"; and comment the ls command it does not execute successfully.
When the code is as below everything works fine, but switching the commented
lines cause it to fail. I send the results of $command to a file and it
looks fine, I can even copy and paste the output, as any user, and it
executes fine, it just won't execute successfully when I call it from a web
page. Any assistance would be appreciated.
## Code begins
print "Content-type: text/html\n\n";
print "<HTML><BODY bgcolor=#483d8b><FONT COLOR=\"yellow\">";
print "<CENTER>";
$portnumber = $in{'PORT'}; #Value passed in from the
/usr/local/apache/htdocs/port-reset/index.html page
#$command="/usr/local/apache/cgi-bin/port-reset.exp $portnumber"; ## This
command will only execute from a command line and not from within this
script
$command="/usr/bin/ls -al > /tmp/file2"; # This works fine, so I comment
this line, uncomment the above and the script fails. Why?
$result = system("$command");
if ($result) {
# $? is the exit code.
print "<h1>Unable to reset port $portnumber. Contact support.\n";
}
else {
#It exits 0 if successfully
print "<h1>Port $portnumber has been reset.";
}
##############################################################
# This logs all page sent through the web
##############################################################
$Time = localtime;
open(OUTFILE, ">>/usr/local/apache/logs/port-reset.logs");
print OUTFILE
("\"$Time\",\"$ENV{'REMOTE_ADDR'}\",\"$portnumber\",\"$command\"\n\"");
exit;
## Code ends
when I uncomment the #$command="/usr/local/apache/cgi-bin/port-reset.exp
$portnumber"; and comment the ls command it does not execute successfully.
When the code is as below everything works fine, but switching the commented
lines cause it to fail. I send the results of $command to a file and it
looks fine, I can even copy and paste the output, as any user, and it
executes fine, it just won't execute successfully when I call it from a web
page. Any assistance would be appreciated.
## Code begins
print "Content-type: text/html\n\n";
print "<HTML><BODY bgcolor=#483d8b><FONT COLOR=\"yellow\">";
print "<CENTER>";
$portnumber = $in{'PORT'}; #Value passed in from the
/usr/local/apache/htdocs/port-reset/index.html page
#$command="/usr/local/apache/cgi-bin/port-reset.exp $portnumber"; ## This
command will only execute from a command line and not from within this
script
$command="/usr/bin/ls -al > /tmp/file2"; # This works fine, so I comment
this line, uncomment the above and the script fails. Why?
$result = system("$command");
if ($result) {
# $? is the exit code.
print "<h1>Unable to reset port $portnumber. Contact support.\n";
}
else {
#It exits 0 if successfully
print "<h1>Port $portnumber has been reset.";
}
##############################################################
# This logs all page sent through the web
##############################################################
$Time = localtime;
open(OUTFILE, ">>/usr/local/apache/logs/port-reset.logs");
print OUTFILE
("\"$Time\",\"$ENV{'REMOTE_ADDR'}\",\"$portnumber\",\"$command\"\n\"");
exit;
## Code ends