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