]> git.plutz.net Git - webpoll/blob - index.cgi
1bfc2b7e3231b27c2af4cbeb1653daa5322aba6d
[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 bookmarks="$(COOKIE bookmarks |grep -xE '[0-9a-zA-Z:=]{16}(/[0-9a-zA-Z:=]{16})?( [0-9a-zA-Z:=]{16}(/[0-9a-zA-Z:=]{16})?)*')"
18
19 yield_page(){
20   title="${1:-Webpoll}" page="$2"
21   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
22                   "Content-Security-Policy: script-src 'none'" \
23                   ''
24   { printf '[html
25     [head
26       [meta name="viewport" content="width=device-width"]
27       [link rel="stylesheet" type="text/css" href="%s/common.css"]
28       [link rel="stylesheet" type="text/css" href="%s/widgets.css"]
29       [link rel="stylesheet" type="text/css" href="%s/webpoll.css"]
30       [title %s]
31     ] [body class="%s"
32   ' "$_BASE" "$_BASE" "$_BASE" "$(HTML "$title")" "$page"
33   cat
34   printf '] ]'
35   } |"$_EXEC/cgilite/html-sh.sed" -u
36 }
37
38 pagename() {
39   local id="$1"
40   local file="$_DATA/$id"
41   if [ -f "$file" ]; then
42     DBM "$file" get title || printf 'Unnamed Page'
43   else
44     return 1;
45   fi
46 }
47
48    page_home() { . "$_EXEC"/home.sh; }
49 page_newdate() { . "$_EXEC"/newdate.sh; }
50    page_poll() { . "$_EXEC"/poll.sh; }
51
52 case ${PATH_INFO} in
53   /favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
54   /common.css) FILE "$_EXEC/cgilite/common.css";;
55   /widgets.css|/webpoll.css) FILE "${_EXEC}/${PATH_INFO}";;
56   /) page_home;;
57   /[0-9a-zA-Z:=]???????????????/[0-9a-zA-Z:=]???????????????) page_newdate;;
58   /*/newoptions);;
59   /[0-9a-zA-Z:=]???????????????) page_poll;;
60 esac
61
62 exit 0