]> git.plutz.net Git - confetti/blob - index.cgi
record course timing in 5 minute steppings
[confetti] / index.cgi
1 #!/bin/zsh
2
3 export LC_ALL=de_DE.UTF-8
4
5 # basic functions
6 die() {
7   echo "$*" >/dev/stderr
8   exit 1
9 }
10 debug() { #change to false to disable debugging
11   #true && echo "$*" >>debug
12   true && [ -n "$*" ] && echo -E "$*" >>/dev/stderr
13   true && [ -z "$*" ] && tee /dev/stderr
14 }
15
16 # this program is supposed to be symlinked into a http root directory
17 # we will use the http root as object storage (data directory) and call sub
18 # programs from the directory in which the real executable resides
19 # therefore we need to identify the code and data directories _EXEC and _DATA
20 call="$0"
21 real="$(readlink -f $call)"
22 _EXEC="$(dirname "$real")"  #execution directory
23 _DATA="$(dirname "$call")"  #storage directory
24
25 [ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable"
26
27 # create directories for object storage
28 for each in "$_DATA"/{vcard,ical,cache,temp,mappings}; do
29   [ ! -e "$each" ] && mkdir "$each"
30   [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory"
31 done
32 touch "$_DATA/mappings/attendance"
33
34 # create htaccess file
35 [ -f .htaccess ] || cat >.htaccess <<EOF
36 Options         +ExecCGI
37 AddHandler      cgi-script .cgi
38 DirectoryIndex  index.cgi
39 EOF
40 [ -f .htaccess ] || die "no htaccess file present and unable to create one"
41
42 . "$_EXEC/cgi.sh"
43
44 cgi_get
45
46 . "$_EXEC/constants.sh"
47
48 if [ -n "$_GET[\"action\"]" ]; then
49   . "$_EXEC/action.sh"
50 elif [ -n "$_GET[\"export\"]" ]; then
51   . "$_EXEC/export.sh"
52 else
53   . "$_EXEC/page.sh"
54 fi