]> git.plutz.net Git - httpchat/blobdiff - index.cgi
fix syntax error m)
[httpchat] / index.cgi
index ff9e563f356689f95115ddb1aaac6f4f4df42bbe..23139976acc4fdd5dd0e135dd4421193dd1e5100 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -12,6 +12,13 @@ LOCATION="$(PATH "$PATH_INFO")"
 LOCATION="${LOCATION#/}"
 LOCATION="${LOCATION%%/*}"
 
+NICK_REGISTRATION="${NICK_REGISTRATION:-on}"
+CHANNEL_LIST="${CHANNEL_LIST:-off}"
+
+# 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,6 +38,7 @@ yield_page(){
 }
 
 settings_menu(){
+  local nick="$(HTML "${nickname#\?}")"
   printf '
     [form #settings method="POST" action="?settings"
       [hidden "session_key" "%s"]
@@ -40,17 +48,22 @@ settings_menu(){
     printf '[p .error %s %s]' "${ERROR%% *}" "$(HTML "${ERROR#.* }")"
     unset ERROR
   fi
-  printf '
+  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]]
-  ' "$(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 ']'
 }
 
@@ -85,9 +98,24 @@ case ${LOCATION} in
       REDIRECT /
     fi
     ;;
-  '') yield_page front <<-EOF
-       Front
+  '')
+    if [ "$(POST action)" = join ]; then
+      REDIRECT "./&$(POST channel |URL)"
+    else
+      yield_page front <<-EOF
+       [h1 Webchat]
+       [form method=POST
+         [label Join Channel: [input name=channel value='' placeholder="Name of Channel"][button type=submit name=action value=join Join]]
+       ]
+       $(if [ "$CHANNEL_LIST" = on ]; then
+         printf '[h2 Existing channels][div #channels'
+         for chan in "$_DATA/&"*; do
+           printf '[a href="./%s" . %s]\n' "$(HTML "${chan##*/}")" "$(HTML "${chan##*/}")"
+         done
+         printf ']'
+       fi)
        EOF
+    fi
     ;;
   *) REDIRECT /
     ;;