From 6b73b82389a8963365d1b437d76ed2070617598d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 20 Nov 2019 20:55:07 +0100 Subject: [PATCH 1/1] framework --- .gitignore | 3 + index.cgi | 236 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 .gitignore create mode 100755 index.cgi diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22b5907 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +&* +@* +serverkey diff --git a/index.cgi b/index.cgi new file mode 100755 index 0000000..e84122c --- /dev/null +++ b/index.cgi @@ -0,0 +1,236 @@ +#!/bin/sh + +_EXEC=. +_DATA=. +. "$_EXEC/cgilite/logging.sh" +. "$_EXEC/cgilite/cgilite.sh" +. "$_EXEC/cgilite/session.sh" +. "$_EXEC/cgilite/storage.sh" + + +LOCATION="$(PATH "$PATH_INFO")" +LOCATION="${LOCATION#/}" +LOCATION="${LOCATION%%/*}" + +yield_css(){ + printf 'Content-Type: text/css; charset=utf-8\r\n\r\n' + cat <"$chatfile" + fi + REDIRECT "$(URL "/$LOCATION")" + ;; + channel\ submit) + if [ -f "$chatfile" -a "$channelkey" = "$(POST channelkey)" ]; then + printf "%s %s: %s\n" "$(date +%F_%T)" "$(STRING "$nickname")" "$(POST message |STRING)" >>"$chatfile" + fi + REDIRECT "$(URL "/$LOCATION")" + ;; + channel\ nick) + SET_COOKIE +1209600 "nick=$(POST nickname |URL)" + REDIRECT "$(URL "/$LOCATION")" + ;; + channel\ *) + if [ ! -f "$chatfile" ]; then + yield_page create <<-EOF + [form #nonexist method=POST action="$(URL "/$LOCATION")" + There is no channel named $(HTML "$LOCATION") + [submit "action" "create" Create] + ] + EOF + else + { printf ' + [form #channel method=POST action="%s" + [submit "action" "submit" style="display: none;"] + [input type=hidden name=channelkey value="%s"] + %s [input name="message" autofocus=true][submit "action" "submit" Send!] + ] + ' "$(URL "/$LOCATION")" "$channelkey" "$(settings_menu)" + SHESCAPE='s;[]&<>#."[];\\&;g;' + + printf '[div #chat' + # tail -n30 -f "$chatfile" | { + # read x + # while read -r date nick message; do + # printf '[p .message [span .date %s] [span .nick [span .indicator %s]%s:] [span .message %s]]\n' \ + # "${date#*_}" "${nick%${nick#?}}" "$(UNSTRING "${nick#?}" |HTML)" "$(UNSTRING "$message" |HTML)" + # done + # } + tail -n50 -f "$chatfile" \ + | sed -nuE ' + /^[^ ]+ [^ ]+ [^ ]+$/{ + h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p; + g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p; + g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p; + } + b; :ESC + '"$UNSTRING"' '"$SHESCAPE"' + /^a/bA; /^b/bB; + ' + } |yield_page channel + fi + ;; + pubinfo\ *);; + front\ *) yield_page front <<-EOF + Front + EOF + ;; +esac -- 2.39.2