From: Paul Hänsch Date: Wed, 28 Jul 2021 21:22:05 +0000 (+0200) Subject: keep invalid URLs intact in case of typo X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=22d77b49555ed424e7d9064b06f37b8caa83f914;p=webpoll keep invalid URLs intact in case of typo --- diff --git a/home.sh b/home.sh index bea9940..c4d5754 100755 --- a/home.sh +++ b/home.sh @@ -18,6 +18,7 @@ if [ "$REQUEST_METHOD" = POST ]; then *) REDIRECT "$_BASE/";; esac else + [ "$PATH_INFO" != / ] && printf 'Status: 404 Not Found\r\n' yield_page "Start a Poll" "home" <<-EOF [form method=post [submit "start" "date" Start a new poll] diff --git a/index.cgi b/index.cgi index e0f8a1c..a7481d7 100755 --- a/index.cgi +++ b/index.cgi @@ -63,6 +63,7 @@ case ${PATH_INFO} in /[0-9a-zA-Z:=]???????????????/[0-9a-zA-Z:=]???????????????) page_newdate;; /*/newoptions);; /[0-9a-zA-Z:=]???????????????) page_poll;; + /*) page_home;; esac exit 0 diff --git a/newdate.sh b/newdate.sh index 9c5a1e7..2efa748 100755 --- a/newdate.sh +++ b/newdate.sh @@ -1,5 +1,23 @@ #!/bin/sh +id="${PATH_INFO%/*}"; id="${id#/}" +admin=${PATH_INFO##*/} +file="$_DATA/$id" + +if [ "$(DBM "$file" get adminkey)" != "$admin" ]; then + page_home; + return 0 + # 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 + fs_timeofday() { local todall="$(DBM "$file" get todall)" time c=0 cat <<-EOF @@ -50,22 +68,6 @@ 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 month="$(POST month |grep -m 1 -xE '[0-9]{4}-(0[1-9]|1[012])')" todremove="$(POST todremove |grep -m 1 -xE '[0-9]+')" diff --git a/poll.sh b/poll.sh index de5b614..bb5bc8d 100644 --- a/poll.sh +++ b/poll.sh @@ -4,7 +4,10 @@ id="$(checkid "${PATH_INFO#/}")" file="${_DATA}/${id}" #cancel if poll is invalid -[ "$id" -a -f "$file" ] || REDIRECT "$_BASE/" +if [ ! "$id" -o ! -f "$file" ]; then + page_home; + return 0 +fi if expr match "$bookmarks" ".*${id}.*" >/dev/null; then :