]> git.plutz.net Git - confetti/blob - index.cgi
introduce sessions
[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 yield_page() {
19   local class="$1" style="$2"
20   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
21   { printf '
22         [html [head
23           [meta name="viewport" content="width=device-width"]
24           [link rel="stylesheet" type="text/css" href="/style.css"]
25     '
26     [ -n "$style" ] && printf '
27           [link rel="stylesheet" type="text/css" href="%s"]
28     ' "$style"
29     printf '
30         ] [body class="%s"
31     ' "$class"
32     cat
33     printf '] ]'
34   } \
35   | "${_EXEC}/cgilite/html-sh.sed"
36 }
37
38 if   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/main.cgi" ]; then
39   . "${_EXEC}/${_PATH}/main.cgi"
40 elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
41   . "${_EXEC}/${_PATH}"
42 elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
43   . "$_EXEC/cgilite/file.sh"
44   FILE "${_EXEC}/${_PATH}"
45 else
46   printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
47 fi