Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl script is not executing in HTML form

Tags:

apache

perl

I have a guestbook.htm file in the directory named as Chrome (/home/chankey/Desktop/Chrome/guestbook.htm) whose content is given below

<html>
<head>
<title>Guestbook</title>
</head>
<body>

<form action="/home/chankey/Desktop/Chrome/guestbook.pl" method="get">
<table>
<tr><td>Name</td><td><input name="name" type="text" value=""></td></tr>
<tr><td>E-Mail</td><td><input name="email" type="text" value=""></td></tr>
<tr><td>Location</td><td><input name="loc" type="text" value=""></td></tr>
<tr><td>Comments</td><td>
<TEXTAREA name="comments" rows="10" cols="32"></TEXTAREA></td></tr>
</table><br><br>
<input type="submit" value="Add Entry">
</form>

</body>
</html>

In the same Chrome directory I have one file "guestbook.pl" whose content is

#!/usr/bin/perl

my $query_string = "";
#Get the input
if ($ENV{REQUEST_METHOD} eq 'POST') {
read(STDIN, $query_string, $ENV{CONTENT_LENGTH});
} else {
$query_string = $ENV{QUERY_STRING};
}
##### We will remove this
print "Content-Type: text/html\n\n";
print "Query String is \n<br> $query_string";
##### We will remove this

When I am executing the guestbook.htm file there appears a form, when I fill the data and click on "Add Entry" button a new page opens where the complete script appears.

i.e. the script "guestbook.pl" is not executing. May I know the reason behind this? Why the script is not executing? (I have already given executing permission to this file).

In the httpd.conf file I have added

AddHandler cgi-script cgi pl
<Directory /home/chankey/Desktop/Chrome/>
    Options +ExecCGI
</Directory>

Still it is not executing. Let me know the reason.

like image 381
Chankey Pathak Avatar asked Nov 23 '25 14:11

Chankey Pathak


1 Answers

When you access a file locally (over the file:// type URL in your browser), it's not running from a web server, so:

  • There is no CGI environment
  • The httpd.conf/.htaccess files have no effect

A few ways to deal with this:

  • Create a folder named public_html in your home. Your web server likely has a setting to map http://localhost/~chankey/ to /home/chankey/public_html. (On MacOSX, the preferred name is Sites, instead, I believe.) On an SELinux system, you'll have to specifically grant permission for Apache to use this method.
  • For the specific case of Perl scripts using the standard CGI package, you can also run them manually from a terminal shell, and redirect their output to a temporary file (e.g. >/tmp/output.html), which you can then access
  • Migrate your development workspace into your web server's own directory structure, typically /var/www/html/

PS / unrelated: I strongly recommend that, if you plan to put this on the Internet, you should probably use CGI; use strict; and have the tainting mode enabled #!/usr/bin/perl -WT

like image 136
BRPocock Avatar answered Nov 26 '25 17:11

BRPocock