Click to See Complete Forum and Search --> : CGI errors


jclark2496
01-05-2004, 08:56 AM
Hi all

I have been trying to get this CGI guestbook script working on my server, and every time I run the script I receive this errors in my logs "error: directory is writable by others: (/home/masseyw/public_html/cgi-bin

File does not exist: /home/masseyw/public_html/500.shtml
Premature end of script headers: /home/masseyw/public_html/cgi-bin/guestbook.cgi

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

Any suggestions would be appreciated.

Here is my script:


#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";

# This is the absolute pathname of the BBS file.
$guestbook="/home/masseyw/public_html/guest.html";

# This is the url of that file on the web server.
$entriespage="http://www.masseywedding.com/guestbookpost.html";

# This is the email address of the maintainer.
$maintainer="user\@emailaddress.com";

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

# Get the input

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs

@pairs = split(/&/, $buffer);

# Load the FORM variables

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}


open (GUESTBOOK,">> $guestbook");
$currenttime=localtime;

# Put the new log entry in.


print GUESTBOOK "$currenttime from $ENV{'REMOTE_HOST'}<BR>\n";

print GUESTBOOK "<FONT SIZE=+1>$FORM{name}";
if ($FORM{email} ne "") {
print GUESTBOOK "&nbsp;&lt;<A HREF=\"mailto:$FORM{email}\"><I>$FORM{email}</I></A>&gt;&nbsp;"; }

print GUESTBOOK "\n";
if ($FORM{url} ne "") {
print GUESTBOOK "(<A HREF=\"$FORM{url}\">Home Page</A>)"; }
print GUESTBOOK "</FONT><P>\n";
print GUESTBOOK "$FORM{comments}<HR><P>\n";
close (GUESTBOOK);
# Thank the user and acknowledge
# the feedback
&thank_you;
}

&sub_error;

sub sub_error {
# Format an error message for the user

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Guestbook Form Error</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<H1>Guestbook Form Error</H1>\n";
print "<HR>\n";
print "<P>\n";
print "Form input was not proccessed. Please mail your ";
print "remarks to $maintainer\n";
print "</BODY>\n";
print "</HTML>\n";
}
sub evil_characters {

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Illegal Email Address</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<H1>Illegal Email Address</H1>\n";
print "<HR>\n";
print "<P>\n";
print "The Email address you entered contains illegal";
print "characters. Please back up and correct, then resubmit.\n";
print "</BODY>\n";
print "</HTML>\n";
}
sub thank_you {

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Thank You!</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFFF TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";
print "<H3>Thanks for your entry. Your feedback is greatly appreciated.<BR>\n";
print "Click here to <A HREF=$ENV{'REFERRER'}>Back</A>, or check out the guestbook <A HREF=$entriespage>entries</A>.\n";
print "<P>\n";
print "<I>$maintainer</I>\n";
print "</BODY>\n";
print "</HTML>\n";
exit(0);
}



TIA

Jason

jane_262
01-15-2004, 07:10 PM
Hey,
First error:
Simply means your file permissions are incorrect. Try 755 instead of 777.

Second error:
Simply means 500.shtml does not exist.
You can create your own Internal Server Error page, but you haven't. (I think)

Third error:
My favoritist of all errors. Means something is wrong with the code in your script.
Always check your file permissions (Apache doesn't like group writable/executable files)
Always upload in ASCII and ensure you have Unix line breaks.
Make sure your shebang is correct.
Finally, make sure all your paths are correct, and variables are defined.

If I check my code four times and again the next day, I usually find the problem. If not, forums are nice. Hope this helps.