From 22d77b49555ed424e7d9064b06f37b8caa83f914 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 28 Jul 2021 23:22:05 +0200 Subject: [PATCH] keep invalid URLs intact in case of typo --- home.sh | 1 + index.cgi | 1 + newdate.sh | 34 ++++++++++++++++++---------------- poll.sh | 5 ++++- 4 files changed, 24 insertions(+), 17 deletions(-) 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 : -- 2.39.2