styling for course page
[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 debug() {
13   local dbg=/dev/stderr
14   if [ ! "$DEBUG" ]; then
15     [ "$#" -gt 0 ] && : || cat;
16   elif [ "$#" -gt 0 ]; then
17     printf '%s\n' "$@" >>"$dbg"
18   else
19     tee -a "$dbg"
20   fi
21 }
22
23 . "$_EXEC/cgilite/cgilite.sh"
24 . "$_EXEC/cgilite/session.sh"
25
26 _PATH="$(PATH "/${PATH_INFO}")"
27 ACTION="$(GET a)"
28
29 message="$(COOKIE message)"
30 [ "$message" ] && SET_COOKIE 0 message=''
31
32 checked(){
33   if [ "$1" = "$2" ] || [ "$1" -eq "$2" ]; then
34     printf 'checked="checked"'
35   fi 2>/dev/null
36 }
37 selected(){
38   if [ "$1" = "$2" ] || [ "$1" -eq "$2" ]; then
39     printf 'selected="selected"'
40   fi 2>/dev/null
41 }
42
43 yield_page() {
44   local class="$1" style="$2"
45   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
46   { printf '
47         [html [head
48           [title Confetti]
49           [meta name="viewport" content="width=device-width"]
50           [link rel="stylesheet" type="text/css" href="/style.css"]
51     '
52     [ -n "$style" ] && printf '
53           [link rel="stylesheet" type="text/css" href="%s"]
54     ' "$style"
55     printf '
56         ] [body #top class="%s"
57     ' "$class"
58     cat
59     [ "$message" ] && printf '[p #message\n%s\n]' "$(l10n "$message")"
60     printf '] ]'
61   } \
62   | "${_EXEC}/cgilite/html-sh.sed"
63 }
64
65 topdir="${_PATH#/}"
66 topdir="/${topdir%%/*}"
67
68 if [ "${_PATH}" = / ]; then
69   REDIRECT /cards/
70 elif   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/index.cgi" ]; then
71   . "${_EXEC}/${_PATH}/index.cgi"
72 elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
73   . "${_EXEC}/${_PATH}"
74 elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
75   . "$_EXEC/cgilite/file.sh"
76   FILE "${_EXEC}/${_PATH}"
77 elif   [   -d "${_EXEC}/${topdir}" -a -x "${_EXEC}/${topdir}/index.cgi" ]; then
78   . "${_EXEC}/${topdir}/index.cgi"
79 else
80   printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
81 fi