3 if [ "$(COOKIE nick)" ]; then
4 nickname="?$(COOKIE nick)"
9 if [ -f "$chatfile" ]; then
10 read -r channelkey x <"$chatfile"
11 channelkey="$( printf '%s-%s' "$channelkey" "$SESSION_ID" |sha256sum)"
14 case $(POST action) in
16 if [ ! -f "$chatfile" ]; then
17 { randomid; printf ' '; STRING "$nickname"; echo; } >"$chatfile"
19 REDIRECT "$(URL "/$LOCATION")"
22 if [ -f "$chatfile" -a "$channelkey" = "$(POST channelkey)" ]; then
23 printf "%s %s: %s\n" "$(date +%F_%T)" "$(STRING "$nickname")" "$(POST message |STRING)" >>"$chatfile"
25 REDIRECT "$(URL "/$LOCATION")"
28 SET_COOKIE +1209600 "nick=$(POST nickname |URL)"
29 REDIRECT "$(URL "/$LOCATION")"
31 *) if [ ! -f "$chatfile" ]; then
32 yield_page create <<-EOF
33 [form #nonexist method=POST action="$(URL "/$LOCATION")"
34 There is no channel named $(HTML "$LOCATION")
35 [submit "action" "create" Create]
40 [form #channel method=POST action="%s"
41 [submit "action" "submit" style="display: none;"]
42 [input type=hidden name=channelkey value="%s"]
43 %s [input name="message" autofocus=true][submit "action" "submit" Send!]
45 ' "$(URL "/$LOCATION")" "$channelkey" "$(settings_menu)"
46 SHESCAPE='s;[]&<>#."[];\\&;g;'
49 # tail -n30 -f "$chatfile" | {
51 # while read -r date nick message; do
52 # printf '[p .message [span .date %s] [span .nick [span .indicator %s]%s:] [span .message %s]]\n' \
53 # "${date#*_}" "${nick%${nick#?}}" "$(UNSTRING "${nick#?}" |HTML)" "$(UNSTRING "$message" |HTML)"
56 tail -n50 -f "$chatfile" \
58 /^[^ ]+ [^ ]+ [^ ]+$/{
59 h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p;
60 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p;
61 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p;
64 '"$UNSTRING"' '"$SHESCAPE"'