[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Deceptively?] Simple-looking PERL/CGI problem




If you know PERL and CGI, please look at the atached trio of files.

cgilib.pm is a library of common routines for producing email from HTML 
forms.

mail.cgi is the program to be run when the "submit" button is pressed on the 
form.

mf1.html is a very simple HTML form that uses mail.cgi

When I try this, I get this message on my Apache 1.2 error log:

exec of /home/httpd/cgi-bin/mail.cgi failed, reason: No such file or directory 
(errno = 2)
[Sat Jan  9 11:24:19 1999] access to /home/httpd/cgi-bin/mail.cgi failed for 
192.168.24.25, reason: Premature end of script headers

I have these permissions on the cgi-bin files:
-rwxr-xr-x   1 root     root         2396 Jan  9 11:04 cgilib.pm
-rwxr-xr-x   1 root     root         1710 Jan  9 11:13 mail.cgi

And on the cgi-bin directory:
drwxr-xr-x   2 root     root         1024 Jan  9 11:13 .

similarly, these permission on the HTML:
-rwxr-xr-x   1 root     root          576 Jan  9 10:28 mf1.html
drwxr-xr-x   6 root     root         1024 Jan  9 10:31 .


Very bizarre error; I've never seen this before. While I dig, does anyone 
have sage words of advice, etc.

I believe everything relevent is attached, so you can try it if you like; it
will only take a few minutes... thanks!
                                                            ---> RGB <---
package CGILIB;

################################################################
# Print the content-type header.
#
# &print_header;
sub print_header
{
 print "Content-type: text/html\n\n";
}

################################################################
# Print a canned header with title as argument.
#
#
sub canned_header
{
 my( $title ) = @_;

 print "<HTML>\n";
 print "<HEAD>\n";
 print "<TITLE>$title</TITLE>\n";
 print "</HEAD>\n";
}
################################################################
# Print the closing lines for an HTML document.
#
# &print_closing;
sub print_closing
{
 print "</BODY></HTML>\n";
}

################################################################
# Parse the HTML header and form
# information
#
# %ASSOC_ARRAY = &parse_form;
sub parse_form
{
 my ($buffer,$name,$value,%FORM);
 my ($content_length,$query_string,$request_method);

 $content_length = $ENV{'CONTENT_LENGTH'};
 $query_string = $ENV{'QUERY_STRING'};
 $request_method = $ENV{'REQUEST_METHOD'};

# If the REQUEST_METHOD was POST, read from stdin, else the string is in 
QUERY_STRING
 if ($request_method eq 'POST') {
    read(STDIN, $buffer, $content_length);
 }
 else {
  $buffer = $query_string;
 }

   # Split the name-value pairs
   @pairs = split(/&/, $buffer);

   foreach $pair (@pairs)
   {
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
  $name =~ tr/+/ /;
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    # Stop people from using subshells to execute commands
    # Not a big deal when using sendmail, but very important
      # when using UCB mail (aka mailx).
    $value =~ s/~!/ ~!/g;

     # Uncomment for debugging purposes
     # print "Setting $name to $value<P>\n";
    $FORM{$name} = $value;
   }

 %FORM;  # Returns %FORM to caller source...
} #End Sub form_mail


###########################################################################
#
# sub dump_env_vars
#
# Dumps the contents of %ENV in HTML
#
# INPUTS:  \%ENV
#
###########################################################################
sub dump_env_vars
{
 my ($ENV) = @_;

 foreach (keys %$ENV)
 {
  print "$_=$$ENV{$_}<BR>";
 }
}

# For require files
# 1;

mail.cgi