![]() | :: | Software | :: | shttpd |
cgi-httpd progwhere prog is one or more arguments specifying a program to run for each valid request.
cgi-httpd reads an HTTP request message from standard input, and treats the URI path as the name of a CGI script. The script is expected to print its reply to standard output.
Before reading any input, cgi-httpd changes the working directory to that named in the $ROOT environment variable, performs chroot to the current directory, and then sets its group id and user id to the numeric values given in the environment variables $GID and $UID, typically set with envdir. Before executing prog, cgi-httpd sets the execution path to /bin. If it cannot carry out these operations, cgi-httpd complains to standard output and exits 111.
If it encounters an error in processing a request, cgi-httpd exits 21. Otherwise, it returns the exit code of prog.
For a request specifying the hostname H, cgi-httpd changes its working directory to ./host/H after replacing /. with /: and // with / in ./host/H. When a valid request lacks a host name, cgi-httpd uses 0 as the host name. After changing the working directory, cgi-httpd sets the cgi environment variables and executes prog.
cgi-httpd accepts HTTP/0.9, HTTP/1.0, and HTTP/1.1 requests. It supports HEAD, GET, and POST, and rejects all other methods.
cgi-httpd manipulates the following environment variables:
$AUTH_TYPE is unset.
$CONTENT_LENGTH is the content length of the request, if applicable, or unset.
$CONTENT_TYPE is the content type of the request, if applicable, or unset.
$GATEWAY_INTERFACE is the string CGI/1.1
$PATH_INFO is the path portion of the request URI, after URL decoding.
$PATH_TRANSLATED is unset.
$QUERY_STRING is the query string portion of the request URI.
$REMOTE_ADDR is set to the value of the environment variable $TCPREMOTEIP.
$REMOTE_HOST is set to the value of the environment variable $TCPREMOTEHOST.
$REMOTE_USER is set to the value of the environment variable $TCPREMOTEINFO.
$REQUEST_METHOD is set to the method of the request URI.
$SCRIPT_NAME is the empty string.
$SERVER_NAME is the name of the host given in the request, if applicable, and 0 otherwise.
$SERVER_PORT is the value of the environment variable $TCPLOCALPORT.
$SERVER_PROTOCOL is one of the strings HTTP/0.9, HTTP/1.0, or HTTP/1.1.
$SERVER_SOFTWARE is the string cgi-httpd.
Create a directory to house shttpd service directories, for example:
mkdir /usr/local/shttpd/service
Configure a cgi-example server to listen on a port of your choice:
cgi-config shttp shttplog /usr/local/shttpd/service/cgi-example port cgi-example
Copy cgi-example to /usr/local/shttpd/service/cgi-example/root/bin.
Download and compile the miscellanea package. Copy the executables foldlines, revline, rot13, and wrapcr to /usr/local/shttpd/service/cgi-example/root/bin.
For each hostname you wish accept in requests, create the directory /usr/local/shttpd/service/cgi-example/root/host/hostname.
Finally, start the service under svscan:
ln -s /usr/local/shttpd/service/cgi-example /service
You can test the cgi-example server here.
Documentation for the programs used by the example server is here.