LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-25-2017, 10:46 AM   #1
phipm1
LQ Newbie
 
Registered: May 2017
Posts: 20

Rep: Reputation: Disabled
Premature end of script headers formail


I am migrating our internal webserver over from UNIX to Linux.

we are using formmail.cgi for html forms.

I keep getting Premature end of script headers error in the logs and in your browser you get an internal server error when trying to submit a html form.


file ownership is 755, there are no typos in the referrers and the domain is also listed in the referrers.

Any suggestions of what else to look at?
 
Old 05-25-2017, 05:04 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,425

Rep: Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054
Two possibilities in my experience:
1. the #! line is missing or pointed to the wrong place (is formmail.cgi the same as formmail.pl -- that is, is it a perl script?)
Code:
which perl
make the #! the same as the result of that

2. the file contains CRLF line ends (\r\n -- "DOS line ends") instead of l/unix LF (\n). This can happen if the script was uploaded (FTP/SFTP) from a Windows PC in binary mode instead of ascii mode [AFAIK, the ONLY thing ascii mode does is convert the line ends]
A quick way to check that is to open the script in vi/vim. If the line ends are CRLF, it will display ^M at the ends of the lines.

It's also possible that the web directory doesn't allow CGI, but I don't think that will give you the "Premature end of script headers" error. Be sure it has:
Code:
<Directory /var/www/somedirectory/cgi-bin>
AllowOverride None
Options ExecCGI
</Directory>
It would be helpful to know what error number the web server is throwing.

Last edited by scasey; 05-25-2017 at 05:06 PM.
 
Old 05-25-2017, 06:44 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Never heard of FormMail before but I thought I would check it out. I downloaded the script and wrote a short form to call it. I get an additional error:
Code:
[Thu May 25 18:36:29.685511 2017] [cgi:error] [pid 844] [client 192.168.2.3:36172] AH01215: Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) at /usr/lib/cgi-bin/FormMail.pl line 243.: /usr/lib/cgi-bin/FormMail.pl, referer: http://192.168.2.3/perl/formmail.html
[Thu May 25 18:36:29.686511 2017] [cgi:error] [pid 844] [client 192.168.2.3:36172] End of script output before headers: FormMail.pl, referer: http://192.168.2.3/perl/formmail.html
Omitting "defined" as the above recommends eliminated the errors.

HTH
 
Old 05-26-2017, 09:18 AM   #4
phipm1
LQ Newbie
 
Registered: May 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi

I'm using vi to edit the file so I don't have ^M at the end of the rows

this is what I have:

<Directory "/htdocs/thesource/corp/cgi-bin">
Options Indexes FollowSymLinks +ExecCGI +Includes
XBitHack full
AllowOverride None
Order allow,deny
Allow from all

I have the domain added in the referrer as well

Log file:

[Fri May 26 08:16:29 2017] [error] (2)No such file or directory: exec of '/cgi-bin/FormMail_original.cgi' failed
[Fri May 26 08:16:29 2017] [error] [client 10.226.40.1:54192] Premature end of script headers: FormMail_original.cgi, referer: http://XXX.stholdco.com/corp/tools/feedback.htm
 
Old 05-26-2017, 12:51 PM   #5
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Add "use warnings" at the top of "FormMail_original.cgi" to see if that gives you a more descriptive error:
Code:
#!/usr/bin/perl
use warnings;
 
Old 05-26-2017, 01:06 PM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,490

Rep: Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532
premature end usually means you have a pair of delimiters (like <tag> </tag> or anything else) and the closing delimiter was not found. In your post #4 it can be </Directory>, but you did not post the whole script, so it is only a wild guess. From the other hand you posted a file not found ('/cgi-bin/FormMail_original.cgi'). I think that is not /cgi-bin, there should be something before that, probably an environment variable or other settings which is missing/not properly set.
 
Old 05-26-2017, 01:53 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,425

Rep: Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054
Quote:
Originally Posted by phipm1 View Post
Log file:

[Fri May 26 08:16:29 2017] [error] (2)No such file or directory: exec of '/cgi-bin/FormMail_original.cgi' failed
[Fri May 26 08:16:29 2017] [error] [client 10.226.40.1:54192] Premature end of script headers: FormMail_original.cgi, referer: http://XXX.stholdco.com/corp/tools/feedback.htm
OK! That error is saying, pretty clearly, that the web server (Apache?) can't find the file specified in the <form action tag Please post that line from the web page.
A guess, based on the error:
Code:
 <form method='POST' action="/cgi-bin/FormMail_original.cgi">
Your snippet from the httpd.conf:
Code:
<Directory "/htdocs/thesource/corp/cgi-bin">
Is /htdocs/thesource/corp/ the DocumentRoot for the domain? The error is indicating that either the /cgi-bin path is not directly under the DocumentRoot OR there is no script named FormMail_original.cgi in that directory. In your original post you said formmail.cgi

Last edited by scasey; 05-26-2017 at 02:00 PM.
 
Old 05-26-2017, 02:28 PM   #8
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Quote:
Originally Posted by scasey View Post
It would be helpful to know what error number the web server is throwing.
Amen. Do you get "404 Not Found" or "500 Internal Server Error"?

I'm guessing it's line endings as Sean stated in post #2 and "#!/usr/bin/perl^M" is failing.

My server outputs "AH02811: script not found or unable to stat:" if it can't find the file.

Last edited by norobro; 05-26-2017 at 02:29 PM.
 
Old 05-26-2017, 03:46 PM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,425

Rep: Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054
off-topic: about FormMail

Matt Wright's FormMail script is very well written and very secure, if implemented properly. However every cracker in the world knows about it, and, since it's open source, can often find ways to break in and abuse it.
On the sites I maintain, I have added one more step to help prevent that abuse...I rename the script to something else.
Just thought I'd pass that on.

Oh, and my bad...Welcome to LQ phipm1 Enjoy!

Last edited by scasey; 05-26-2017 at 03:51 PM.
 
Old 05-26-2017, 04:12 PM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,425

Rep: Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054
Quote:
Originally Posted by norobro View Post
Amen. Do you get "404 Not Found" or "500 Internal Server Error"?

I'm guessing it's line endings as Sean stated in post #2 and "#!/usr/bin/perl^M" is failing.

My server outputs "AH02811: script not found or unable to stat:" if it can't find the file.
phipm1 posted the entries from the apache error log, which doesn't record the error codes. We'd need to see the corresponding entry from the access log, which would show the error code.

When I set up the situation of a not found script on my server, I get a 404 error in the access log, and
Code:
script not found or unable to stat:
in the error log. I do NOT get Premature end of script headers. Hmmm

I get exactly the same error as phipm1 when I munge the #! in the formmail script (!!)
Have you (phipm1) confirmed that the #! is pointing correctly to perl? It could be in a different place on your new OS than it was in your UNIX installation.

Last edited by scasey; 05-26-2017 at 04:38 PM.
 
Old 05-29-2017, 08:00 AM   #11
phipm1
LQ Newbie
 
Registered: May 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
The path to perl is correct #!/usr/bin/perl


I get a internal 500 error

this is the error message in the log

[error] (2)No such file or directory: exec of '/cgi-bin/FormMail.cgi' failed
[error] Premature end of script headers: FormMail.cgi, referer: http://xxx.domain.com/corp/tools/feedback.htm


the domain is in the referrer as well as the correct path to feedback.htm page
 
Old 05-29-2017, 10:59 AM   #12
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,425

Rep: Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054
Quote:
Originally Posted by phipm1 View Post
The path to perl is correct #!/usr/bin/perl


I get a internal 500 error

this is the error message in the log

[error] (2)No such file or directory: exec of '/cgi-bin/FormMail.cgi' failed
[error] Premature end of script headers: FormMail.cgi, referer: http://xxx.domain.com/corp/tools/feedback.htm


the domain is in the referrer as well as the correct path to feedback.htm page
and
Code:
which perl
gives you the same thing as in the #! line?


If so, then I'm stumped. A mis-directed or munged #! line is the only thing I can replicate the error with.

Please also confirm the action in the form tag in feedback.htm matches the file name in cgi-bin ...you've posted two different spellings of the script. Still, a missing script doesn't give the exec failed and Premature end of script headers (on my apache server anyway)

Last edited by scasey; 05-29-2017 at 11:02 AM.
 
Old 06-12-2017, 04:04 PM   #13
phipm1
LQ Newbie
 
Registered: May 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
as stated previously perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
 
Old 06-12-2017, 04:06 PM   #14
phipm1
LQ Newbie
 
Registered: May 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
I'm still trying to get Formmail to work. So I have built a basic web server but still getting no where.

Why would I be getting error

[Mon Jun 12 14:59:43 2017] [error] [client 10.226.40.1:62454] File does not exist: /htdocs/michelle2/htdocs, referer: http://thesourceqa.stholdco.com/

/htdocs/michelle2 is the doc root of the webserver where would it be picking up the 2nd htdocs from?

directory is this, as well as the html files
 
Old 06-12-2017, 05:55 PM   #15
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,425

Rep: Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054Reputation: 2054
Quote:
Originally Posted by phipm1 View Post
as stated previously perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
I'm sorry, that looks like a selection from the results of the command
Code:
perl -V
I'm asking you for the results of the command
Code:
which perl
that should display the absolute path to the perl executable, i.e.:
Code:
/usr/bin/perl
...that needs to match the absolute path on the #! line in the formmail script.
Does it?

Last edited by scasey; 06-12-2017 at 06:22 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Premature End of Script Headers yuri16 Linux - Newbie 3 05-26-2009 03:03 AM
Premature end of script headers: CGI fatturi Linux - Newbie 4 07-19-2007 04:55 PM
Premature end of script headers bhomass Debian 1 12-02-2005 05:31 PM
Premature end of script headers webhead Red Hat 5 09-22-2004 01:56 AM
Perl/CGI Problem "Premature Premature end of script headers: countdown.pl" newuser455 Linux - Software 2 07-18-2004 11:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration