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