I am very new here today. I have a problem with running a perl script which results in displaying the following message:
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request
The Perl Script for my small Guest book is:
#!/usr/bin/perl
# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
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;
}
# The following sends the email
open (MESSAGE,"¦ /usr/sbin/sendmail -t");
print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{surName}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Subject: Feedback from $FORM{lastName} at Itwebxpert\n\n";
print MESSAGE "Surname: $FORM{lastName}\n";
print MESSAGE "First name: $FORM{firstName}\n";
print MESSAGE "email: $FORM{email}\n";
print MESSAGE "Sex: $FORM{sex}\n";
print MESSAGE "The user wrote:\n\n";
print MESSAGE "$FORM{message}\n";
close (MESSAGE);
&thank_you;
}
#The following creates the Thank You page display
sub thank_you {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Thank You Page</title>\n";
#link to external style sheet file: style1.css
print "<link rel=\"StyleSheet\" name=\"style\" href=\"../styles/style2.css\" type=\"text/css\">";
print "</head>\n";
print "<body>\n";
print "<h1><center>Your message has been sent</center></h1><hr>";
print "<h2 align=\"center\">Thank You!</h2>\n";
print "\n";
print "<h3 align=center>Your feedback is greatly appreciated?</h3><hr><br>";
print "<center><a class=\"declink\" href=\"../personal/personal.html\">Back to home page</a></center>\n";
print "</body>\n";
print "</html>\n";
exit(0);
}
I check the path to the Perl server is correct, and the path from my HTML guest book form to this script file is also correct. The Script work previously in my previous webhosting server, but it does not work at the current webhosting server. The technician of the current webhosting said there is something wrong with the script, but I denied as it worked before. Just to make sure the script is correct, could anyone here check if there is any thing missing from the script above.
Your kind help is very appreciated.
Regards
Daro2008
this means you need to fix either the config/.htaccess or the location of the error document.
then you will be able to see and fix the error in the script or environment that threw the initial error...
just to rule out unix/windows-linebreaks-trouble.
people often can't access errorlogs on shared hosting environments. you might also want to try putting
use CGI::Carp qw(fatalsToBrowser);
right after #!/usr/bin/perl -w.
I don't think it should cause a problem (but silently not send email) -- but, did you check if the path to sendmail? you have "/usr/sbin/sendmail" set up right now ...
I am not the owner of the server, so i cannot have access to log file: config/.htaccess.
the technician of this server claim that his Perl server run perfectly see link below:
[edited]
Could you please advise if any thing is wrong with the above?
[edited by: phranque at 11:04 pm (utc) on July 14, 2008]
[edit reason] No urls, please. See TOS [webmasterworld.com] [/edit]
Phranque, there is on .htaccess in my root directory, but there is no logs inside when I view/edit it. Below is the result of the Perl server test given by the technician:
Server Settings
Date/Time: Monday 14 July 2008 : 19 h 58 mn 03 s
Operating System: linux
Operating System Version: 2.6.21.5-hostnoc-3.1.7-libata-grsec-32
Hardware: i686 (PC)
Host Name:
Last time rebooted: 84 days, 4 hour(s) 56 minute(s)
Average Usage: The Last minute: 0.04
The last 5 minutes: 0.11
The last 15 minutes: 0.16
Connected Users: 0
Software Paths :
sendmail : /usr/lib/sendmail
/usr/sbin/sendmail
whois : /usr/bin/whois
gpg : /usr/bin/gpg
tar : /bin/tar
gunzip : /usr/bin/gunzip
/bin/gunzip
gzip : /usr/bin/gzip
/bin/gzip
sh : /bin/sh
Perl Info:
Installed Perl Version: 5.008008
/usr/local/bin/perl installed?: YES, version :
This is perl, v5.8.8 built for i386-linux-thread-multi
/usr/bin/perl Installed?: YES, version :
This is perl, v5.8.8 built for i386-linux-thread-multi
Installed Perl Modules :
List of all installed Perl modules on this server: CLICK HERE
(This may be long....,Please wait)
Check if a module is installed AND is running: Module's exact Name (without ".pm") :
Examples: CGI or LWP::Simple or DBD::mysql
Variables:
DOCUMENT_ROOT:
Website Root /home/dollarho/public_html/admin
GATEWAY_INTERFACE:
CGI info CGI/1.1
HTTP_ACCEPT:
Types de documents acceptés par le navigateur-visiteur */*
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE:
Language Used en-gb
HTTP_CONNECTION:
HTTP Connection Keep-Alive
HTTP_HOST:
HTTP of the requesting host
HTTP_REFERER:
Referring URL
HTTP_UA_CPU: x86
HTTP_USER_AGENT:
Your Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)
PATH:
Répertoires de base, de recherche de prg /usr/local/bin: /usr/bin: /bin
QUERY_STRING:
Things that follow the ? in a URL
REMOTE_ADDR:
Your IP Address
REMOTE_PORT:
Port used for this request 3917
REQUEST_METHOD:
Type of the request (GET/POST/HEAD) GET
REQUEST_URI:
URI of the request /cgi-bin/servertester.pl
SCRIPT_FILENAME:
CGI path in your server /home/dollarho/public_html/admin/cgi-bin/servertester.pl
SCRIPT_NAME:
URI du CGI en cours d'éxécution (avec wrapper éventuel) /cgi-bin/servertester.pl
SERVER_ADDR:
SERVER_ADMIN:
Administrator's Email webmaster@
SERVER_NAME:
Site's Name
SERVER_PORT:
Server Port 80
SERVER_PROTOCOL:
Server Protocol HTTP/1.1
SERVER_SOFTWARE:
Nom et version du logiciel serveur web Apache/1.3.41 (Unix) mod_gzip/1.3.26.1a mod_log_bytes/1.2 mod_bwlimited/1.4 mod_auth_passthrough/1.8 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.8b
Can you check if there is anything wrong in the above test?
Many thanks for your all inputs.
Cheers
[edited by: phranque at 1:12 am (utc) on July 15, 2008]
[edit reason] specifics [/edit]
1.
sendmail : /usr/lib/sendmail
/usr/sbin/sendmail
(Correct me if I'm wrong) this appears to be two locations to sendmail, or one is an alias, you can try changing it to the first one.
2. One common error on uploading scripts: if you are using a program like WS_FTP to upload this script, be sure it's in ASCII mode.
3. Another one I see frequently: PC end of line characters and Unix end of line characters are different. If the FTP program does not correctly convert the PC EOL's to Unix, this will cause an error. This is especially true if you use Notepad to edit your scripts. The best solution is to use a program like HomeSite to save your files in Unix format.
4. Check your script extension. Some servers are only configured to execute scripts with .cgi or .pl extensions, and often exclude one or the other.
5. I totally, completely agree w. perl_diver on this one, trust me, you don't need this kind of headache.
Let me give you one scenario: using this script, as posted, will allow a potential hacker to do something like this:
To: email1@example.com \n BCC: spam1@example.com,spam2@example.com,.....
Note the newline \n after the to address, followed by the BCC. In reality, they do something more complex to create the newline, but it's enough to exemplify. What I've done here, is created MY OWN BCC field using your headers.
I've only put two "spam" addresses. Imagine this X 1000. What happens?
BCC means "blind carbon copy." You get one email, and don't "see" any of the addresses in BCC. Because it's a BCC, you don't even know you have a problem, which is just what the spammers want.
1000 unsuspecting email users on example.com get an email. example.com says, "AH! Someone's spamming us from yoursite.com! Block all emails from yoursite.com!"
They then complain to your ISP that someone on their servers is spamming them. It's now the ISP's problem, and they will pull your plug in an instant. Your web site goes down until you find a new home for it.
This is only one of the MANY holes in this simple script. I learned of this early on in my career the hard way, and wished a million times over someone had bonked me up-side the head and told me what I was getting into.
We're telling you now. Find something else. Best of luck . . . .
perl_diver - There are no syntax errors in the perl code you posted. But, word of advise, do not use the guestbook script. It will be abused so fast you will regret the day you put it on your server. No security what so ever and bots will start spamming your server. Its a disaster waiting to happen.
What is an alternative option to the Guest Book you suggest would be a safe way to get a feedback from users/visitors?
---------------------------
rocknbil - I change the path to sendmail between two above, and use .pl or .cgi vice versa, there is no luck. What would be your best advice in the above senario. If there is nothing wrong with my perl codes (it did work in the previous hosting server), and technician claimed that his Perl server runs perfectly, what would your best advice?
Cheers
create a file hello.cgi in your server root directory:
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);# add any new code after this print statement
print "Content-type: text/html\n\n";hello_html_doc;
sub hello_html_doc {
print "<html>\n";
print "<head>\n";
print "<title>Hello, World!</title>\n";
print "</head>\n";
print "<body>\n";
print "hello, world!\n";
print "</body>\n";
print "</html>\n";
}
if that works, start adding your code until it breaks.
It did not work. the error message is the same as before:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@example.co.uk 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.
-----------------
I tried to place the file you suggested in both root directory or in cgi-bin directory. I think it is a problem with the server which is denied by the technician?
Any advice?
[edited by: phranque at 12:22 am (utc) on July 16, 2008]
[edit reason] examplified url [/edit]
do the location, permissions and ownership of the hello.cgi test script match those of your technician's test script?
What you mean by that?
---------------------------------
I set the file attributes of hello.cgi/hello.pl to 775; transferred it as ASCII using CuteFTP 8.0 professional; placed it in either root directory or cgi-bin folder, but there is no luck. The same error message is received as above.
Any advice?
#!/usr/local/bin/perl
use CGI::Carp qw(fatalsToBrowser);
# add any new code after this print statement
print "Content-type: text/html\n\n";
hello_html_doc;
sub hello_html_doc {
print "<html>\n";
print "<head>\n";
print "<title>Hello, World!</title>\n";
print "</head>\n";
print "<body>\n";
print "hello, world!\n";
print "</body>\n";
print "</html>\n";
}
Any advice?