3 _EXEC="${_EXEC:-${0%/*}/}"
6 . "$_EXEC"/cgilite/cgilite.sh
7 . "$_EXEC"/cgilite/session.sh
8 . "$_EXEC"/cgilite/file.sh
9 . "$_EXEC"/session_lock.sh
11 git init "$_DATA" >/dev/null &
13 export MD_HTML="false"
15 local awkbin=`which awk`
16 if [ "$awkbin" ]; then
17 "$awkbin" -f "$_EXEC"/cgilite/markdown.awk
19 busybox awk -f "$_EXEC"/cgilite/markdown.awk
24 title="${1:-WebTXT}" page="$2"
25 printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
26 "Content-Security-Policy: script-src 'none'" \
30 [meta name="viewport" content="width=device-width"]
31 [link rel="stylesheet" type="text/css" href="common.css"]
32 [link rel="stylesheet" type="text/css" href="webnote.css"]
38 } |"$_EXEC/cgilite/html-sh.sed" -u
42 local name page="${1##*/}"
43 name="$(sed -nE "/[a-zA-Z0-9].[^\r ]/{s;\r$;;; p; q;};" "$_DATA/$page")"
44 [ "$name" ] && printf %s "$name" \
48 recent="$(COOKIE pages)"
50 case ${PATH_INFO##*/} in
51 favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
52 common.css) FILE "$_EXEC/cgilite/common.css";;
53 webnote.css) FILE "$_EXEC/webnote.css";;
55 [form .new action=new [button type=submit New Note]
56 $(if [ "$recent" ]; then
57 printf '[h2 Recent Pages][ul .recent'
58 for page in $recent; do
59 [ -f "$_DATA/$(printf %s "$page" |checkid)" ] \
60 && printf '[li [a href="./%s" . %s]]' "$page" "$(pagename "$page" |HTML)"
71 git -C "$_DATA" add "$newid" >/dev/null
72 git -C "$_DATA" commit -m "new note \"${newid}\"" "$newid" >/dev/null
77 doc="$_DATA/$(printf %s ${PATH_INFO##*/} |checkid)"
79 if [ ! -f "$doc" ]; then
80 REDIRECT "${PATH_INFO%/*}/"
84 [ $REQUEST_METHOD = POST ] && case $(POST action) in
86 if temp=$(SLOCK "$doc"); then
87 yield_page "$(pagename "$doc" |HTML)" <<-EOF
89 [input type=hidden name=session_key value="$SESSION_KEY"]
90 [button type=submit name=action value=cancel Cancel]
91 [button type=submit name=action value=update Update]
92 [textarea name=document . $(HTML <"$doc")]
96 yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF
97 [p .error .locked Someone else is already editing this Dokument. Wait a few minutes and try again. [a href="$PATH_INFO" Nothing else I can do.]]
104 REDIRECT "$PATH_INFO"
107 if temp=$(CHECK_SLOCK "$doc"); then
109 POST document >"${doc}"
110 git -C "$_DATA" commit -m "update note ${doc##*/} \"$(pagename "$doc")\"" "${doc##*/}" >/dev/null
111 REDIRECT "$PATH_INFO"
113 yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF
114 [p .error .stolen Your edit took too long and someone else is now editing this file. [a href="$PATH_INFO" Dang, I must be quicker next time!]]
115 [p Copy your Content for reference:]
116 [div .text . $(POST document |HTML)]
123 printf %s "$recent" |grep -qwF "${doc##*/}" \
124 || SET_COOKIE +$((90 * 86400)) pages="${recent}${recent+ }${doc##*/}" Path="${PATH_INFO%/*}/"
126 yield_page "$(pagename "$doc" |HTML)" <<-EOF
128 [input type=hidden name=session_key value="$SESSION_KEY"]
129 [button type=submit name=action value=edit Edit]
131 [div .text . $(markdown <"$doc")]