#!/bin/sh _EXEC="${_EXEC:-.}" _DATA="${_DATA:-.}" SESSION_TIMEOUT=43200 . "$_EXEC/cgilite/logging.sh" . "$_EXEC/cgilite/cgilite.sh" . "$_EXEC/cgilite/session.sh" . "$_EXEC/cgilite/storage.sh" 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' \ "Content-Security-Policy: script-src 'none'" \ '' { printf '[html [head [meta name="viewport" content="width=device-width"] [link rel="stylesheet" type="text/css" href="/webchat.css"] [title Webchat] ] [body class="%s" ' "$page" [ "$QUERY_STRING" = settings ] && settings_menu cat printf '] ]' } |"$_EXEC/cgilite/html-sh.sed" -u } settings_menu(){ local nick="$(HTML "${nickname#\?}")" printf ' [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 if [ "$NICK_REGISTRATION" != on -o "$nickname" = '?Guest' ]; then printf ' [a .section href="#nick" Nickname] [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] ]' "$nick" "$nick" fi printf ']' } . "$_EXEC/usernick.sh" case ${LOCATION} in 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 ;; @?*) 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 ;; '') 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 / ;; esac