drop pasted card info from course functions
[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 checked(){  [ "$1" = "$2" ] || [ "$1" -eq "$2" ] && printf 'checked="checked"' 2>/dev/null; }
22 selected(){ [ "$1" = "$2" ] || [ "$1" -eq "$2" ] && printf 'selected="selected"' 2>/dev/null; }
23
24 yield_page() {
25   local class="$1" style="$2"
26   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
27   { printf '
28         [html [head
29           [title Confetti]
30           [meta name="viewport" content="width=device-width"]
31           [link rel="stylesheet" type="text/css" href="/style.css"]
32     '
33     [ -n "$style" ] && printf '
34           [link rel="stylesheet" type="text/css" href="%s"]
35     ' "$style"
36     printf '
37         ] [body class="%s"
38     ' "$class"
39     cat
40     [ "$message" ] && printf '[p #message\n%s\n]' $(l10n "$message")
41     printf '] ]'
42   } \
43   | "${_EXEC}/cgilite/html-sh.sed"
44 }
45
46 if   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/index.cgi" ]; then
47   . "${_EXEC}/${_PATH}/index.cgi"
48 elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
49   . "${_EXEC}/${_PATH}"
50 elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
51   . "$_EXEC/cgilite/file.sh"
52   FILE "${_EXEC}/${_PATH}"
53 else
54   printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
55 fi