]> git.plutz.net Git - busy/blob - pages/Wiki.sh
upgraded to fit new shcgi revision, slightly better input validation, switched to...
[busy] / pages / Wiki.sh
1 #!/bin/sh
2
3 # Copyright 2014 Paul Hänsch
4 #
5 # This file is part of Busy
6
7 # Busy is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # Busy is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Busy. If not, see <http://www.gnu.org/licenses/>. 
19
20 info="$(egrep -o '[0-9]{10}_[0-9]{3}' <<<"${_GET[i]}")"
21 edit="$(egrep -o '[0-9]{10}_[0-9]{3}' <<<"${_GET[e]}")"
22  rev="$(egrep -o '[0-9]{10}' <<<"${_GET[r]}")"
23 search="$(sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' <<<"${_GET[s]}")"
24
25 [ -n "$rev" ] && rev=".$rev"
26 if [ -n "$search" ]; then
27   info=''
28   edit=''
29   rev=''
30 fi
31
32 lock="$_DATA/Wiki/${info}.lock"
33 if ([ -r "$lock" ] && [ "$(cut -d: -f2 "$lock")" -lt "$(date +%s)" ]); then
34   rm "$lock"
35   lock=''
36 elif [ -r "$lock" ]; then
37   lock="$(cut -d: -f1 "$lock")"
38 else
39   lock=''
40 fi
41
42 case "$1" in
43   title)
44     echo "Wiki"
45   ;;
46   css)
47     cat ${_EXEC}/templates/Wiki.css
48   ;;
49   body)
50     #. ${_EXEC}/templates/text_wiki.sh
51     if [ -n "$edit" -a -r "$_DATA/Wiki/${edit}${rev}" ]; then
52       title="$(egrep -x 'title=.+' "$_DATA/Wiki/$edit.meta" |cut -d= -f2- || echo '(Untitled)')"
53       . ${_EXEC}/templates/Wiki_edit.page
54     elif [ -n "$info" -a -r "$_DATA/Wiki/${info}${rev}" ]; then
55       title="$(egrep -x 'title=.+' "$_DATA/Wiki/$info.meta" |cut -d= -f2- || echo '(Untitled)')"
56       . ${_EXEC}/templates/Wiki_show.page
57     elif [ -z "$info" ]; then
58       . ${_EXEC}/templates/Wiki_list.page
59     fi
60   ;;
61 esac
62