开发者

Perl form-mail script that is not working

开发者 https://www.devze.com 2023-04-08 11:19 出处:网络
I have been given the task through school to institute a comments form on my website.I got all of what I thought would be the hard things done, but have now hit a major stumbling block.I was given a p

I have been given the task through school to institute a comments form on my website. I got all of what I thought would be the hard things done, but have now hit a major stumbling block. I was given a perl script called form-mail2 to put in the cgi-bin of my web server and did that, but when I click submit on my form, I get this:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@randyloope.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

This has to be related to the script, so I would like to reach out to you to help me. I was given the script in total so I'm guessing it isn't configured right, but I haven't the foggiest of how to configure it correctly. Here is the script:

#!/usr/local/bin/perl

# ------------------------------------------------------------
# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
#
# Last updated: March 14, 1994
#
# Form-mail provides a mechanism by which users of a World-
# Wide Web browser may submit comments to the webmasters
# (or anyone else) at a site.  It should be compatible with
# any CGI-compatible HTTP server.
# 
# Please read the README file that came with this distribution
# for further details.
# ------------------------------------------------------------

# ------------------------------------------------------------
# This package is Copyright 1994 by The Tech. 

# Form-mail is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.

# Form-mail is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Form-mail; see the file COPYING.  If not, write to the Free
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# ------------------------------------------------------------

# Define fairly-constants

# This should match the mail program on your system.
$mailprog = '/usr/lib/sendmail';

# This should be set to the username or alias that runs your
# WWW server.

$recipient = 'salvador.voli@gmail.com' 


if ($recipient eq  "\@csprofessor.com") { 
    $recipient = $ENV{'SERVER_ADMIN'};
}

# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

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

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

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ 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>";

    $FORM{$name} = $value;
}

# If the comments are blank, then give a "blank form" response

unless ($FORM{'realname'}) { &blank_response("name");    }
unless ($FORM{'email'}   ) { &blank_response("email");   }   
unless ($FORM{'message'} ) { &blank_response("message"); }
unless ($FORM{'rating'}  ) { &blank_response("rating");  }

# Print a title and initial heading
print "<html>\n";
print "<Head><Title>Thank you</Title></Head>";
print "<Body><H1>Thank you</H1>";
print "<p>Thank you for sending your comments!<br>";
print "</body></html>";

# Now send mail to $recipient

open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "To: sgifford\@csprofessor.com\n";
#print MAIL "To: $recipient\n";
print MAIL "From: $FORM{'email'} ($FORM{'realname'})\n";
print MAIL "Reply-to: $FORM{'email'} ($FORM{'realname'})\n";
print MAIL "Subject: Web Site Comments\n\n";
print MAIL "------------------------------------------------------------\n";
print MAIL "$FORM{'email'} ($FORM{'realname'}) Stopped by\n";
print MAIL "Phone: $FORM{'phone'}\n";
print MAIL "Birthday: $FORM{'bday'}\n";
print MAIL "------------------------------------------------------------\n";
print MAIL "And this is what $FORM{'realname'} had to say:\n\n";
print MAIL "$FORM{'message'}";
print MAIL "\n------------------------------------------------------------\n";
print MAIL "Web Site Rating: $FORM{'rating'}";
print MAIL "\n------------------------------------------------------------\n";
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
print MAIL  "------------------------------------------------------------\n";
close (MAIL);

# Make the person feel good for writing to us

# ------------------------------------------------------------
# subroutine blank_response
sub blank_response
{

    print "<html>\开发者_运维知识库n";
    print "<Head><Title>Incomplete Comment Form</Title></Head>";
    print "<Body><H1>Incomplete Comment Form</H1>";
    print "<p>";
    print "The $_[0] field appears to be blank! ";
    print "Please finish filling out the form and re-submit your comments. ";
    print "</body></html>";
    exit;
}

And here is the form part of my code:

<form name="usercomments" action="/cgi-bin/form-mail2.pl" method="post" onsubmit="return finalCheck()">


Name: <input type="text" name="realname" onchange= "nameCheck()" value="" /><br />

email: <input type="text" name="email" onchange = "emailCheck()" value="" /><br />

phone: <input type="text" name="phone" onchange = "phoneCheck()" value="" /><br />

birthday: <input type="text" name="bday" onchange = "birthdayCheck()" value="" /><br />


How would you describe your experience today? <br/ >

  <input type="radio" name="rating" value="Awesome" checked="checked" /> Awesome<br />
  <input type="radio" name="rating" value="Mediocre"  /> Mediocre<br />
  <input type="radio" name="rating" value="Terrible"  /> Terrible<br />

Comments: <br />
<textarea name="message"  rows="5" cols = "100" > 
</textarea><br />

<input type="submit" value="Submit" />
</form>

Any suggestions you could give would be most appreciated.


Perhaps the "last updated 1994" should have been a bit of a red flag?

If you're going to do form-mail in Perl you should start with the NMS FormMail script which is well written and commented and almost certainly way more secure than the script you have.

But yes, look at your server error logs.


I wrote that form-mail program, back in 1993. (I updated it somewhat over the subsequent year, as the copyright indicates.)

You should not use it on any modern Web server. It was more than adequate at a time when the Web was young, and we didn't have to worry (too much) about security. And before the CGI module was written. And so forth.

No one should use it any more. There are dozens, and probably hundreds, of ways to send e-mail from a Web server without the security concerns that form-mail has.


Since you saw this part of the message:

More information about this error may be available in the server error log.

You should be here asking "How do I see the contents of my server error log?" :-)

The short answer is "it depends on how your particular web server is configured".

ie. you should ask your webmaster/ISP that question.

For more info, there is a magazine article (written by the same author as your code):

Learning to use the httpd error log to debug CGI programs
http://www.linuxjournal.com/article/2055

You can easily arrange to get those messages displayed in the browser too, as described in the answer to your frequently asked question:

http://perldoc.perl.org/perlfaq9.html#My-CGI-script-runs-from-the-command-line-but-not-the-browser.-%28500-Server-Error%29
0

精彩评论

暂无评论...
验证码 换一张
取 消