]> git.plutz.net Git - httpchat/blobdiff - index.cgi
always submit most current nicklist
[httpchat] / index.cgi
index 2daabd824e750495e42b0bf42f318fbd5b576476..ac9a110149f9e8b79a992b946b4cd6321c2df85c 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,7 +1,8 @@
 #!/bin/sh
 
-_EXEC=.
-_DATA=.
+_EXEC="${_EXEC:-.}"
+_DATA="${_DATA:-.}"
+SESSION_TIMEOUT=43200
 . "$_EXEC/cgilite/logging.sh"
 . "$_EXEC/cgilite/cgilite.sh"
 . "$_EXEC/cgilite/session.sh"
@@ -11,9 +12,17 @@ LOCATION="$(PATH "$PATH_INFO")"
 LOCATION="${LOCATION#/}"
 LOCATION="${LOCATION%%/*}"
 
+NICK_REGISTRATION="${NICK_REGISTRATION:-on}"
+
+# ToDo:
+# COOKIE_NICK_EXPIRE=$((86400 * 14))
+# REGEISTERED_NICK_EXPIRE=$((86400 * 365))
+
 yield_page(){
   page="$1"
-  printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
+  printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
+                  "Content-Security-Policy: script-src 'none'" \
+                  ''
   { printf '[html
     [head
       [meta name="viewport" content="width=device-width"]
@@ -21,6 +30,7 @@ yield_page(){
       [title Webchat]
     ] [body class="%s"
   ' "$page"
+  [ "$QUERY_STRING" = settings ] && settings_menu
   cat
   printf '] ]'
   } |"$_EXEC/cgilite/html-sh.sed" -u
@@ -28,48 +38,63 @@ yield_page(){
 
 settings_menu(){
   printf '
-    [input #check_settings type="checkbox"][label for=check_settings Settings]
-    [div #settings
-      [h1 Settings][label for=check_settings Close]
-      [input #set_nick type=radio name="setting" value="nick" selected][label for=set_nick Nickname]
-      [div [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
-    ]
+    [form #settings method="POST" action="?settings"
+      [hidden "session_key" "%s"]
+      [h1 Settings][a .settings href="?" Close]
+  ' "$SESSION_KEY"
+  if [ "$ERROR" ]; then
+    printf '[p .error %s %s]' "${ERROR%% *}" "$(HTML "${ERROR#.* }")"
+    unset ERROR
+  fi
+  printf '
+      [a .section href="#nick" Nickname]
+      [div #nick [input name="nickname" placeholder="%s"][submit "action" "nick" Set Cookie]]
   ' "$(HTML "${nickname#\?}")"
+  [ "$NICK_REGISTRATION" = on -a "$nickname" != '?Guest' ] && printf '
+      [a .section href="#register" Register Nickname]
+      [div #register
+        [p Registration will set a permanent Cookie in your Browser.
+           Registration requires neither a password, nor an email address.]
+        [input name="regnick" value="%s"][submit "action" "register" Register]
+      ]' "$(HTML "${nickname#\?}")"
+  printf ']'
 }
 
+. "$_EXEC/usernick.sh"
+
 case ${LOCATION} in
-  \&?*) chatfile="$_DATA/${LOCATION}"
-       . $_EXEC/channel.sh
-       exit 0
-   ;;
-  @?*) if [ -d "$_DATA/${LOCATION}" ]; then
-        chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
-       . $_EXEC/channel.sh
-      else
-        REDIRECT /
-      fi
-       exit 0
-   ;;
-  ~?*) if [ -d "$_DATA/@${LOCATION#~}" ]; then
-        pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
-        page=pubinfo
-      else 
-        REDIRECT /
-      fi
-   ;;
   webchat.css)
-    . "$_EXEC/file.sh"
-    FILE "$_EXEC/webchat.css"
+    . "$_EXEC/cgilite/file.sh"
+    FILE "$_EXEC/${LOCATION}"
+    return 0
+    ;;
+  \&?*)
+    [ "$(COOKIE nick)" -o "$QUERY_STRING" = settings ] || REDIRECT "/$LOCATION?settings#nick"
+    chatfile="$_DATA/${LOCATION}/channel"
+    . "$_EXEC/channel.sh"
     exit 0
     ;;
-  '') page=front;;
-  *) REDIRECT /;;
-esac
-
-case "$page $(POST action)" in
-  pubinfo\ *);;
-  front\ *) yield_page front <<-EOF
+  @?*)
+    if [ -d "$_DATA/${LOCATION}" ]; then
+      chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
+      . "$_EXEC/channel.sh"
+    else
+      REDIRECT /
+    fi
+    exit 0
+    ;;
+  ~?*)
+    if [ -d "$_DATA/@${LOCATION#~}" ]; then
+      pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
+    else 
+      # ToDo Edit / Display of public user information
+      REDIRECT /
+    fi
+    ;;
+  '') yield_page front <<-EOF
        Front
        EOF
     ;;
+  *) REDIRECT /
+    ;;
 esac