]> git.plutz.net Git - busy/blob - index.cgi
whoopsie, forgot that m-)
[busy] / index.cgi
1 #!/bin/zsh
2
3 # Copyright 2014 Paul Hänsch
4 #
5 # This file is part of Busy.
6 # (originally written for and copied from Confetti)
7
8 # Busy is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12
13 # Busy is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Affero General Public License for more details.
17
18 # You should have received a copy of the GNU Affero General Public License
19 # along with Busy.  If not, see <http://www.gnu.org/licenses/>. 
20
21 export LC_ALL=de_DE.UTF-8
22
23 # basic functions
24 die() {
25   echo "$*" >/dev/stderr
26   exit 1
27 }
28 debug() { #change to false to disable debugging
29   #true && echo "$*" >>debug
30   true && [ -n "$*" ] && echo -E "$*" >>/dev/stderr
31   true && [ -z "$*" ] && tee /dev/stderr
32 }
33
34 # this program is supposed to be symlinked into a http root directory
35 # we will use the http root as object storage (data directory) and call sub
36 # programs from the directory in which the real executable resides
37 # therefore we need to identify the code and data directories _EXEC and _DATA
38 call="$0"
39 real="$(readlink -f $call)"
40 _EXEC="$(dirname "$real")"  #execution directory
41 _DATA="$(dirname "$call")"  #storage directory
42
43 [ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable"
44
45 # create directories for object storage
46 for each in "$_DATA"/{Home,Tasks,Wiki,QRcodes}; do
47   [ ! -e "$each" ] && mkdir "$each"
48   [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory"
49 done
50
51 # create htaccess file
52 [ -f .htaccess ] || cat >.htaccess <<EOF
53 Options         +ExecCGI
54 AddHandler      cgi-script .cgi
55 DirectoryIndex  index.cgi
56 EOF
57 [ -f .htaccess ] || die "no htaccess file present and unable to create one"
58
59 . "$_EXEC/cgi.sh"
60 . "$_EXEC/constants.sh"
61
62 cgi_get
63
64 if [ -n "$_GET[\"action\"]" ]; then
65   . "$_EXEC/action.sh"
66 elif [ -n "$_GET[\"export\"]" ]; then
67   . "$_EXEC/export.sh"
68 else
69   . "$_EXEC/page.sh"
70 fi