12f59b299db03c715539a229c965f0e63e73cc59
[confetti] / index.cgi
1 #!/bin/sh
2
3 for n in "$@"; do case ${n%%=*} in
4   data) _DATA="${n#data=}";;
5   exec) _exec="${n#exec=}";;
6   noerr) exec 2>&-;;
7 esac; done
8
9 [ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
10 [ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
11
12 . "$_EXEC/cgilite/cgilite.sh"
13
14 _PATH="$(PATH "/${PATH_INFO}")"
15 ACTION="$(GET a)"
16
17 yield_page() {
18   local class="$1" style="$2"
19   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
20   { printf '
21         [html [head
22           [meta name="viewport" content="width=device-width"]
23           [link rel="stylesheet" type="text/css" href="/style.css"]
24     '
25     [ -n "$style" ] && printf '
26           [link rel="stylesheet" type="text/css" href="%s"]
27     ' "$style"
28     printf '
29         ] [body class="%s"
30     ' "$class"
31     cat
32     printf '] ]'
33   } \
34   | "${_EXEC}/cgilite/html-sh.sed"
35 }
36
37 if   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/main.cgi" ]; then
38   . "${_EXEC}/${_PATH}/main.cgi"
39 elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
40   . "${_EXEC}/${_PATH}"
41 elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
42   . "$_EXEC/cgilite/file.sh"
43   FILE "${_EXEC}/${_PATH}"
44 else
45   printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
46 fi