OpenWrt Forum Archive

Topic: Got stuck mini_httpd with haserl and cgi

The content of this topic has been archived on 28 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi folks,

I just want to run some cgi scripts on my router (i.e. wrtstats) and got stuck. I've tried some different web-servers (thttpd, lighttpd) and now run mini_httpd from Nico. It works fine (SSL only?), but I can't run cgi-scripts. What I've done so far:

put a # in front of /usr/sbin/httpd in S50 httpd, so internal daemon will not be started, verified with ps:no process httpd
installed mini_httpd with ipkg install - this installed itself the required libmatrixssl,libopenssl and so on
installed haserl
chmod 777 to /www/cgi-bin

Now I can get static html pages well. But on loading any cgi related I always get
500 Internal Error - Something unexpected went wrong running a CGI program.
mini_httpd/1.19 19dec2003

When starting mini_httpd it says 'socket: Address family not supported by protocol'
Whats going wrong? Can anyone help me?
Thanks!
Matze

Ok, so basically, you have to follow these steps to run a haserl interpreted cgi script.

1) Your script should have the following HTML structure :

#!/usr/bin/haserl -u
content-type: text/html
--------------------------------------------- first line -------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
Headers
</head>
------------------------------------------- second line -------------------------------------------------------------
<body>
<table>
<?
free_ram=$(/usr/bin/free | awk '{ print $4}' | tail -1)
?>

Note that it is really important to have these 2 lines, many times I went into trouble don't understanding why I was having type 500 errors.

Then, download your file as you usually do : via http, ftp, scp ...

Place it in /www/cgi-bin/, and finally, after having renamed it to *.cgi, toggle it executable :

chmod +x /www/cgi-bin/*.cgi

Hope this helps, but be sure that if you get error 500, it is either because your HTML structure is incorrect regarding the haserl rules, or it is not executable.

Thanks for your help, but doesn't change anything :-(
Do you know the meaning of the message  'socket: Address family not supported by protocol' when starting mini_httpd ?
Maybe my general problems rely on something else: I use the experimental-general-4mb version 2505. Seems there's missing some code to get cgi working...

You must follow theese steps to use the default configuration which IS working.
Use the supplied init-script, it will lauch mini-httpd with the default config. file :

/etc/init.d/mini-httpd start

then create a directory in your /www root with reasonable permissions:

mkdir -p /www/cgi-bin
chmod 0755 /www/cgi-bin

put you script in there, with appropriate permissions for an executable script:

touch /www/cgi-bin/test.cgi
chmod 0755 /www/cgi-bin/test.cgi

edit the script:

vi /www/cgi-bin/test.cgi

and put some haserl in it. The example supplied by RItalMan should work.
an even simplier example would be:

#!/usr/bin/haserl
Content-Type: text/plain

OK

Like busybox httpd, mini-httpd is configured to run cgi only if they're found in a "cgi-bin" directory. If you decide something else, you should adjust "cgipat" in /etc/mini_httpd.conf.

The discussion might have continued from here.