#!/bin/sh
-_EXEC="${_EXEC:-${0%/*}/}"
-_DATA="${_DATA:-.}"
-
-. "$_EXEC"/cgilite/cgilite.sh
-#. "$_EXEC"/cgilite/session.sh
+. "${_EXEC:-${0%/*}}"/cgilite/cgilite.sh
+. "$_EXEC"/cgilite/session.sh
. "$_EXEC"/cgilite/file.sh
-#. "$_EXEC"/session_lock.sh
+. "$_EXEC"/cgilite/storage.sh
. "$_EXEC"/widgets.sh
-#git init "$_DATA" >/dev/null &
+# PATH_INFO="$(PATH "/${PATH_INFO#${_BASE}}")"
+
+# 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})?)*')"
+bookmarks=''
+for bm in $(COOKIE bookmarks); do
+ [ -f "${_DATA}/$(checkid "${bm%/*}")" ] && bookmarks="${bookmarks}${bookmarks:+ }${bm}"
+done
+if [ "$bookmarks" ]; then
+ SET_COOKIE +$((182 * 86400)) bookmarks="${bm}" Path="${_BASE}/"
+fi
yield_page(){
title="${1:-Webpoll}" page="$2"
{ printf '[html
[head
[meta name="viewport" content="width=device-width"]
- [link rel="stylesheet" type="text/css" href="common.css"]
- [link rel="stylesheet" type="text/css" href="widgets.css"]
+ [link rel="stylesheet" type="text/css" href="%s/common.css"]
+ [link rel="stylesheet" type="text/css" href="%s/widgets.css"]
+ [link rel="stylesheet" type="text/css" href="%s/webpoll.css"]
[title %s]
] [body class="%s"
- ' "$title" "$page"
+ ' "$_BASE" "$_BASE" "$_BASE" "$(HTML "$title")" "$page"
cat
printf '] ]'
} |"$_EXEC/cgilite/html-sh.sed" -u
}
-case ${PATH_INFO##*/} in
- favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
- common.css) FILE "$_EXEC/cgilite/common.css";;
- widgets.css) FILE "$_EXEC/widgets.css";;
- '') yield_page <<-EOF
- $(w_month date1 2019-12 24)
- $(w_month date2 2020-01)
- $(w_month date3 2020-02)
- EOF
- return 0
- ;;
+pagename() {
+ local id="$1"
+ local file="$_DATA/$id"
+ if [ -f "$file" ]; then
+ DBM "$file" get title || printf 'Unnamed Page'
+ else
+ return 1;
+ fi
+}
+
+ page_home() { . "$_EXEC"/home.sh; }
+page_newdate() { . "$_EXEC"/newdate.sh; }
+ page_poll() { . "$_EXEC"/poll.sh; }
+
+case ${PATH_INFO} in
+ /favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
+ /common.css) FILE "$_EXEC/cgilite/common.css";;
+ /widgets.css|/webpoll.css) FILE "${_EXEC}/${PATH_INFO}";;
+ /) page_home;;
+ /[0-9a-zA-Z:=]???????????????/[0-9a-zA-Z:=]???????????????) page_newdate;;
+ /*/newoptions);;
+ /[0-9a-zA-Z:=]???????????????) page_poll;;
+ /*) page_home;;
esac
+exit 0