OpenBSD - HTTPD CGI

Page content

Let’s have a look a the old and simple “cgi-bin” stuff on OpenBSD. The Webserver is written by the OpenBSD Guys, and it runs in a chrooted environment.

switch to cgi-bin dir

cd /var/www/cgi-bin/

ip.cgi

create the file under /var/www/cgi-bin called ‘ip.cgi’

cat << 'EOG' > ip.cgi
#!/bin/sh
cat << EOF
Content-type: text/html

<html><head>
<title>IP: $REMOTE_ADDR</title>
</head><body>
<p>Your IP address is: $REMOTE_ADDR</p>
</body></html>
EOF
EOG

Set Owner & Permission

chmod 500 ip.cgi
chown www ip.cgi

as we have the command “cat” in the Script, we need to have this binary in the chrooted HTTP of OpenBSD as well.

copy Binary & set owner & permission

cp $(which cat) /var/www/bin/
chmod 500 /var/www/bin/cat
chown www /var/www/bin/cat

tmp Dir

the “cat” command writes it’s data to a /tmp Directory first. So, we need to create this directory if not existing.

mkdir /var/www/tmp
chown www /var/www/tmp

enable & restart httpd, slowcgi

rcctl enable httpd slowcgi
rcctl restart httpd slowcgi

and we’re done. just open the Browser and surf to your website: https://anycast.stoege.net/cgi-bin/ip.cgi

debug httpd

in case of problems (the /tmp directory for example, was not aware of) just do the follwoing:

rcctl stop httpd
httpd -vvvvv && tail -f /var/www/logs/access.lgog

Any Comments ?

sha256: 00a2005dd7370ce479c570c9ffaae06d9fcff5c9df2b46fb8c64fe10af4699c0