]> git.plutz.net Git - busy/blob - write/taskmeta.cgi
prevent endless loop on malformed svn path
[busy] / write / taskmeta.cgi
1 #!/bin/zsh
2 # Copyright 2011 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 #info="$(egrep -o '(^|&)i=[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
19 [ "$HTTPS" = "on" ] && PROTO=https || proto=http
20
21 . ../auth/permissions.sh
22 $ACL_CREATETASK || echo "Location: ${proto}://${HTTP_HOST}/?p=Error&i=noaccess\n\n"
23 $ACL_CREATETASK || exit 0
24
25 info="$(sed -r 's:(^|.*&)i=(.*)|.*:\2:;s:&.*::' <<<"${QUERY_STRING}")"
26
27 [ -z "$info" ] && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
28 descfile="../Tasks/$info.meta"
29 commfile="../Tasks/$info.comment.$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
30
31 [ -f "../Tasks/$info.lock" ] && rm "../Wiki/$info.lock"
32 anchor=$(ls ../Tasks |grep -A2 $info |grep '.meta$' |tail -n1 |cut -d. -f1)
33
34 if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
35 (head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
36   if (egrep -xq 'headline=.+' <<<"${line}"); then
37     headline="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
38     headline="$(echo -e "${headline}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
39   elif (egrep -xq 'status=.+' <<<"${line}"); then
40     taskstatus="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
41     taskstatus="$(echo -e "${taskstatus}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
42   elif (egrep -xq 'section=.+' <<<"${line}"); then
43     section="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
44     section="$(echo -e "${section}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
45   elif (egrep -xq 'description=.+' <<<"${line}"); then
46     description="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
47     description="$(echo -e "${description}" |sed 's/\r//g;s/\\/\\\\/g')"
48   elif (egrep -xq 'comm=.+' <<<"${line}"); then
49     comment="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
50     comment="$(echo -e "${comment}" |sed 's/\r//g;s/\\/\\\\/g')"
51   elif (egrep -xq 'cancel=.+' <<<"${line}"); then
52     cancel="true"
53   elif (egrep -xq 'submit=Robots click here' <<<"${line}"); then
54     cancel="true"
55   fi
56 done
57 fi
58
59 if [ -z "$cancel" -a -n "$comment" ]; then
60   touch "../Tasks/$info"
61   echo -e "author=${REMOTE_USER}" > "$commfile"
62   echo -e "${comment}" >> "$commfile"
63   echo -n "Location: ${proto}://${HTTP_HOST}/?p=Tasks&i=$info\n\n"
64 elif [ -z "$cancel" -a -n "$description" ]; then
65   touch "../Tasks/$info"
66   echo -e "headline=${headline}" > "$descfile"
67   echo -e "status=${taskstatus}" >> "$descfile"
68   echo -e "section=${section}" >> "$descfile"
69   echo -e "${description}" >> "../Tasks/$info"
70   echo -n "Location: ${proto}://${HTTP_HOST}/?p=Tasks#$anchor\n\n"
71 elif [ -n "$cancel" ]; then
72   echo -n "Location: ${proto}://${HTTP_HOST}/?p=Tasks#$anchor\n\n"
73 fi