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