From 3ecee15fc19ec1a2d4b44d965e63412860ea01b6 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 28 Nov 2017 19:35:55 +0000 Subject: [PATCH] implemented folder actions, keep secret ID out of address bar svn path=/trunk/; revision=8 --- index.cgi | 150 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 94 insertions(+), 56 deletions(-) diff --git a/index.cgi b/index.cgi index 3cf7e29..0c563ea 100755 --- a/index.cgi +++ b/index.cgi @@ -78,10 +78,54 @@ list_folders(){ | cut -f1,2 } +order_files(){ + n=1000 + list_folders \ + | while read fid nan; do + file="${BDB}/${fid}.bm" + sed -ri "1s;^(([^\t]+\t){2})[^\t]+(.*)$;\1${n}\3;;" "$file" + n=$((n + 1000)) + done +} -QRYID="$(GET id |checkid)" COKID="$(COOKIE id |checkid)" -BDB="users/${QRYID}" +QRYID="$(GET id |checkid)" +BDB="users/${COKID}" + +if [ -n "$QRYID" ]; then + printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL" + printf 'Location: %s\r\n' "${SCRIPT_NAME}" + SET_COOKIE +8640000 "id=${QRYID}" + printf '\r\n' + exit 0 +elif [ -z "$COKID" -a -z "$QRYID" ]; then + printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' + + cat <<-EOF + + + Bookman - New Collection + +

You have not yet set up a collection on this server.

+ Click here to start a new collection. + + EOF + exit 0 +elif ! [ -d "${BDB}" ]; then + printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL" + printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' + + cat <<-EOF + + + Bookman - 404 + +

The collection you requested does not exist on this server.

+ Click here to start a new collection. + + EOF + exit 0 +fi case "$(GET action)" in newid) @@ -109,7 +153,7 @@ case "$(GET action)" in if [ -n "$name" -a -d "${BDB}" ]; then printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"${BDB}/${fid}.bm" fi - REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}" + REDIRECT "${SCRIPT_NAME}#${fid}" ;; modfolder) name="$(POST name |head -n1)" @@ -121,7 +165,34 @@ case "$(GET action)" in tail -n+2 "$file" >>"${file%.bm}.tmp" mv "${file%.bm}.tmp" "$file" fi - REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}" + REDIRECT "${SCRIPT_NAME}#${fid}" + ;; + delfolder) + fid="$(POST fid | checkid)" + target="$(POST target | checkid)" + file="${BDB}/${fid}.bm" + tfile="${BDB}/${target}.bm" + if [ "$(POST control)" = confirm -a -f "$file" ]; then + if [ "$target" = "____________" ] || tail -n+2 "$file" >>"$tfile"; then + rm -f "$file" + fi + fi + REDIRECT "${SCRIPT_NAME}#${target}" + ;; + movefolder) + fid="$(POST fid | checkid)" + target="$(POST target | checkid)" + file="${BDB}/${fid}.bm" + tfile="${BDB}/${target}.bm" + if [ "$target" = "____________" -a -f "$file" -a "$(POST control)" = confirm ]; then + read nan1 nan2 last nan3 <"${BDB}/$(list_folders |tail -n1 |cut -f1).bm" + sed -ri "1s;^(([^\t]+\t){2})[^\t]+(.*)$;\1$((${last:-0} + 1000))\3;;" "$file" + elif [ -f "$tfile" -a -f "$file" -a "$(POST control)" = confirm ]; then + read nan1 nan2 tid nan3 <"$tfile" + sed -ri "1s;^(([^\t]+\t){2})[^\t]+(.*)$;\1$((${tid:-1} -1))\2;;" "$file" + order_files + fi + REDIRECT "${SCRIPT_NAME}#${fid}" ;; newbookmark) fid="$(POST fid | checkid)" @@ -133,7 +204,7 @@ case "$(GET action)" in printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$(HTML "$url")" >>"${file}" fi getFavicon "$url" "$bid" - REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}" + REDIRECT "${SCRIPT_NAME}#${fid}" ;; modbookmark) bid="$(POST bid | checkid)" @@ -145,45 +216,10 @@ case "$(GET action)" in sed -ri "s;^${bid}\t.*$;${bm};" "$file" fi getFavicon "$url" "$bid" - REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}" + REDIRECT "${SCRIPT_NAME}#${fid}" ;; esac -if [ -z "$QRYID" -a -n "$COKID" ]; then - REDIRECT "${SCRIPT_NAME}?id=${COKID}" -elif [ -n "$QRYID" -a -z "$COKID" ]; then - SET_COOKIE +8640000 "id=${QRYID}" -fi - -if [ -z "$QRYID" -a -z "$COKID" ]; then - printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' - - cat <<-EOF - - - Bookman - New Collection - -

You have not yet set up a collection on this server.

- Click here to start a new collection. - - EOF - exit 0 -elif ! [ -d "users/${QRYID}" ]; then - printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL" - printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' - - cat <<-EOF - - - Bookman - 404 - -

The collection you requested does not exist on this server.

- Click here to start a new collection. - - EOF - exit 0 -fi - list_bookmarks(){ fid="$1" bmodify="$(GET bmodify |checkid)" @@ -192,7 +228,7 @@ list_bookmarks(){ | while read bid name url; do if [ "${bid}" = "$bmodify" ]; then cat <<-EOF -
+ @@ -202,7 +238,7 @@ list_bookmarks(){ else cat <<-EOF EOF @@ -218,14 +254,14 @@ foldermod(){ if [ -n "$fmodify" ]; then read fid fname order <"${BDB}/${fmodify}.bm" cat <<-EOF - +

Rename Folder: ${fname}

Delete + href="${SCRIPT_NAME}?fdelete=${fid}">Delete Move + href="${SCRIPT_NAME}?fmove=${fid}">Move @@ -234,17 +270,17 @@ foldermod(){ elif [ -n "$fdelete" ]; then read fid fname order <"${BDB}/${fdelete}.bm" cat <<-EOF - +

Delete Folder: ${fname}

- Rename + Rename Move + href="${SCRIPT_NAME}?fmove=${fid}">Move @@ -253,11 +289,11 @@ foldermod(){ elif [ -n "$fmove" ]; then read fid fname order <"${BDB}/${fmove}.bm" cat <<-EOF - +

Move Folder: ${fname}

- Rename - Delete + Rename + Delete @@ -290,7 +326,9 @@ show_folders(){ done } +SET_COOKIE +8640000 "id=${COKID}" # Refresh Cookie printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' + cat < @@ -299,7 +337,7 @@ cat < $(foldermod) $(show_folders) - + -- 2.39.2