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 \
82 QRYID="$(GET id |checkid)"
83 COKID="$(COOKIE id |checkid)"
86 case "$(GET action)" in
90 { git init "users/${NEWID}" || mkdir -p "users/${NEWID}"; } >&-
92 printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
93 printf 'Location: %s\r\n' "${SCRIPT_NAME}?id=${NEWID}"
94 SET_COOKIE +8640000 "id=${NEWID}"
99 name="$(POST name |head -n1)"
102 head -qn1 "${BDB}"/????????????.bm \
108 order="$(((order + 1000) / 1000 * 1000))"
109 if [ -n "$name" -a -d "${BDB}" ]; then
110 printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"${BDB}/${fid}.bm"
112 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
115 name="$(POST name |head -n1)"
116 fid="$(POST fid | checkid)"
117 file="${BDB}/${fid}.bm"
118 if [ "$(POST control)" = confirm -a -n "$name" -a -f "$file" ]; then
119 order="$(head -n1 "$file" |cut -f3 || printf 1000)"
120 printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"${file%.bm}.tmp"
121 tail -n+2 "$file" >>"${file%.bm}.tmp"
122 mv "${file%.bm}.tmp" "$file"
124 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
127 fid="$(POST fid | checkid)"
128 name="$(POST name |head -n1)"
129 url="$(POST url |head -n1)"
130 file="${BDB}/${fid}.bm"
132 if [ -n "$name" -a -f "${file}" ]; then
133 printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$(HTML "$url")" >>"${file}"
135 getFavicon "$url" "$bid"
136 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
139 bid="$(POST bid | checkid)"
140 name="$(POST name |head -n1)"
141 url="$(POST url |head -n1)"
142 file="$(grep -lE "^${bid}" "${BDB}"/????????????.bm)"
143 if [ -w "$file" -a -n "$name" -a -n "$url" ]; then
144 bm="$(printf '%s\t%s\t%s' "$bid" "$(HTML "$name")" "$(HTML "$url")" |sed -r 's;[\&\;];\\&;g;')"
145 sed -ri "s;^${bid}\t.*$;${bm};" "$file"
147 getFavicon "$url" "$bid"
148 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
152 if [ -z "$QRYID" -a -n "$COKID" ]; then
153 REDIRECT "${SCRIPT_NAME}?id=${COKID}"
154 elif [ -n "$QRYID" -a -z "$COKID" ]; then
155 SET_COOKIE +8640000 "id=${QRYID}"
158 if [ -z "$QRYID" -a -z "$COKID" ]; then
159 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
164 <title>Bookman - New Collection</title>
165 </head><body id="newcollection">
166 <h1>You have not yet set up a collection on this server.</h1>
167 Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
171 elif ! [ -d "users/${QRYID}" ]; then
172 printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL"
173 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
178 <title>Bookman - 404</title>
179 </head><body id="missingcollection">
180 <h1>The collection you requested does not exist on this server.</h1>
181 Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
189 bmodify="$(GET bmodify |checkid)"
191 tail -n+2 "${BDB}/${fid}.bm" \
192 | while read bid name url; do
193 if [ "${bid}" = "$bmodify" ]; then
195 <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modbookmark">
196 <input type="hidden" name="bid" value="${bid}" />
197 <input type="text" name="name" value="${name}")" placeholder="Name" />
198 <input type="text" name="url" value="${url}")" placeholder="URL" />
199 <button type="submit">Modify</button>
204 <div class="bookmark">
205 <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&bmodify=${bid}">Modify</a>
206 <a class="link" href="${url}")"><img src="${BDB}/favicons/${bid}.ico"/>${name}</a>
214 fmodify="$(GET fmodify |checkid )"
215 fdelete="$(GET fdelete |checkid )"
216 fmove="$(GET fmove |checkid )"
218 if [ -n "$fmodify" ]; then
219 read fid fname order <"${BDB}/${fmodify}.bm"
221 <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
222 <h1>Rename Folder: ${fname}</h1>
223 <input type="hidden" name="fid" value="${fid}" />
224 <label class="tab">Rename</label>
226 href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a>
228 href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
229 <input type="text" name="name" value="${fname}" />
230 <button type="submit" name="control" value="confirm">OK</button>
231 <button type="submit" name="control" value="cancel">Cancel</button>
234 elif [ -n "$fdelete" ]; then
235 read fid fname order <"${BDB}/${fdelete}.bm"
237 <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=delfolder">
238 <h1>Delete Folder: ${fname}</h1>
239 <input type="hidden" name="fid" value="${fid}" />
240 <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a>
241 <label class="tab">Delete</label>
243 href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
244 <label>Pass Bookmarks on to:</label>
245 <select name="target">
246 $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
247 <option value="____________">(none)</option>
249 <button type="submit" name="control" value="confirm">OK</button>
250 <button type="submit" name="control" value="cancel">Cancel</button>
253 elif [ -n "$fmove" ]; then
254 read fid fname order <"${BDB}/${fmove}.bm"
256 <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
257 <h1>Move Folder: ${fname}</h1>
258 <input type="hidden" name="fid" value="${fid}" />
259 <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a>
260 <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a>
261 <label class="tab">Move</label>
262 <label>Move before folder:</label>
263 <select name="target">
264 $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
265 <option value="____________">(last)</option>
267 <button type="submit" name="control" value="confirm">OK</button>
268 <button type="submit" name="control" value="cancel">Cancel</button>
276 | while read fid fname order; do
278 <section class="folder" id="${fid}">
280 <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Modify</a>
281 $(list_bookmarks "$fid")
282 <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newbookmark">
283 <input type="hidden" name="fid" value="${fid}" />
284 <input type="text" name="name" value="" placeholder="Name" />
285 <input type="text" name="url" value="" placeholder="URL" />
286 <button type="submit">New Bookmark</button>
293 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
297 <title>Bookman - Your Collection</title>
298 <link rel="stylesheet" type="text/css" href="bookmarks.css" />
299 </head><body id="collection">
302 <form class="newfolder" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newfolder">
303 <input type="text" name="name" value="" placeholder="New Folder" />
304 <button type="submit">New</button>