f18743956e9607ce88fe019254b7fd67759c378a
[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 . "$_EXEC/cgilite/session.sh"
14
15 _PATH="$(PATH "/${PATH_INFO}")"
16 ACTION="$(GET a)"
17
18 message="$(COOKIE message)"
19 [ "$message" ] && SET_COOKIE 0 message=''
20
21 yield_page() {
22   local class="$1" style="$2"
23   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
24   { printf '
25         [html [head
26           [meta name="viewport" content="width=device-width"]
27           [link rel="stylesheet" type="text/css" href="/style.css"]
28     '
29     [ -n "$style" ] && printf '
30           [link rel="stylesheet" type="text/css" href="%s"]
31     ' "$style"
32     printf '
33         ] [body class="%s"
34     ' "$class"
35     cat
36     [ "$message" ] && printf '[p #message\n%s\n]' $(l10n "$message")
37     printf '] ]'
38   } \
39   | "${_EXEC}/cgilite/html-sh.sed"
40 }
41
42 if   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/main.cgi" ]; then
43   . "${_EXEC}/${_PATH}/main.cgi"
44 elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
45   . "${_EXEC}/${_PATH}"
46 elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
47   . "$_EXEC/cgilite/file.sh"
48   FILE "${_EXEC}/${_PATH}"
49 else
50   printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
51 fi