]> git.plutz.net Git - httpchat/blob - index.cgi
hold session key in POST data
[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="?"
36       [hidden "session_key" "%s"]
37       [h1 Settings][a .settings href="?" Close]'
38   printf '
39       [a .section href="#nick" Nickname]
40       [div #nick [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
41   ' "$SESSION_KEY" "$(HTML "${nickname#\?}")"
42   printf '
43       [a .section href="#register" Register Nickname]
44       [div #register
45         [p Registration will set a permanent Cookie in your Browser.
46            Registration requires neither a password, nor an email address.]
47         [input name="regnick" value="%s"][submit "action" "register" Register]
48       ]' "$(HTML "${nickname#\?}")"
49   printf ']'
50 }
51
52 . "$_EXEC/usernick.sh"
53
54 case ${LOCATION} in
55   webchat.css)
56     . "$_EXEC/cgilite/file.sh"
57     FILE "$_EXEC/webchat.css"
58     exit 0
59     ;;
60   \&?*)
61     chatfile="$_DATA/${LOCATION}/channel"
62     . "$_EXEC/channel.sh"
63     exit 0
64     ;;
65   @?*)
66     if [ -d "$_DATA/${LOCATION}" ]; then
67       chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
68       . "$_EXEC/channel.sh"
69     else
70       REDIRECT /
71     fi
72     exit 0
73     ;;
74   ~?*)
75     if [ -d "$_DATA/@${LOCATION#~}" ]; then
76       pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
77     else 
78       REDIRECT /
79     fi
80     ;;
81   '') yield_page front <<-EOF
82         Front
83         EOF
84     ;;
85   *) REDIRECT /
86     ;;
87 esac