]> git.plutz.net Git - httpchat/blob - index.cgi
introduce nickname registration
[httpchat] / index.cgi
1 #!/bin/sh
2
3 _EXEC=.
4 _DATA=.
5 . "$_EXEC/cgilite/logging.sh"
6 . "$_EXEC/cgilite/cgilite.sh"
7 . "$_EXEC/cgilite/session.sh"
8 . "$_EXEC/cgilite/storage.sh"
9
10 LOCATION="$(PATH "$PATH_INFO")"
11 LOCATION="${LOCATION#/}"
12 LOCATION="${LOCATION%%/*}"
13
14 yield_page(){
15   page="$1"
16   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
17   { printf '[html
18     [head
19       [meta name="viewport" content="width=device-width"]
20       [link rel="stylesheet" type="text/css" href="/webchat.css"]
21       [title Webchat]
22     ] [body class="%s"
23   ' "$page"
24   [ "$QUERY_STRING" = settings ] && settings_menu
25   cat
26   printf '] ]'
27   } |"$_EXEC/cgilite/html-sh.sed" -u
28 }
29
30 settings_menu(){
31   printf '
32     [form #settings method="POST" action="?"
33       [h1 Settings][a .settings href="?" Close]'
34   printf '
35       [a .section href="#nick" Nickname]
36       [div #nick [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
37   ' "$(HTML "${nickname#\?}")"
38   printf '
39       [a .section href="#register" Register Nickname]
40       [div #register
41         [p Registration will set a permanent Cookie in your Browser.
42            Registration requires neither a password, nor an email address.]
43         [input name="regnick" value="%s"][submit "action" "register" Register]
44       ]' "$(HTML "${nickname#\?}")"
45   printf ']'
46 }
47
48 . "$_EXEC/usernick.sh"
49
50 case ${LOCATION} in
51   webchat.css)
52     . "$_EXEC/cgilite/file.sh"
53     FILE "$_EXEC/webchat.css"
54     exit 0
55     ;;
56   \&?*)
57     chatfile="$_DATA/${LOCATION}"
58     . "$_EXEC/channel.sh"
59     exit 0
60     ;;
61   @?*)
62     if [ -d "$_DATA/${LOCATION}" ]; then
63       chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
64       . "$_EXEC/channel.sh"
65     else
66       REDIRECT /
67     fi
68     exit 0
69     ;;
70   ~?*)
71     if [ -d "$_DATA/@${LOCATION#~}" ]; then
72       pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
73     else 
74       REDIRECT /
75     fi
76     ;;
77   '') yield_page front <<-EOF
78         Front
79         EOF
80     ;;
81   *) REDIRECT /
82     ;;
83 esac