8 printf 'POST: %s\n' "$cgilite_post" >>debug
9 printf 'action: %s\n' "$(GET action)" >>debug
12 wget(){ "$wget" -T 5 -t 1 -q -U '' $@; }
13 checkid(){ grep -m 1 -xE '[0-9a-zA-Z:_]{12}'; }
17 head -c9 /dev/urandom \
19 | sed -n '2{y;+/;:_;;p}'
23 # generate time based ID
26 while [ "$d" -gt 0 ]; do
27 printf \\%o $((d % 256))
34 | sed -n '2{y;+/;:_;;p}'
42 domain="${domain%%/*}"
43 ubase="${prot}://${domain}"
44 file="${BDB}/favicons/${bid}.ico"
46 mkdir -p "${BDB}/favicons/" && chmod a+rx "${BDB}/favicons/"
52 's;^.*(<[Ll][Ii][Nn][Kk]( [^>]*)? [Rr][Re][Ll]='\''([Ss][Hh][Oo][Rr][Tt][Cc][Uu][Tt] )?[Ii][Cc][Oo][Nn]'\''[^>]*>).*$;\1;;
53 s;^.*(<[Ll][Ii][Nn][Kk]( [^>]*)? [Rr][Re][Ll]="([Ss][Hh][Oo][Rr][Tt][Cc][Uu][Tt] )?[Ii][Cc][Oo][Nn]"[^>]*>).*$;\1;;
55 s;^.*<([^>]+) [Hh][Rr][Ee][Ff]="([^"]+)".*$:\2;;
56 s;^.*<([^>]+) [Hh][Rr][Ee][Ff]='\''([^'\'']+)'\''.*$:\2;;
61 printf 'Shortcut icon for %s is %s\n' "$url" "$favinfo" >>debug
62 [ -z "$favinfo" ] && favinfo="${ubase}/favicon.ico"
64 http://*|https://*|//*) wget -O "$file" "$favinfo"
66 /*) wget -O "$file" "${ubase}/${favinfo}"
68 *) wget -O "$file" "${url%/*}/${favinfo}"
71 [ -f "${file}.1" ] && mv "${file}.1" "$file"
76 head -qn1 "${BDB}"/????????????.bm \
84 | while read fid nan; do
85 file="${BDB}/${fid}.bm"
86 sed -ri "1s;^(([^\t]+\t){2})[^\t]+(.*)$;\1${n}\3;;" "$file"
91 COKID="$(COOKIE id |checkid)"
92 QRYID="$(GET id |checkid)"
95 if [ -n "$QRYID" ]; then
96 printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
97 printf 'Location: %s\r\n' "${SCRIPT_NAME}"
98 SET_COOKIE +8640000 "id=${QRYID}"
101 elif [ -z "$COKID" -a -z "$QRYID" ]; then
102 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
107 <title>Bookman - New Collection</title>
108 </head><body id="newcollection">
109 <h1>You have not yet set up a collection on this server.</h1>
110 Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
114 elif ! [ -d "${BDB}" ]; then
115 printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL"
116 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
121 <title>Bookman - 404</title>
122 </head><body id="missingcollection">
123 <h1>The collection you requested does not exist on this server.</h1>
124 Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
130 case "$(GET action)" in
134 { git init "users/${NEWID}" || mkdir -p "users/${NEWID}"; } >&-
136 printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
137 printf 'Location: %s\r\n' "${SCRIPT_NAME}?id=${NEWID}"
138 SET_COOKIE +8640000 "id=${NEWID}"
143 name="$(POST name |head -n1)"
146 head -qn1 "${BDB}"/????????????.bm \
152 order="$(((order + 1000) / 1000 * 1000))"
153 if [ -n "$name" -a -d "${BDB}" ]; then
154 printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"${BDB}/${fid}.bm"
156 REDIRECT "${SCRIPT_NAME}#${fid}"
159 name="$(POST name |head -n1)"
160 fid="$(POST fid | checkid)"
161 file="${BDB}/${fid}.bm"
162 if [ "$(POST control)" = confirm -a -n "$name" -a -f "$file" ]; then
163 sed -ri "1s'^(${fid}\t)[^\t]+(\t.+)$'\1${name}\2';" "$file"
165 REDIRECT "${SCRIPT_NAME}#${fid}"
168 fid="$(POST fid | checkid)"
169 target="$(POST target | checkid)"
170 file="${BDB}/${fid}.bm"
171 tfile="${BDB}/${target}.bm"
172 if [ "$(POST control)" = confirm -a -f "$file" ]; then
173 if [ "$target" = "____________" ] || tail -n+2 "$file" >>"$tfile"; then
177 REDIRECT "${SCRIPT_NAME}#${target}"
180 fid="$(POST fid | checkid)"
181 target="$(POST target | checkid)"
182 file="${BDB}/${fid}.bm"
183 tfile="${BDB}/${target}.bm"
184 if [ "$target" = "____________" -a -f "$file" -a "$(POST control)" = confirm ]; then
185 read nan1 nan2 last nan3 <"${BDB}/$(list_folders |tail -n1 |cut -f1).bm"
186 sed -ri "1s;^(([^\t]+\t){2})[^\t]+(.*)$;\1$((${last:-0} + 1000))\3;;" "$file"
187 elif [ -f "$tfile" -a -f "$file" -a "$(POST control)" = confirm ]; then
188 read nan1 nan2 tid nan3 <"$tfile"
189 sed -ri "1s;^(([^\t]+\t){2})[^\t]+(.*)$;\1$((${tid:-1} -1))\2;;" "$file"
192 REDIRECT "${SCRIPT_NAME}#${fid}"
195 fid="$(POST fid | checkid)"
196 name="$(POST name |head -n1)"
197 url="$(POST url |head -n1)"
198 file="${BDB}/${fid}.bm"
200 if [ -n "$name" -a -f "${file}" ]; then
201 printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$(HTML "$url")" >>"${file}"
203 getFavicon "$url" "$bid"
204 REDIRECT "${SCRIPT_NAME}#${fid}"
207 bid="$(POST bid | checkid)"
208 name="$(POST name |head -n1)"
209 url="$(POST url |head -n1)"
210 file="$(grep -lm1 "^${bid}" "${BDB}"/????????????.bm |head -n1)"
211 if [ -n "$name" -a -n "$url" -a "$(POST control)" = confirm -a -w "$file" ]; then
212 bm="$(printf '%s\t%s\t%s' "$bid" "$(HTML "$name")" "$(HTML "$url")" |sed -r 's;[\&\;];\\&;g;')"
213 sed -ri "s;^${bid}\t.*$;${bm};" "$file"
215 getFavicon "$url" "$bid"
216 REDIRECT "${SCRIPT_NAME}#${fid}"
219 bid="$(POST bid | checkid)"
220 fid="$(POST target | checkid)"
221 sfile="$(grep -lm1 "^${bid}" "${BDB}"/????????????.bm |head -n1)"
222 tfile="${BDB}/${fid}.bm"
224 if [ "$(POST control)" = confirm -a -n "$bid" -a -w "$sfile" -a -w "$tfile" ]; then
225 grep -m1 "^${bid}" "$sfile" >>"$tfile" \
226 && sed -ri "0,/^${bid}/{/^${bid}/d;}" "$sfile"
228 REDIRECT "${SCRIPT_NAME}#${fid}"
231 fid="$(GET fid |checkid)"
232 bid="$(GET bid |checkid)"
233 file="${BDB}/${fid}.bm"
235 if [ -n "$bid" -a -n "$fid" ] && grep -q "^${bid}" "$file"; then
236 sed -ri ":X;\$bY;N;bX;:Y; s;(\n[^\n]+)(\n${bid}\t[^\n]+);\2\1;;" "$file"
238 REDIRECT "${SCRIPT_NAME}#${fid}"
241 fid="$(GET fid |checkid)"
242 bid="$(GET bid |checkid)"
243 file="${BDB}/${fid}.bm"
245 if [ -n "$bid" -a -n "$fid" ] && grep -q "^${bid}" "$file"; then
246 sed -ri ":X;\$bY;N;bX;:Y; s;(\n${bid}\t[^\n]+)(\n[^\n]+);\2\1;;" "$file"
248 REDIRECT "${SCRIPT_NAME}#${fid}"
253 bmod="$(GET bmodify |checkid)"
254 bmove="$(GET bmove |checkid)"
256 if [ -n "$bmod" ]; then
257 file="$(grep -lm1 "^${bmod}" "${BDB}/"????????????.bm |head -n1)"
258 read bid name url <<-EOF
259 $(grep -m1 "^${bmod}" "$file")
262 <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?action=modbookmark">
263 <input type="hidden" name="bid" value="${bid}" />
264 <h1>Modify: ${name}</h1>
265 <label class="tab">Modify</label>
266 <a class="tab" href="${SCRIPT_NAME}?bmove=${bid}">Move</a>
268 <input type="text" name="name" value="${name}")" placeholder="Name" />
270 <input type="text" name="url" value="${url}")" placeholder="URL" />
271 <button type="submit" name="control" value="confirm">OK</button>
272 <button type="submit" name="control" value="cancel">Cancel</button>
275 elif [ -n "$bmove" ]; then
276 file="$(grep -lm1 "^${bmove}" "${BDB}/"????????????.bm |head -n1)"
277 read bid name url <<-EOF
278 $(grep -m1 "^${bmove}" "$file")
281 <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?action=movebookmark">
282 <input type="hidden" name="bid" value="${bid}" />
283 <h1>Move: ${name}</h1>
284 <a class="tab" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
285 <label class="tab">Move</label>
286 <label>Move to Folder:</label>
287 <select name="target">
288 $(printf '<option value="%s">%s</option>' $(list_folders))
290 <button type="submit" name="control" value="confirm">OK</button>
291 <button type="submit" name="control" value="cancel">Cancel</button>
299 bmodify="$(GET bmodify |checkid)"
301 tail -n+2 "${BDB}/${fid}.bm" \
302 | while read bid name url; do
304 <div class="bookmark">
305 <a class="modify" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
306 <a class="link" href="${url}")"><img src="${BDB}/favicons/${bid}.ico"/>${name}</a>
307 <a class="bmove" href="${SCRIPT_NAME}?action=bmup&fid=${fid}&bid=${bid}">move left</a>
308 <a class="bmove" href="${SCRIPT_NAME}?action=bmdn&fid=${fid}&bid=${bid}">move right</a>
315 fmodify="$(GET fmodify |checkid )"
316 fdelete="$(GET fdelete |checkid )"
317 fmove="$(GET fmove |checkid )"
319 if [ -n "$fmodify" ]; then
320 read fid fname order <"${BDB}/${fmodify}.bm"
322 <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?action=modfolder">
323 <h1>Rename Folder: ${fname}</h1>
324 <input type="hidden" name="fid" value="${fid}" />
325 <label class="tab">Rename</label>
327 href="${SCRIPT_NAME}?fdelete=${fid}">Delete</a>
329 href="${SCRIPT_NAME}?fmove=${fid}">Move</a>
330 <input type="text" name="name" value="${fname}" />
331 <button type="submit" name="control" value="confirm">OK</button>
332 <button type="submit" name="control" value="cancel">Cancel</button>
335 elif [ -n "$fdelete" ]; then
336 read fid fname order <"${BDB}/${fdelete}.bm"
338 <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?action=delfolder">
339 <h1>Delete Folder: ${fname}</h1>
340 <input type="hidden" name="fid" value="${fid}" />
341 <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
342 <label class="tab">Delete</label>
344 href="${SCRIPT_NAME}?fmove=${fid}">Move</a>
345 <label>Pass Bookmarks on to:</label>
346 <select name="target">
347 $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
348 <option value="____________">(discard)</option>
350 <button type="submit" name="control" value="confirm">OK</button>
351 <button type="submit" name="control" value="cancel">Cancel</button>
354 elif [ -n "$fmove" ]; then
355 read fid fname order <"${BDB}/${fmove}.bm"
357 <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?action=movefolder">
358 <h1>Move Folder: ${fname}</h1>
359 <input type="hidden" name="fid" value="${fid}" />
360 <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
361 <a class="tab" href="${SCRIPT_NAME}?fdelete=${fid}">Delete</a>
362 <label class="tab">Move</label>
363 <label>Move before folder:</label>
364 <select name="target">
365 $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
366 <option value="____________">(last)</option>
368 <button type="submit" name="control" value="confirm">OK</button>
369 <button type="submit" name="control" value="cancel">Cancel</button>
377 | while read fid fname order; do
379 <section class="folder" id="${fid}">
381 <a class="modify" href="${SCRIPT_NAME}?fmodify=${fid}">Modify</a>
382 $(show_bookmarks "$fid")
383 <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?action=newbookmark">
384 <input type="hidden" name="fid" value="${fid}" />
385 <input type="text" name="name" value="" placeholder="Name" />
386 <input type="text" name="url" value="" placeholder="URL" />
387 <button type="submit">New Bookmark</button>
394 SET_COOKIE +8640000 "id=${COKID}" # Refresh Cookie
395 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
400 <title>Bookman - Your Collection</title>
401 <link rel="stylesheet" type="text/css" href="bookmarks.css" />
402 </head><body id="collection">
406 <form class="newfolder" method="POST" action="${SCRIPT_NAME}?action=newfolder">
407 <input type="text" name="name" value="" placeholder="New Folder" />
408 <button type="submit">New</button>