]> git.plutz.net Git - busy/blob - actions/wikimeta.sh
51236c9135599d7bc5fc61511016f61dc7f4415b
[busy] / actions / wikimeta.sh
1 #!/bin/zsh
2 # Copyright 2011 - 2014 Paul Haensch
3 # This file is part of Busy
4 #
5 # Busy is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Busy is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
17
18 $ACL_WIKIEDIT || echo "Location: ?p=Error&i=noaccess\n\n"
19 $ACL_WIKIEDIT || exit 0 
20
21 info="$(egrep -o '(^|&)i=[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
22 info="$(echo -E "$_GET[\"i\"]" |grep -Ex '[0-9]{10}_[0-9]{3}')"
23
24 [ -z "$info" ] && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
25 descfile="$_DATA/Wiki/$info.meta"
26 commfile="$_DATA/Wiki/$info.comment.$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
27
28 [ -f "$_DATA/Wiki/$info.lock" ] && rm "$_DATA/Wiki/$info.lock"
29 anchor=$(ls "$_DATA/Wiki" |grep -A2 $info |grep '.meta$' |tail -n1 |cut -d. -f1)
30
31 cgi_post
32 title="$_POST[\"title\"]"
33 description="$_POST[\"desc\"]"
34 comment="$_POST[\"comm\"]"
35 [ -n "$_POST[\"cancel\"]" ] && cancel=true
36
37 if [ -z "$cancel" -a -n "$comment" ]; then
38   touch "$_DATA/Wiki/$info"
39   echo -e "author=${USER}" > "$commfile"
40   echo -e "${comment}" >> "$commfile"
41   echo -n "Location: ?p=Wiki&i=$info\n\n"
42 elif [ -z "$cancel" -a -n "$description" ]; then
43   touch "$_DATA/Wiki/$info"
44   echo -e "title=${title}" > "$descfile"
45   echo -e "description=${description}" >> "$descfile"
46   echo -n "Location: ?p=Wiki#$anchor\n\n"
47 elif [ -n "$cancel" ]; then
48   echo -n "Location: ?p=Wiki#$anchor\n\n"
49 fi