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"
75 QRYID="$(GET id |checkid)"
76 COKID="$(COOKIE id |checkid)"
79 case "$(GET action)" in
83 { git init "users/${NEWID}" || mkdir -p "users/${NEWID}"; } >&-
85 printf '%s 303 See Other\r\n' "$SERVER_PROTOCOL"
86 printf 'Location: %s\r\n' "${SCRIPT_NAME}?id=${NEWID}"
87 SET_COOKIE +8640000 "id=${NEWID}"
92 name="$(POST name |head -n1)"
95 head -qn1 "${BDB}"/????????????.bm \
101 order="$(((order + 1000) / 1000 * 1000))"
102 if [ -n "$name" -a -d "${BDB}" ]; then
103 printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"${BDB}/${fid}.bm"
105 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
108 name="$(POST name |head -n1)"
109 fid="$(POST fid | checkid)"
110 file="${BDB}/${fid}.bm"
111 if [ "$(POST control)" = confirm -a -n "$name" -a -f "$file" ]; then
112 order="$(head -n1 "$file" |cut -f3 || printf 1000)"
113 printf '%s\t%s\t%s\n' "$fid" "$(HTML "$name")" "$order" >"${file%.bm}.tmp"
114 tail -n+2 "$file" >>"${file%.bm}.tmp"
115 mv "${file%.bm}.tmp" "$file"
117 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
120 fid="$(POST fid | checkid)"
121 name="$(POST name |head -n1)"
122 url="$(POST url |head -n1)"
123 file="${BDB}/${fid}.bm"
125 if [ -n "$name" -a -f "${file}" ]; then
126 printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$(HTML "$url")" >>"${file}"
128 getFavicon "$url" "$bid"
129 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
132 bid="$(POST bid | checkid)"
133 name="$(POST name |head -n1)"
134 url="$(POST url |head -n1)"
135 file="$(grep -lE "^${bid}" "${BDB}"/????????????.bm)"
136 if [ -w "$file" -a -n "$name" -a -n "$url" ]; then
137 bm="$(printf '%s\t%s\t%s' "$bid" "$(HTML "$name")" "$(HTML "$url")" |sed -r 's;[\&\;];\\&;g;')"
138 sed -ri "s;^${bid}\t.*$;${bm};" "$file"
140 getFavicon "$url" "$bid"
141 REDIRECT "${SCRIPT_NAME}?id=${QRYID}#${fid}"
145 if [ -z "$QRYID" -a -n "$COKID" ]; then
146 REDIRECT "${SCRIPT_NAME}?id=${COKID}"
147 elif [ -n "$QRYID" -a -z "$COKID" ]; then
148 SET_COOKIE +8640000 "id=${QRYID}"
151 if [ -z "$QRYID" -a -z "$COKID" ]; then
152 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
157 <title>Bookman - New Collection</title>
158 </head><body id="newcollection">
159 <h1>You have not yet set up a collection on this server.</h1>
160 Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
164 elif ! [ -d "users/${QRYID}" ]; then
165 printf '%s 404 Not Found\r\n' "$SERVER_PROTOCOL"
166 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
171 <title>Bookman - 404</title>
172 </head><body id="missingcollection">
173 <h1>The collection you requested does not exist on this server.</h1>
174 Click <a href="${SCRIPT_NAME}?action=newid">here</a> to start a new collection.
182 bmodify="$(GET bmodify |checkid)"
184 tail -n+2 "${BDB}/${fid}.bm" \
185 | while read bid name url; do
186 if [ "${bid}" = "$bmodify" ]; then
188 <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modbookmark">
189 <input type="hidden" name="bid" value="${bid}" />
190 <input type="text" name="name" value="${name}")" placeholder="Name" />
191 <input type="text" name="url" value="${url}")" placeholder="URL" />
192 <button type="submit">Modify</button>
197 <div class="bookmark">
198 <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&bmodify=${bid}">Modify</a>
199 <a class="link" href="${url}")"><img src="${BDB}/favicons/${bid}.ico"/>${name}</a>
207 fmodify="$(GET fmodify |checkid )"
208 fdelete="$(GET fdelete |checkid )"
209 fmove="$(GET fmove |checkid )"
211 head -qn1 "${BDB}"/????????????.bm \
213 | while read fid fname order; do
215 <section class="folder" id="${fid}">
217 <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Modify</a>
218 $(list_bookmarks "$fid")
219 <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newbookmark">
220 <input type="hidden" name="fid" value="${fid}" />
221 <input type="text" name="name" value="" placeholder="Name" />
222 <input type="text" name="url" value="" placeholder="URL" />
223 <button type="submit">New Bookmark</button>
227 if [ "$fid" = "$fmodify" ]; then
229 <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
230 <input type="hidden" name="fid" value="${fid}" />
231 <label>Rename</label><a
232 href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a><a
233 href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
234 <input type="text" name="name" value="${fname}" />
235 <button type="submit" name="control" value="confirm">OK</button>
236 <button type="submit" name="control" value="cancel">Cancel</button>
239 elif [ "$fid" = "$fdelete" ]; then
241 <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
242 <input type="hidden" name="fid" value="${fid}" />
243 <a href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a><label
245 href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
246 <input type="text" name="name" value="${fname}" />
247 <button type="submit" name="control" value="confirm">OK</button>
248 <button type="submit" name="control" value="cancel">Cancel</button>
251 elif [ "$fid" = "$fmove" ]; then
253 <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
254 <input type="hidden" name="fid" value="${fid}" />
255 <a href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a><a
256 href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a><label
258 <input type="text" name="name" value="${fname}" />
259 <button type="submit" name="control" value="confirm">OK</button>
260 <button type="submit" name="control" value="cancel">Cancel</button>
267 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
271 <title>Bookman - Your Collection</title>
272 <link rel="stylesheet" type="text/css" href="bookmarks.css" />
273 </head><body id="collection">
275 <form class="newfolder" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newfolder">
276 <input type="text" name="name" value="" placeholder="New Folder" />
277 <button type="submit">New</button>