]> git.plutz.net Git - httpchat/blob - index.cgi
force nick menu to be open, when no other options available
[httpchat] / index.cgi
1 #!/bin/sh
2
3 _EXEC="${_EXEC:-.}"
4 _DATA="${_DATA:-.}"
5 SESSION_TIMEOUT=43200
6 . "$_EXEC/cgilite/logging.sh"
7 . "$_EXEC/cgilite/cgilite.sh"
8 . "$_EXEC/cgilite/session.sh"
9 . "$_EXEC/cgilite/storage.sh"
10
11 LOCATION="$(PATH "$PATH_INFO")"
12 LOCATION="${LOCATION#/}"
13 LOCATION="${LOCATION%%/*}"
14
15 NICK_REGISTRATION="${NICK_REGISTRATION:-on}"
16
17 # ToDo:
18 # COOKIE_NICK_EXPIRE=$((86400 * 14))
19 # REGEISTERED_NICK_EXPIRE=$((86400 * 365))
20
21 yield_page(){
22   page="$1"
23   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
24                   "Content-Security-Policy: script-src 'none'" \
25                   ''
26   { printf '[html
27     [head
28       [meta name="viewport" content="width=device-width"]
29       [link rel="stylesheet" type="text/css" href="/webchat.css"]
30       [title Webchat]
31     ] [body class="%s"
32   ' "$page"
33   [ "$QUERY_STRING" = settings ] && settings_menu
34   cat
35   printf '] ]'
36   } |"$_EXEC/cgilite/html-sh.sed" -u
37 }
38
39 settings_menu(){
40   local nick="$(HTML "${nickname#\?}")"
41   printf '
42     [form #settings method="POST" action="?settings"
43       [hidden "session_key" "%s"]
44       [h1 Settings][a .settings href="?" Close]
45   ' "$SESSION_KEY"
46   if [ "$ERROR" ]; then
47     printf '[p .error %s %s]' "${ERROR%% *}" "$(HTML "${ERROR#.* }")"
48     unset ERROR
49   fi
50   if [ "$NICK_REGISTRATION" != on -o "$nickname" = '?Guest' ]; then
51     printf '
52       [a .section href="#nick" Nickname]
53       [div #nick .open [input name="nickname" placeholder="%s"][submit "action" "nick" Set Cookie]]
54     ' "$nick"
55   else
56     printf '
57       [a .section href="#nick" Nickname]
58       [div #nick [input name="nickname" placeholder="%s"][submit "action" "nick" Set Cookie]]
59       [a .section href="#register" Register Nickname]
60       [div #register
61         [p Registration will set a permanent Cookie in your Browser.
62            Registration requires neither a password, nor an email address.]
63         [input name="regnick" value="%s"][submit "action" "register" Register]
64       ]' "$nick" "$nick"
65   fi
66   printf ']'
67 }
68
69 . "$_EXEC/usernick.sh"
70
71 case ${LOCATION} in
72   webchat.css)
73     . "$_EXEC/cgilite/file.sh"
74     FILE "$_EXEC/${LOCATION}"
75     return 0
76     ;;
77   \&?*)
78     [ "$(COOKIE nick)" -o "$QUERY_STRING" = settings ] || REDIRECT "/$LOCATION?settings#nick"
79     chatfile="$_DATA/${LOCATION}/channel"
80     . "$_EXEC/channel.sh"
81     exit 0
82     ;;
83   @?*)
84     if [ -d "$_DATA/${LOCATION}" ]; then
85       chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
86       . "$_EXEC/channel.sh"
87     else
88       REDIRECT /
89     fi
90     exit 0
91     ;;
92   ~?*)
93     if [ -d "$_DATA/@${LOCATION#~}" ]; then
94       pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
95     else 
96       # ToDo Edit / Display of public user information
97       REDIRECT /
98     fi
99     ;;
100   '') yield_page front <<-EOF
101         Front
102         EOF
103     ;;
104   *) REDIRECT /
105     ;;
106 esac