]> git.plutz.net Git - webpoll/commitdiff
keep invalid URLs intact in case of typo
authorPaul Hänsch <paul@plutz.net>
Wed, 28 Jul 2021 21:22:05 +0000 (23:22 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 28 Jul 2021 21:22:05 +0000 (23:22 +0200)
home.sh
index.cgi
newdate.sh
poll.sh

diff --git a/home.sh b/home.sh
index bea9940e56af096080dff83507175b8eebe76463..c4d5754139bb2d6c04a1260e25e4272692be032e 100755 (executable)
--- 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]
index e0f8a1cb10189a5916afbf82b3237dac55207658..a7481d70383280808ba70ded82b9bd6d288f968a 100755 (executable)
--- 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
index 9c5a1e71cb9dd654c55cc2642eb46f5ae8963035..2efa7485a44a73e715318c3bdf47bc874db5ec83 100755 (executable)
@@ -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 de5b614c74321c93521a6ac0e1bb3c2e08f45d05..bb5bc8db1d213dc0b46d3bdebacfe5a24d257c3f 100644 (file)
--- 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
   :