]> git.plutz.net Git - httpchat/blob - index.cgi
split up in multiple files
[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   cat
25   printf '] ]'
26   } |"$_EXEC/cgilite/html-sh.sed" -u
27 }
28
29 settings_menu(){
30   printf '
31     [input #check_settings type="checkbox"][label for=check_settings Settings]
32     [div #settings
33       [h1 Settings][label for=check_settings Close]
34       [input #set_nick type=radio name="setting" value="nick" selected][label for=set_nick Nickname]
35       [div [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]]
36     ]
37   ' "$(HTML "${nickname#\?}")"
38 }
39
40 case ${LOCATION} in
41   \&?*) chatfile="$_DATA/${LOCATION}"
42        . $_EXEC/channel.sh
43        exit 0
44    ;;
45   @?*) if [ -d "$_DATA/${LOCATION}" ]; then
46         chatfile="$_DATA/${LOCATION}/?${SESSION_ID}"
47        . $_EXEC/channel.sh
48       else
49         REDIRECT /
50       fi
51        exit 0
52    ;;
53   ~?*) if [ -d "$_DATA/@${LOCATION#~}" ]; then
54         pubinfo="$_DATA/@${LOCATION#~}/pubinfo"
55         page=pubinfo
56       else 
57         REDIRECT /
58       fi
59    ;;
60   webchat.css)
61     . "$_EXEC/file.sh"
62     FILE "$_EXEC/webchat.css"
63     exit 0
64     ;;
65   '') page=front;;
66   *) REDIRECT /;;
67 esac
68
69 case "$page $(POST action)" in
70   pubinfo\ *);;
71   front\ *) yield_page front <<-EOF
72         Front
73         EOF
74     ;;
75 esac