Forum

CGI not working

maxter
19 June 2012, 12:40
Hiawatha version: 8.3.2
Operating System: linux

Hello!

I've compiled Hiawatha for linux running on ARM processor. HTML pages work OK, but when I try to use CGI, I get a mesage "500 - Internal server error".

Here is the content of the HTML page index.html

<!DOCCTYPE html>
<html>
<head>
<title>Hello HTML</title>
</head>
<body>
<form action="cgi-bin/test.cgi">
<div><label>Multiplicand 1: <input name="m" size="5"></label></div>
<div><label>Multiplicand 2: <input name="n" size="5"></label></div>
<div><input type="submit" value="Multiply!"></div>
</form>
</body>
</html>

And here is the content of the file test.cgi
#!/bin/sh

echo "Content-type:text/html\r\n\r\n"
echo "<html>"
echo "<head>"
echo "<title>Hello Word - First CGI Program</title>"
echo "</head>"
echo "<body>"
echo "<h2>Hello Word! This is my first CGI program</h2>"
echo "</body>"
echo "</html>"


Here is my config file
# Hiawatha main configuration file
#


# GENERAL SETTINGS
#
#ServerId = www-data
ConnectionsTotal = 150
ConnectionsPerIP = 10
SystemLogfile = /etc/hiawatha/system.log
GarbageLogfile = /etc/hiawatha/garbage.log


# BINDING SETTINGS
# A binding is where a client can connect to.
#
Binding {
Port = 80
# Interface = 127.0.0.1
# MaxKeepAlive = 30
# TimeForRequest = 3,20
}
#
#Binding {
# Port = 443
# Interface = ::1
# MaxKeepAlive = 30
# TimeForRequest = 3,20
# SSLcertFile = hiawatha.pem
#}


# BANNING SETTINGS
# Deny service to clients who misbehave.
#
#BanOnGarbage = 300
#BanOnMaxPerIP = 60
#BanOnMaxReqSize = 300
#KickOnBan = yes
#RebanDuringBan = yes


# COMMON GATEWAY INTERFACE (CGI) SETTINGS
# These settings can be used to run CGI applications. Use the 'php-fcgi'
# tool to start PHP as a FastCGI daemon.
#
#CGIhandler = /usr/bin/perl:pl

#CGIhandler = /bin/sh:sh
#CGIhandler = /usr/bin/php-cgi:php
#CGIhandler = /usr/bin/python:py
#CGIhandler = /usr/bin/ruby:rb
#CGIhandler = /usr/bin/ssi-cgi:shtml
CGIextension = cgi
#
#FastCGIserver {
# FastCGIid = PHP5
# ConnectTo = 127.0.0.1:2005
# Extension = php
#}


# URL TOOLKIT
# This URL toolkit rule was made for the Banshee PHP framework, which
# can be downloaded from http://www.hiawatha-webserver.org/banshee
#
#UrlToolkit {
# ToolkitID = banshee
# RequestURI isfile Return
# Match ^/(css|files|images|js|slimstat)($|/) Return
# Match ^/(favicon.ico|robots.txt|sitemap.xml)$ Return
# Match .*\?(.*) Rewrite /index.php?$1
# Match .* Rewrite /index.php
#}


# DEFAULT WEBSITE
# It is wise to use your IP address as the hostname of the default website
# and give it a blank webpage. By doing so, automated webscanners won't find
# your possible vulnerable website.
#
Hostname = 127.0.0.1
WebsiteRoot = /home/root/www/hiawatha
StartFile = index.html
ExecuteCGI = yes
AccessLogfile = /etc/hiawatha/access.log
ErrorLogfile = /etc/hiawatha/error.log
#ErrorHandler = 404:/error.cgi


# VIRTUAL HOSTS
# Use a VirtualHost section to declare the websites you want to host.
#
#VirtualHost {
# Hostname = www.my-domain.com
# WebsiteRoot = /home/root/www/hiawatha
# StartFile = index.html
# AccessLogfile = /home/root/www/hiawatha/access.log
# ErrorLogfile = /home/root/www/hiawatha/error.log
# ExecuteCGI = yes
# TimeForCGI = 5
# UseFastCGI = PHP5
# UseToolkit = banshee
#}


# DIRECTORY SETTINGS
# You can specify some settings per directory.
#
#Directory {
# Path = /home/root/www/hiawatha/cgi-bin
# ExecuteCGI = yes
# UploadSpeed = 10,2
#}

I couldn't find answer for my question so could you, please, help me with it.
maxter
19 June 2012, 12:42
Another thing. After the attempt to execute this cgi program, I see the following string in error.log

192.168.100.24|Fri 25 Mar 2011 16:35:04 +0000|/home/root/www/hiawatha/cgi-bin/test.cgi|CGI only printed a HTTP header, no content
Hugo Leisink
22 June 2012, 13:40
My guess is that Hiawatha, which is running as user 'nobody', can't access files in /home/root. Otherwise, I have no idea what goes wrong.
maxter
24 July 2012, 11:48
Unfortunately that's not the reason. Thank you for your suggestion. Any other ideas?
Hugo Leisink
24 July 2012, 18:51
I'm afraid not...
Nick Coleman
10 August 2012, 17:35
Possibly the \r\n\r\n. Should be \n\n, shouldn't it? That would explain the "CGI only printed a header" message.
Hugo Leisink
10 August 2012, 20:49
The correct way to end a CGI header line is by using \r\n. To end the complete CGI header is to also use \r\n. So, \r\n\r\n at the end is the correct one.
This topic has been closed.