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 &
12 export MD_HTML="false"
15 title="${1:-WebTXT}" page="$2"
16 printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
17 "Content-Security-Policy: script-src 'none'" \
21 [meta name="viewport" content="width=device-width"]
22 [link rel="stylesheet" type="text/css" href="common.css"]
23 [link rel="stylesheet" type="text/css" href="webnote.css"]
29 } |"$_EXEC/cgilite/html-sh.sed" -u
33 local name page="${1##*/}"
34 name="$(sed -nE "/[a-zA-Z0-9].[^\r ]/{s;\r$;;; p; q;};" "$_DATA/$page")"
35 [ "$name" ] && printf %s "$name" \
39 recent="$(COOKIE pages)"
41 case ${PATH_INFO##*/} in
42 favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
43 common.css) FILE "$_EXEC/cgilite/common.css";;
44 webnote.css) FILE "$_EXEC/webnote.css";;
46 [form .new action=new [button type=submit New Note]
47 $(if [ "$recent" ]; then
48 printf '[h2 Recent Pages][ul .recent'
49 for page in $recent; do
50 [ -f "$_DATA/$(printf %s "$page" |checkid)" ] \
51 && printf '[li [a href="./%s" . %s]]' "$page" "$(pagename "$page" |HTML)"
62 git -C "$_DATA" add "$newid" >/dev/null
63 git -C "$_DATA" commit -m "new note \"${newid}\"" "$newid" >/dev/null
68 doc="$_DATA/$(printf %s ${PATH_INFO##*/} |checkid)"
70 if [ ! -f "$doc" ]; then
71 REDIRECT "${PATH_INFO%/*}/"
75 [ $REQUEST_METHOD = POST ] && case $(POST action) in
77 if temp=$(SLOCK "$doc"); then
78 yield_page "$(pagename "$doc" |HTML)" <<-EOF
80 [input type=hidden name=session_key value="$SESSION_KEY"]
81 [button type=submit name=action value=cancel Cancel]
82 [button type=submit name=action value=update Update]
83 [textarea name=document . $(HTML <"$doc")]
87 yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF
88 [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.]]
98 if temp=$(CHECK_SLOCK "$doc"); then
100 POST document >"${doc}"
101 git -C "$_DATA" commit -m "update note ${doc##*/} \"$(pagename "$doc")\"" "${doc##*/}" >/dev/null
102 REDIRECT "$PATH_INFO"
104 yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF
105 [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!]]
106 [p Copy your Content for reference:]
107 [div .text . $(POST document |HTML)]
114 printf %s "$recent" |grep -qwF "${doc##*/}" \
115 || SET_COOKIE +$((90 * 86400)) pages="${recent}${recent+ }${doc##*/}" Path="${PATH_INFO%/*}/"
117 yield_page "$(pagename "$doc" |HTML)" <<-EOF
119 [input type=hidden name=session_key value="$SESSION_KEY"]
120 [button type=submit name=action value=edit Edit]
122 [div .text . $("$_EXEC"/cgilite/markdown.awk <"$doc")]