X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;ds=inline;f=index.cgi;h=e96c9f01e750c7c323a8b7d031177918f6c96e7f;hb=refs%2Fheads%2Fmaster;hp=4f24149bd8f53024b5903c7e4a1ed37196185b22;hpb=104596e3d1aa06eb5cb6108b477e2b379b202537;p=bookman
diff --git a/index.cgi b/index.cgi
index 4f24149..e96c9f0 100755
--- a/index.cgi
+++ b/index.cgi
@@ -92,8 +92,8 @@ 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}?${QUERY_STRING#id=*&}"
+ printf 'Status: 303 See Other\r\n'
+ printf 'Location: %s\r\n' "${SCRIPT_NAME}?${QUERY_STRING#id=????????????}"
SET_COOKIE +8640000 "id=${QRYID}"
printf '\r\n'
exit 0
@@ -103,6 +103,7 @@ elif [ -z "$COKID" -a -z "$QRYID" ]; then
cat <<-EOF
+
Bookman - New Collection
You have not yet set up a collection on this server.
@@ -111,12 +112,13 @@ elif [ -z "$COKID" -a -z "$QRYID" ]; then
EOF
exit 0
elif ! [ -d "${BDB}" ]; then
- printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL"
+ printf 'Status: 404 Not Found\r\n'
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.
@@ -132,7 +134,7 @@ case "$(GET action)" in
{ git init "users/${NEWID}" || mkdir -p "users/${NEWID}"; } >&-
- printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
+ printf 'Status: 303 See Other\r\n'
printf 'Location: %s\r\n' "${SCRIPT_NAME}?id=${NEWID}"
SET_COOKIE +8640000 "id=${NEWID}"
printf '\r\n'
@@ -173,8 +175,11 @@ case "$(GET action)" in
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" >&-
+ if [ "$target" = "____________" ]; then
+ rm -f "$file" "${file%.bm}.cache" >&-
+ git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" >&-
+ elif tail -n+2 "$file" >>"$tfile"; then
+ rm -f "$file" "${file%.bm}.cache" >&-
git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" "${target}.bm" >&-
fi
fi
@@ -202,12 +207,19 @@ case "$(GET action)" in
url="$(POST url |head -n1)"
file="${BDB}/${fid}.bm"
bid="$(timeid)"
- if [ -n "$name" -a -f "${file}" ]; then
+ ctl="$(POST control)"
+ [ "$url" = "${url#*://}" ] && url="http://$url"
+
+ if [ -n "$name" -a -n "$url" -a -f "${file}" -a "$ctl" = "confirm" ]; then
printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$url" >>"${file}"
git -C "${BDB}" commit -m "New Bookmark: ${name} in ${fid}" -- "${fid}.bm" >&-
+ getFavicon "$url" "$bid"
+ REDIRECT "${SCRIPT_NAME}#${fid}"
+ elif [ "$ctl" = "confirm" ]; then
+ REDIRECT "${SCRIPT_NAME}?newbm=${fid}&nbmurl=${url}&nbmname=${name}"
+ else
+ REDIRECT "${SCRIPT_NAME}#${fid}"
fi
- getFavicon "$url" "$bid"
- REDIRECT "${SCRIPT_NAME}#${fid}"
;;
modbookmark)
bid="$(POST bid | checkid)"
@@ -272,6 +284,44 @@ case "$(GET action)" in
;;
esac
+bookmarkgen(){
+ fid="$(GET newbm |checkid)"
+ name="$(GET nbmname)"
+ url="$(GET nbmurl)"
+ file="${BDB}/${fid}.bm"
+
+ if [ -z "$name" -a -n "$url" ]; then
+ name="$(wget -O- "$url" \
+ | head -c4096 \
+ | sed -rn ':X;$bY;N;bX;:Y; s;^.*]*>([^<]+)<.*$;\1;p;'
+ )"
+ fi
+
+ if [ -n "$fid" -o -n "$name" -o -n "$url" ]; then
+ [ "$url" = "${url#*://}" ] && url="http://$url"
+ cat <<-EOF
+
+ EOF
+ fi
+}
+
bookmarkmod(){
bmod="$(GET bmodify |checkid)"
bmove="$(GET bmove |checkid)"
@@ -282,7 +332,7 @@ bookmarkmod(){
$(grep -m1 "^${bmod}" "$file")
EOF
cat <<-EOF
-
+ New Bookmark
EOF
fi
@@ -442,16 +487,21 @@ printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
cat <
+
Bookman - Your Collection
$(foldermod)
$(bookmarkmod)
+ $(bookmarkgen)
$(show_folders)
+
EOF