X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=channel.sh;h=b930620ab610a93653cfe14186842f7ac98f38cb;hb=8ab57724f6c6d4d14040a393f51a108c6aba9c60;hp=1f86e5214c061525e5e6486c9db93f03f6367c00;hpb=1b78a6c60a0c44a164dcf12f1e7683008f2cf402;p=httpchat diff --git a/channel.sh b/channel.sh index 1f86e52..b930620 100755 --- a/channel.sh +++ b/channel.sh @@ -7,13 +7,21 @@ fi case $(POST action) in create) - if [ ! -f "$chatfile" ]; then + if mkdir "${_DATA}/${LOCATION}"; then { randomid; printf ' '; STRING "$nickname"; echo; } >"$chatfile" fi REDIRECT "$(URL "/$LOCATION")" ;; submit) - if [ -f "$chatfile" -a "$channelkey" = "$(POST channelkey)" ]; then + read lasttime x <<-EOFread + $(tail -n 50 "$chatfile" |grep -F " $(STRING "$nickname"): " |tail -n1) + EOFread + if [ "$lasttime" ]; then + lasttime="$(date -d "${lasttime%_*} ${lasttime#*_}" +%s)" + else + lasttime=0 + fi + if [ -f "$chatfile" -a "$channelkey" = "$(POST channelkey)" -a "$(POST timenonce)" -ge "$lasttime" ]; then printf "%s %s: %s\n" "$(date +%F_%T)" "$(STRING "$nickname")" "$(POST message |STRING)" >>"$chatfile" fi REDIRECT "$(URL "/$LOCATION")" @@ -32,10 +40,10 @@ else { printf ' [form #channel method="POST" [submit "action" "submit" style="display: none;"] - [input type=hidden name=channelkey value="%s"] + [hidden "session_key" "%s"][hidden "channelkey" "%s"][hidden "timenonce" "%s"] [a .settings href="?settings#nick" Settings][input autocomplete="off" name="message" autofocus=true][submit "action" "submit" Send!] ] - ' "$channelkey" + ' "$SESSION_KEY" "$channelkey" "$_DATE" SHESCAPE='s;[]&<>#."[];\\&;g;' while sleep 10; do printf '\n'; done &