Subject: Re: CVS commit: src/libexec/httpd
To: None <source-changes@netbsd.org>
From: Karsten Kruse <tecneeq@gmx.net>
List: source-changes
Date: 10/17/2007 00:08:23
Mindaugas R. schrieb:
>> Update of /cvsroot/src/libexec/httpd
What i needed a thousand times in base (read: before pkgsrc was there) was
a webbrowser. I think w3m is a BSD licensed one.
>> Import of bozohttpd for its originally intended purpose: a small (~30k)
>> simple run-from-inetd httpd suitable for small systems (and some large
>> ones).
This httpd works fine with NetBSD and is only ~1,5 k:
#!/bin/sh -e
# httpd.sh - Very small webserver
# Karsten Kruse 2004 2005 www.tecneeq.de
# Idea from httpd.ksh www.shelldorado.com
#
# 1) Save this file as /usr/sbin/httpd.sh
# 2) Put this into /etc/inetd.conf:
# 80 stream tcp nowait nobody /usr/sbin/httpd.sh
# 3) Let inetd reread it's configuration:
# /etc/rc.d/inetd reload
# 4) Set the document root
root=${HTTP_DOC_ROOT:-/home/httpd/htdocs/}
gettype(){
case "$1" in
*.xhtml|*.html|*.htm|*.XHTML|*.HTML|*.HTM) type="text/html" ;;
esac
echo ${type:-$(file -i "$1" | awk '{print $2}' | sed 's/;//')}
}
while read line ; do
[ "$line" = "$(printf \r\n)" ] && break # end of request header
[ -z $requestline ] && requestline="$line" && break
done
set -- $requestline
doc="$root/$2"
[ -d "$doc" ] && doc="$doc/index.html"
if [ "$1" != GET ] ; then
printf "HTTP/1.0 501 Not implemented\r\n\r\n501 Not implemented\r\n"
elif expr "$doc" : '.*/\.\./.*' >/dev/null ; then
printf "HTTP/1.0 400 Bad Request\r\n\r\n400 Bad Request\r\n"
elif [ ! -f "$doc" ] ; then
printf "HTTP/1.0 404 Not Found\r\n\r\n404 Not Found\r\n"
elif [ ! -r "$doc" ] ; then
printf "HTTP/1.0 403 Forbidden\r\n\r\n403 Forbidden\r\n"
elif [ -r "$doc" -a -f "$doc" ] ; then
printf "HTTP/1.0 200 OK\r\nContent-type: $(gettype "$doc")\r\n"
printf "Content-Length: $(wc -c < "$doc")\r\n\r\n"
exec cat "$doc"
else
printf "HTTP/1.0 500 Server Error\r\n\r\n500 Server Error\r\n"
fi
# eof
MFG,
Karsten Kruse
--
()
<\/> GPL-guy: "Argh, they used my code! :-/"
_/\_ BSD-guy: "Cool, they used my code! :-)"