]> git.plutz.net Git - confetti/blob - cgi.sh
stylebug, make "+"-field appear next to newfield button in edit attendee
[confetti] / cgi.sh
1 #!/bin/zsh
2
3 # Copyright 2014 Paul Hänsch
4 #
5 # This file is part of Confetti.
6
7 # Confetti 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 # Confetti 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 Confetti.  If not, see <http://www.gnu.org/licenses/>. 
19
20 declare -A _GET
21 declare -A _POST
22 declare -A _REF
23
24 cgi_get() {  # parse HTTP GET string
25   echo "$QUERY_STRING" |tr '&' '\n' |while read query; do
26     key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
27     val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
28     _GET["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")"
29   done
30 }
31
32 cgi_post() {  # parse HTTP POST string
33   sed -u 1q |tr '&' '\n' |while read query; do
34     key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
35     val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
36     value="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")"
37     if [ -n "$_POST[\"$key\"]" ]; then
38       n=0
39       while [ -n "$_POST[\"$key$n\"]" ]; do n=$(($n + 1)); done
40       _POST["$key$n"]="$value"
41     else
42       _POST["$key"]="$value"
43     fi
44     #debug "_POST[$key] => $value"
45   done
46 }
47
48 cgi_refdata() { # Parse GET data from referer
49   echo "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do
50     key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
51     val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
52     _REF["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")"
53   done
54 }