#!/bin/sh # cacophony by C. Duckworth --- hereby released to the public domain SCRIPTDIR=/home/acdw/www crlf() { # crlf < INPUT ## Convert LF to CRLF sed 's/$/ /g' } log() { # log MESSAGE ... printf >&2 '%s\n' "$*" } http_header() { # http_header [STATUS] [MIMETYPE] [CHARSET] cat <
this page is a program served by cacophony. FOOTER } hcat() { # hcat [STATUS] < INPUT case "$(file -)" in *HTML*) http_header "{1:-200}" ;; *) http_header "${1:-200}" text/plain ;; # todo: smarter esac cat } hexec() { # hexec PROGRAM [http_header args] prog="$1" shift http_header "$@" "$prog" html_footer "$prog" } run() { # run pag="$PWD$PATH_INFO" src="$SCRIPTDIR$PATH_INFO" if test / = "$PATH_INFO" then PATH_INFO=/index run elif ! test -d "$pag" && test -x "$src" then hexec "$src" 200 elif ! test -d "$pag" && test -r "$pag" then hcat 200 < "$pag" elif test -d "$pag" && test -r "$pag/index.html" then hcat 200 < "$pag/index.html" else case "$PATH_INFO" in /src/*) hcat 200 < "$SCRIPTDIR/${PATH_INFO#/src/}" ;; *) http_header 404 ;; esac fi } run