From: Paul Hänsch Date: Tue, 27 Jul 2021 23:19:50 +0000 (+0200) Subject: optional bookmarking of poll and admin pages X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=83fc1c222fd0c89d90e780ef93c5da048da3f5de;p=webpoll optional bookmarking of poll and admin pages --- diff --git a/newdate.sh b/newdate.sh index b2e35a6..e2902e4 100755 --- a/newdate.sh +++ b/newdate.sh @@ -50,9 +50,23 @@ fs_splittimes() { EOF } +id="${PATH_INFO%/*}"; id="${id#/}" +admin=${PATH_INFO##*/} +file="$_DATA/$id" + +if [ "$(DBM "$file" get adminkey)" != "$admin" ]; then + REDIRECT "$_BASE/#ERRO_INVALIDKEY" +elif expr match "$bookmarks" ".*${id}/${admin}.*" >/dev/null; then + : +elif expr match "$bookmarks" ".*${id}.*" >/dev/null; then + bookmarks="$(printf %s "$bookmarks" |tr \ \\n |grep -vxF "${id}")" + bookmarks="$(printf %s "$bookmarks" |tr \\n \ )" + SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks}${bookmarks:+ }${id}/${admin}" Path="${_BASE}/" +elif [ "$bookmarks" ]; then + SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}/${admin}" Path="${_BASE}/" +fi + if [ "$REQUEST_METHOD" = POST ]; then - id="${PATH_INFO%/newdate}"; id="${id#/}" - file="$_DATA/$id" month="$(POST month |grep -m 1 -xE '[0-9]{4}-(0[1-9]|1[012])')" todremove="$(POST todremove |grep -m 1 -xE '[0-9]+')" splittimes="$(POST splittimes |grep -m 1 -xE 'yes|no')" @@ -118,12 +132,13 @@ if [ "$REQUEST_METHOD" = POST ]; then REDIRECT "$_BASE/" elif [ "$(POST post)" = post ]; then REDIRECT "$_BASE${PATH_INFO%/*}" + elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then + SET_COOKIE +$((182 * 86400)) bookmarks="${id}/${admin}" Path="${_BASE}/" + REDIRECT "$_BASE$PATH_INFO${month:+?month=}${month}" else REDIRECT "$_BASE$PATH_INFO${month:+?month=}${month}" fi else - id="${PATH_INFO%/newdate}"; id="${id#/}" - file="$_DATA/$id" month="$(GET month |grep -m1 -xE '[0-9]{4}-(0[1-9]|1[012])' || date +%Y-%m)" Y="${month%-*}"; m="${month#*-}"; Y=${Y#0}; m=${m#0}; [ "$m" = 1 ] && prev=$(printf '%04i-%02i' $((Y - 1)) 12) || prev=$(printf '%04i-%02i' $Y $((m - 1))) @@ -148,6 +163,15 @@ else $([ "$splittimes" = "yes" ] && fs_splittimes || fs_timeofday ) [submit "cancel" "cancel" Cancel] [submit "post" "post" Post Event] + $(if [ "$bookmarks" ]; then + printf '[section .bookmark This admin page is accessible via the link [a href="%s" %s]. You must copy this link and keep it safe, so you can modify this poll later! The poll has also been bookmarked and will be listed on the front page.' \ + "$(URL "//$(HEADER Host)/${_BASE}/${id}/${admin}")" \ + "$(HTML "${HTTPS:+https:}${HTTPS:-http:}//$(HEADER Host)$(PATH "/${_BASE}/${id}/${admin}")")" + else + printf '[section .bookmark This admin page is accessible via the link [a href="%s" %s]. You must copy this link and keep it safe, so you can modify this poll later! You can also set a Cookie to bookmark all polls you visit, including this admin page. Bookmarked polls will be listed on the frontpage.
[submit "bookmark" "add" Set Cookie]]' \ + "$(URL "//$(HEADER Host)/${_BASE}/${id}/${admin}")" \ + "$(HTML "${HTTPS:+https:}${HTTPS:-http:}//$(HEADER Host)$(PATH "/${_BASE}/${id}/${admin}")")" + fi) ] EOF fi diff --git a/poll.sh b/poll.sh index d7c0def..5624284 100644 --- a/poll.sh +++ b/poll.sh @@ -6,6 +6,15 @@ file="${_DATA}/${id}" #cancel if poll is invalid [ "$id" -a -f "$file" ] || REDIRECT "$_BASE/" +if expr match "$bookmarks" ".*${id}.*" >/dev/null; then + : +elif [ "$bookmarks" ]; then + SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}" Path="${_BASE}/" +fi + +admin="$(expr match "$bookmarks" ".*$id/\([a-zA-Z0-9:=]\{16\}\).*")" +admin="$(DBM "$file" get adminkey |grep -xF "$admin")" + tkey() { # convert time stamps for use in POST keys local str="$1" out @@ -79,7 +88,7 @@ table_poll() { if [ "$splittimes" = yes -o "$todall" ]; then printf '[tr .tod [th]' for time in $timelist; do - [ "${time#*_}" = "${time}" ] && time="${time}_" + [ "${time#*_}" = "${time}" ] && time="_${time}" printf '[th . %s]' "${time#*_}" done printf '[th]]\n' @@ -196,6 +205,10 @@ if [ "$REQUEST_METHOD" = POST ]; then DBM "$file" delete "reply_yes_${delete}" DBM "$file" delete "reply_no_${delete}" DBM "$file" delete "reply_maybe_${delete}" + + elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then + SET_COOKIE +$((182 * 86400)) bookmarks="${id}" Path="${_BASE}/" + fi REDIRECT "${_BASE}${PATH_INFO}" @@ -209,6 +222,13 @@ else $(DBM "$file" get description |markdown) ] $(table_poll || printf '[p Poll parameters are invalid]') + $(if [ "$admin" ]; then + printf '[section .bookmark You have bookmarked the admin page of this poll: [a href="./%s" modify poll]]' "$(URL ${id}/${admin})" + elif [ "$bookmarks" ]; then + printf '[section .bookmark This poll has been bookmarked and is accessible via a link on the front page.]' + else + printf '[section .bookmark Polls are accessible only via their URL. You can set a Cookie to bookmark all polls you visit. Bookmarked polls will be listed on the frontpage.
[submit "bookmark" "add" Set Cookie]]' + fi) ] EOF fi diff --git a/webpoll.css b/webpoll.css index b89bc45..193b2ed 100644 --- a/webpoll.css +++ b/webpoll.css @@ -22,13 +22,16 @@ body.poll form { text-align: center; max-width: 95%; } -body.poll .description { - text-align: left; +body section { max-width: 50em; - padding: 1pt 1em 1em 1em; - margin: auto; - margin-bottom: 1em; + padding: 1em; + margin: 1em auto; background-color: rgba(255,255,255,.5); + word-wrap: break-word; +} +body.poll .description .title { + margin-top: 0; + text-align: left; } body.poll .description .title { text-align: center; @@ -69,7 +72,7 @@ body.poll table tbody tr.votecount td { padding: .375em .25em;} body.poll table tbody tr th.name button[name=delete] { font-size: .625em; line-height: 1.5em; background-color: #FAA; } body.poll table tbody tr.new td:first-child { text-align: right; } -body.poll table tbody tr.new td input[name=name] { min-width: 100%; width: 4em; } +body.poll table tbody tr.new td input[name=name] { min-width: 100%; width: 8em; } body.poll table td input[type=radio] { display: none; } body.poll table td input[type=radio] + label {