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 &
14 title="${1:-WebTXT}" page="$2"
15 printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
16 "Content-Security-Policy: script-src 'none'" \
20 [meta name="viewport" content="width=device-width"]
21 [link rel="stylesheet" type="text/css" href="common.css"]
22 [link rel="stylesheet" type="text/css" href="webnote.css"]
28 } |"$_EXEC/cgilite/html-sh.sed" -u
32 local name page="${1##*/}"
33 name="$(sed -nE "/[a-zA-Z0-9].[^\r ]/{s;\r$;;; p; q;};" "$_DATA/$page")"
34 [ "$name" ] && printf %s "$name" \
38 recent="$(COOKIE pages)"
40 case ${PATH_INFO##*/} in
41 favicon.ico) printf '%s\r\n' 'Content-Length: 0' '';;
42 common.css) FILE "$_EXEC/cgilite/common.css";;
43 webnote.css) FILE "$_EXEC/webnote.css";;
45 [form .new action=new [button type=submit New Note]
46 $(if [ "$recent" ]; then
47 printf '[h2 Recent Pages][ul .recent'
48 for page in $recent; do
49 [ -f "$_DATA/$(printf %s "$page" |checkid)" ] \
50 && printf '[li [a href="./%s" . %s]]' "$page" "$(pagename "$page" |HTML)"
61 git -C "$_DATA" add "$newid" >/dev/null
62 git -C "$_DATA" commit -m "new note \"${newid}\"" "$newid" >/dev/null
67 doc="$_DATA/$(printf %s ${PATH_INFO##*/} |checkid)"
69 if [ ! -f "$doc" ]; then
70 REDIRECT "${PATH_INFO%/*}/"
74 [ $REQUEST_METHOD = POST ] && case $(POST action) in
76 if temp=$(SLOCK "$doc"); then
77 yield_page "$(pagename "$doc" |HTML)" <<-EOF
79 [input type=hidden name=session_key value="$SESSION_KEY"]
80 [button type=submit name=action value=cancel Cancel]
81 [button type=submit name=action value=update Update]
82 [textarea name=document . $(HTML <"$doc")]
86 yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF
87 [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.]]
97 if temp=$(CHECK_SLOCK "$doc"); then
99 POST document >"${doc}"
100 git -C "$_DATA" commit -m "update note ${doc##*/} \"$(pagename "$doc")\"" "${doc##*/}" >/dev/null
101 REDIRECT "$PATH_INFO"
103 yield_page "$(pagename "$doc" |HTML) - Error" <<-EOF
104 [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!]]
105 [p Copy your Content for reference:]
106 [div .text . $(POST document |HTML)]
113 printf %s "$recent" |grep -qwF "${doc##*/}" \
114 || SET_COOKIE +$((90 * 86400)) pages="${recent}${recent+ }${doc##*/}" Path="${PATH_INFO%/*}/"
116 yield_page "$(pagename "$doc" |HTML)" <<-EOF
118 [input type=hidden name=session_key value="$SESSION_KEY"]
119 [button type=submit name=action value=edit Edit]
121 [div .text . $(markdown <"$doc")]