]> git.plutz.net Git - httpchat/blobdiff - index.cgi
force nick menu to be open, when no other options available
[httpchat] / index.cgi
index f44d288db0e41ba30f093e2a1c485424b61172ed..a1b6a08689c823dc75568902eb8c1d1bfad07df0 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,7 +1,7 @@
 #!/bin/sh
 
-_EXEC=.
-_DATA=.
+_EXEC="${_EXEC:-.}"
+_DATA="${_DATA:-.}"
 SESSION_TIMEOUT=43200
 . "$_EXEC/cgilite/logging.sh"
 . "$_EXEC/cgilite/cgilite.sh"
@@ -12,6 +12,12 @@ 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 '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
@@ -31,21 +37,32 @@ yield_page(){
 }
 
 settings_menu(){
+  local nick="$(HTML "${nickname#\?}")"
   printf '
-    [form #settings method="POST" action="?"
+    [form #settings method="POST" action="?settings"
       [hidden "session_key" "%s"]
-      [h1 Settings][a .settings href="?" Close]'
-  printf '
+      [h1 Settings][a .settings href="?" Close]
+  ' "$SESSION_KEY"
+  if [ "$ERROR" ]; then
+    printf '[p .error %s %s]' "${ERROR%% *}" "$(HTML "${ERROR#.* }")"
+    unset ERROR
+  fi
+  if [ "$NICK_REGISTRATION" != on -o "$nickname" = '?Guest' ]; then
+    printf '
       [a .section href="#nick" Nickname]
-      [div #nick [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
-  ' "$SESSION_KEY" "$(HTML "${nickname#\?}")"
-  printf '
+      [div #nick .open [input name="nickname" placeholder="%s"][submit "action" "nick" Set Cookie]]
+    ' "$nick"
+  else
+    printf '
+      [a .section href="#nick" Nickname]
+      [div #nick [input name="nickname" placeholder="%s"][submit "action" "nick" Set Cookie]]
       [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#\?}")"
+      ]' "$nick" "$nick"
+  fi
   printf ']'
 }
 
@@ -54,10 +71,11 @@ settings_menu(){
 case ${LOCATION} in
   webchat.css)
     . "$_EXEC/cgilite/file.sh"
-    FILE "$_EXEC/webchat.css"
-    exit 0
+    FILE "$_EXEC/${LOCATION}"
+    return 0
     ;;
   \&?*)
+    [ "$(COOKIE nick)" -o "$QUERY_STRING" = settings ] || REDIRECT "/$LOCATION?settings#nick"
     chatfile="$_DATA/${LOCATION}/channel"
     . "$_EXEC/channel.sh"
     exit 0
@@ -75,6 +93,7 @@ case ${LOCATION} in
     if [ -d "$_DATA/@${LOCATION#~}" ]; then
       pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
     else 
+      # ToDo Edit / Display of public user information
       REDIRECT /
     fi
     ;;