5 . "$_EXEC/cgilite/logging.sh"
6 . "$_EXEC/cgilite/cgilite.sh"
7 . "$_EXEC/cgilite/session.sh"
8 . "$_EXEC/cgilite/storage.sh"
11 LOCATION="$(PATH "$PATH_INFO")"
12 LOCATION="${LOCATION#/}"
13 LOCATION="${LOCATION%%/*}"
16 printf 'Content-Type: text/css; charset=utf-8\r\n\r\n'
18 * { box-sizing: border-box;}
23 border: 1px solid #08b;
34 #check_settings { display: none; }
35 #check_settings + label {
36 display: inline-block;
38 #check_settings + label:before {
44 #check_settings + label + #settings { display: none; }
45 #check_settings:checked + label + #settings {
48 min-width: 20%; max-width: 90%;
51 left: 50%; transform: translate(-50%);
52 background-color: #FFF;
54 border-radius: 1ex 1ex .5ex .5ex;
57 background-color: #08b;
62 border-bottom: 1px solid;
63 border-radius: 1ex 1ex 0 0;
65 #settings label[for=check_settings] {
68 background-color: #F88;
69 border-left: 1px solid;
70 border-radius: 0 1ex 0 0;
74 #settings label[for=check_settings]:before {
78 #settings input[type=radio] { display: none; }
79 #settings input[type=radio] + label + * { display: none; }
80 #settings input[type=radio]:checked + label + * { display: block; }
81 #settings input[type=radio] + label {
84 text-decoration: underline;
85 margin: -1px 1px; padding: 0 1ex;
86 border-top: 1px solid;
87 background-color: #EEE;
89 #settings input[type=radio] + label + * {
90 padding: 1ex 1ex .5ex 1ex;
93 form#channel input[name=message] {
94 display: inline-block;
97 width: calc(100% - 5ex - 1px);
99 form#channel button[value=submit] { display: none; }
100 #chat .message .date {
104 #chat .message .nick {
107 #chat .message .nick .indicator {
116 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
119 [meta name="viewport" content="width=device-width"]
120 [link rel="stylesheet" type="text/css" href="/webchat.css"]
126 } |"$_EXEC/cgilite/html-sh.sed" -u
131 [input #check_settings type="checkbox"][label for=check_settings Settings]
133 [h1 Settings][label for=check_settings Close]
134 [input #set_nick type=radio name="setting" value="nick" selected][label for=set_nick Nickname]
135 [div [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
137 ' "$(HTML "${nickname#\?}")"
141 \&?*) chatfile="$_DATA/${LOCATION}"
144 @?*) if [ -d "$_DATA/${LOCATION}" ]; then
145 chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
151 ~?*) if [ -d "$_DATA/@${LOCATION#~}" ]; then
152 pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
158 webchat.css) yield_css; exit 0;;
163 if [ "$(COOKIE nick)" ]; then
164 nickname="?$(COOKIE nick)"
169 if [ -f "$chatfile" ]; then
170 read -r channelkey x <"$chatfile"
171 channelkey="$( printf '%s-%s' "$channelkey" "$SESSION_ID" |sha256sum)"
174 case "$page $(POST action)" in
176 if [ ! -f "$chatfile" ]; then
177 { randomid; printf ' '; STRING "$nickname"; echo; } >"$chatfile"
179 REDIRECT "$(URL "/$LOCATION")"
182 if [ -f "$chatfile" -a "$channelkey" = "$(POST channelkey)" ]; then
183 printf "%s %s: %s\n" "$(date +%F_%T)" "$(STRING "$nickname")" "$(POST message |STRING)" >>"$chatfile"
185 REDIRECT "$(URL "/$LOCATION")"
188 SET_COOKIE +1209600 "nick=$(POST nickname |URL)"
189 REDIRECT "$(URL "/$LOCATION")"
192 if [ ! -f "$chatfile" ]; then
193 yield_page create <<-EOF
194 [form #nonexist method=POST action="$(URL "/$LOCATION")"
195 There is no channel named $(HTML "$LOCATION")
196 [submit "action" "create" Create]
201 [form #channel method=POST action="%s"
202 [submit "action" "submit" style="display: none;"]
203 [input type=hidden name=channelkey value="%s"]
204 %s [input name="message" autofocus=true][submit "action" "submit" Send!]
206 ' "$(URL "/$LOCATION")" "$channelkey" "$(settings_menu)"
207 SHESCAPE='s;[]&<>#."[];\\&;g;'
210 # tail -n30 -f "$chatfile" | {
212 # while read -r date nick message; do
213 # printf '[p .message [span .date %s] [span .nick [span .indicator %s]%s:] [span .message %s]]\n' \
214 # "${date#*_}" "${nick%${nick#?}}" "$(UNSTRING "${nick#?}" |HTML)" "$(UNSTRING "$message" |HTML)"
217 tail -n50 -f "$chatfile" \
219 /^[^ ]+ [^ ]+ [^ ]+$/{
220 h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p;
221 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p;
222 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p;
225 '"$UNSTRING"' '"$SHESCAPE"'
228 } |yield_page channel
232 front\ *) yield_page front <<-EOF