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