diff options
Diffstat (limited to 'cacophony.sh')
-rwxr-xr-x | cacophony.sh | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/cacophony.sh b/cacophony.sh index 7cf4dc3..f893a60 100755 --- a/cacophony.sh +++ b/cacophony.sh | |||
@@ -1,4 +1,5 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | # cacophony by C. Duckworth --- public domain | ||
2 | 3 | ||
3 | SCRIPTDIR=source | 4 | SCRIPTDIR=source |
4 | 5 | ||
@@ -7,7 +8,7 @@ crlf() { # crlf < INPUT | |||
7 | sed 's/$/ /g' | 8 | sed 's/$/ /g' |
8 | } | 9 | } |
9 | 10 | ||
10 | header() { # header [STATUS] | 11 | http_header() { # header [STATUS] |
11 | cat <<HEADER | crlf | 12 | cat <<HEADER | crlf |
12 | HTTP/1.1 ${1:-200} | 13 | HTTP/1.1 ${1:-200} |
13 | Content-Type: text/html;charset=utf-8 | 14 | Content-Type: text/html;charset=utf-8 |
@@ -15,20 +16,32 @@ Content-Type: text/html;charset=utf-8 | |||
15 | HEADER | 16 | HEADER |
16 | } | 17 | } |
17 | 18 | ||
19 | html_footer() { # footer PROGRAM | ||
20 | cat <<EOF | ||
21 | <footer> | ||
22 | copyright (C) $(stat -c %y "$1" | cut -d- -f1) Case Duckworth. | ||
23 | this page is a <a href="$SCRIPTDIR/${1##*/}">program</a> | ||
24 | served by <a href="https://git.acdw.net/cacophony">cacophony</a>. | ||
25 | </footer> | ||
26 | </body></html> | ||
27 | EOF | ||
28 | } | ||
29 | |||
18 | hexec() { # hexec PROGRAM [header args] | 30 | hexec() { # hexec PROGRAM [header args] |
19 | prog="$1"; shift | 31 | prog="$1"; shift |
20 | header "$@" | 32 | http_header "$@" |
21 | exec "$prog" | 33 | "$prog" |
34 | html_footer "$prog" | ||
22 | } | 35 | } |
23 | 36 | ||
24 | run() { | 37 | run() { # run |
25 | if test / = "$PATH_INFO" | 38 | if test / = "$PATH_INFO" |
26 | then PATH_INFO=/index run | 39 | then PATH_INFO=/index run |
27 | else | 40 | else |
28 | path="$PWD/$SCRIPTDIR$PATH_INFO" | 41 | path="$PWD/$SCRIPTDIR$PATH_INFO" |
29 | if ! test -d "$path" && test -x "$path" | 42 | if ! test -d "$path" && test -x "$path" |
30 | then hexec "$path" 200 | 43 | then hexec "$path" 200 |
31 | else header 404 | 44 | else http_header 404 |
32 | fi | 45 | fi |
33 | fi | 46 | fi |
34 | } | 47 | } |