-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGIBa.sh
More file actions
117 lines (96 loc) · 2.26 KB
/
CGIBa.sh
File metadata and controls
117 lines (96 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
### CHANGE THIS IF YOU WOULD LIKE TO LISTEN ON A DIFFERENT PORT
declare -i LISTEN_PORT=8080 DEBUG=1 VERBOSE=1
debug(){
[[ ! $VERBOSE -eq 1 ]] && return #{{{
# echo $@ >&2
( >&2 echo -e "\033[1;38;2;255;100;100m$@\033[00m" )
} #}}}
escapeweb(){
echo "$@"| sed 's/[^A-Za-z0-9_(): %\*\-]//g' #{{{
} #}}}
escapewebext(){
echo "$@"| sed 's/[^A-Za-z0-9_(): %\*\/\|\-]//g' #{{{
} #}}}
urldecode(){
local url_encoded="${1//+/ }" #{{{
printf '%b' "${url_encoded//%/\\x}"
} #}}}
error_msg(){
#{{{
echo "<h3 class=error>$@</h3>"
} #}}}
parsePOST(){
#{{{
local CNT=0 fieldn
[ -z "$POST_DATA" -o ! -e $UPLOADDIR/$POST_DATA ] && return
while read -r line; do
if [[ $line == *Content-Type:* ]];then
line="$(escapewebext $line)"
else
line="$(escapeweb $line)"
fi
[[ $((CNT++%2)) -eq 0 ]] && {
[[ $line == *filename=* ]] && {
OFS=IFS;IFS=';' FILENAMEAR=($line); IFS=$OFS
for fileline in ${FILENAMEAR[@]};do
if [[ $((FLCNT++%2)) -eq 0 ]];then
flfield=${fileline#*=}
else
_POST[${flfield}]=${fileline#*=}
continue
fi
# debug fileline=$fileline
done
} #filename
fieldn="$line"
# debug CNT=$((CNT%2)) fieldn: $fieldn
} || { # fieldn
if [[ $line == *Content-Type:* ]];then
fieldn=${line%:*}
_POST[$fieldn]=$line
# debug ContentType: ${_POST[$fieldn]}
else
_POST[$fieldn]="$line"
# debug CNT=$((CNT%2)) lern: ${#_POST[@]} fieldn: $fieldn value=${_POST[$fieldn]}
fi
} #fi
done<<<$(awk -v PROC="getformfields" -f multipart.awk $UPLOADDIR/$POST_DATA)
} #}}}parsePOST
urldecode()
{ #{{{
[ "${1%/}" = "" ] && echo "/"||echo -e "$(sed 's/%\([[:xdigit:]]\{2\}\)/\\\x\1/g' <<< "${1%/}")"
} #}}}
urlencode(){
local s="${@//'%'/%25}" #{{{
s="${s//' '/%20}"
s="${s//'"'/%22}"
s="${s//'#'/%23}"
s="${s//'$'/%24}"
s="${s//'&'/%26}"
s="${s//'+'/%2B}"
s="${s//','/%2C}"
s="${s//'/'/%2F}"
s="${s//':'/%3A}"
s="${s//';'/%3B}"
s="${s//'='/%3D}"
s="${s//'?'/%3F}"
s="${s//'@'/%40}"
s="${s//'['/%5B}"
s="${s//']'/%5D}"
printf '%s' "$s"
} #}}}
:<<'CMNT'
{{{
UPLOADDIR=/tmp
OIFS=$IFS
IFS='=&'
parm_get=($QUERY_STRING)
IFS=$'\r\n\r\n'
parm_post=($POST_STRING)
IFS=$OIFS
declare -A get post
for ((i=0; i<${#parm_get[@]}; i+=2)); do
get[${parm_get[i]}]=$(urldecode ${parm_get[i+1]})
done
}}}
CMNT