]> git.plutz.net Git - webpoll/blob - index.cgi
fix android: display arrow buttons in top row of calendar
[webpoll] / index.cgi
1 #!/bin/sh
2
3 _EXEC="${_EXEC:-${0%/*}/}"
4 _DATA="${_DATA:-.}"
5 _BASE="${_BASE%/}"
6
7 . "$_EXEC"/cgilite/cgilite.sh
8 . "$_EXEC"/cgilite/session.sh
9 . "$_EXEC"/cgilite/file.sh
10 . "$_EXEC"/cgilite/storage.sh
11 #. "$_EXEC"/session_lock.sh
12 . "$_EXEC"/widgets.sh
13
14 PATH_INFO="$(PATH "/${PATH_INFO#${_BASE}}")"
15
16 #git init "$_DATA" >/dev/null &
17
18 yield_page(){
19   title="${1:-Webpoll}" page="$2"
20   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
21                   "Content-Security-Policy: script-src 'none'" \
22                   ''
23   { printf '[html
24     [head
25       [meta name="viewport" content="width=device-width"]
26       [link rel="stylesheet" type="text/css" href="%s/common.css"]
27       [link rel="stylesheet" type="text/css" href="%s/widgets.css"]
28       [link rel="stylesheet" type="text/css" href="%s/webpoll.css"]
29       [title %s]
30     ] [body class="%s"
31   ' "$_BASE" "$_BASE" "$_BASE" "$title" "$page"
32   cat
33   printf '] ]'
34   } |"$_EXEC/cgilite/html-sh.sed" -u
35 }
36
37 pagename() {
38   local id="$1"
39   local file="$_DATA/$id"
40   if [ -f "$file" ]; then
41     DBM "$file" get title || printf 'Unnamed Page'
42   else
43     return 1;
44   fi
45 }
46
47 page_home() {
48   if [ "$REQUEST_METHOD" = POST ]; then
49     case $(POST start) in
50       date)
51         id="$(randomid)"
52         touch "$_DATA/$id"
53         REDIRECT "$_BASE/$id/newdate"
54         ;;
55       options)
56         id="$(randomid)"
57         touch "$_DATA/$id"
58         REDIRECT "$_BASE/$id/newoptions"
59         ;;
60       *) REDIRECT "$_BASE/";;
61     esac
62   else
63     recent="$(COOKIE pages)"
64     yield_page "Start a Poll" "home" <<-EOF
65         [form method=post
66           [submit "start" "date" Start a new poll]
67           $(if [ "$recent" ]; then
68             printf '[h2 Recent Polls][ul .recent'
69             for page in $recent; do
70               [ -f "$_DATA/$(checkid "$page")" ] \
71               && printf '[li [a href="./%s" . %s]]' "$page" "$(pagename "$page" |HTML)"
72             done
73             printf ']'
74           fi)
75         ]
76         EOF
77   fi
78 }
79 page_newdate() { . $_EXEC/newdate.sh; }
80
81 case ${PATH_INFO} in
82   /favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
83   /common.css) FILE "$_EXEC/cgilite/common.css";;
84   /widgets.css|/webpoll.css) FILE "${_EXEC}/${PATH_INFO}";;
85   /) page_home;;
86   /*/newdate) page_newdate;;
87   /*/newoptions);;
88   *);;
89 esac
90