]> git.plutz.net Git - httpchat/blob - index.cgi
display error messages for invalid nick changes
[httpchat] / index.cgi
1 #!/bin/sh
2
3 _EXEC=.
4 _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 yield_page(){
16   page="$1"
17   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
18                   "Content-Security-Policy: script-src 'none'" \
19                   ''
20   { printf '[html
21     [head
22       [meta name="viewport" content="width=device-width"]
23       [link rel="stylesheet" type="text/css" href="/webchat.css"]
24       [title Webchat]
25     ] [body class="%s"
26   ' "$page"
27   [ "$QUERY_STRING" = settings ] && settings_menu
28   cat
29   printf '] ]'
30   } |"$_EXEC/cgilite/html-sh.sed" -u
31 }
32
33 settings_menu(){
34   printf '
35     [form #settings method="POST" action="?settings"
36       [hidden "session_key" "%s"]
37       [h1 Settings][a .settings href="?" Close]
38   ' "$SESSION_KEY"
39   if [ "$ERROR" ]; then
40     printf '[p .error %s %s]' "${ERROR%% *}" "$(HTML "${ERROR#.* }")"
41     unset ERROR
42   fi
43   printf '
44       [a .section href="#nick" Nickname]
45       [div #nick [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
46   ' "$(HTML "${nickname#\?}")"
47   printf '
48       [a .section href="#register" Register Nickname]
49       [div #register
50         [p Registration will set a permanent Cookie in your Browser.
51            Registration requires neither a password, nor an email address.]
52         [input name="regnick" value="%s"][submit "action" "register" Register]
53       ]' "$(HTML "${nickname#\?}")"
54   printf ']'
55 }
56
57 . "$_EXEC/usernick.sh"
58
59 case ${LOCATION} in
60   webchat.css)
61     . "$_EXEC/cgilite/file.sh"
62     FILE "$_EXEC/webchat.css"
63     exit 0
64     ;;
65   \&?*)
66     chatfile="$_DATA/${LOCATION}/channel"
67     . "$_EXEC/channel.sh"
68     exit 0
69     ;;
70   @?*)
71     if [ -d "$_DATA/${LOCATION}" ]; then
72       chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
73       . "$_EXEC/channel.sh"
74     else
75       REDIRECT /
76     fi
77     exit 0
78     ;;
79   ~?*)
80     if [ -d "$_DATA/@${LOCATION#~}" ]; then
81       pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
82     else 
83       # ToDo Edit / Display of public user information
84       REDIRECT /
85     fi
86     ;;
87   '') yield_page front <<-EOF
88         Front
89         EOF
90     ;;
91   *) REDIRECT /
92     ;;
93 esac