-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.sh
executable file
·98 lines (94 loc) · 2.98 KB
/
build.sh
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
#!/bin/bash
set -euo pipefail
# config
# default cgi path
cgi_path="/usr/lib/cgi-bin/"
bos() {
tee "$2" >>/dev/null <<EOF
#!/bin/bash
echo "X-Bash-On-Steroids: Because there's nothing you can't fix with a #!Bash Script."
echo Content-type: text/html
echo ""
## make POST and GET stings
## as bash variables available
if [ ! -z \$CONTENT_LENGTH ] && [ "\$CONTENT_LENGTH" -gt 0 ] && [ \$CONTENT_TYPE != "multipart/form-data" ]; then
read -n \$CONTENT_LENGTH POST_STRING <&0
eval \$(echo "\${POST_STRING//;}"|grep '='|tr '&' ';')
fi
eval \$(echo "\${QUERY_STRING//;}"|grep '='|tr '&' ';')
## decode URL-encoding
urldecode() { : "\${*//+/ }"; echo -e "\${_//%/\\x}"; }
EOF
IFS=''
flag=0
lc=0
export txt=''
while read -r line;do
lc=$(( lc+1 ))
# Start and end tags in same line
if echo "$line"| grep -qe "<?.*?>" -qe "<?bash.*?>";then
if [[ $flag -eq 0 ]];then
line=${line//<?bash/<?}
pre=$(echo -e "$line" | sed -e 's/<?.*//')
comm=$(echo -e "$line" | sed -e 's/^.*<? //' | sed -e 's/?>.*//')
post=$(echo -e "$line" | sed -e 's/^.*?>//')
if [[ -n "$pre" ]];then
pre=${pre//\\/\\\\}
mod_pre=$(echo -e "$pre" |sed 's/"/\\\"/g')
mod_pre=${mod_pre//\$/\\$}
echo -e "echo \"$mod_pre\"" >>"$2"
fi
echo -e "$comm" >> "$2"
if [[ -n "$post" ]];then
post=${post//\\/\\\\}
mod_post=$(echo -e "$post" | sed 's/"/\\\"/g')
mod_post=${mod_post//\$/\\$}
echo -e "echo \"$mod_post\"" >>"$2"
fi
continue
else
echo "ERROR : Non-terminated <?bash or <? in file $1 (Line $lc) "
exit 1
fi
fi
# Start tag
if echo "$line" | sed 's/^ *//' | grep -q "^<?bash\\|^<?";then
if [[ $flag -eq 0 ]];then
flag=1
line=${line/<?bash}
echo -e "${line/<?}" >> "$2"
else
echo "ERROR : Non-terminated <?bash or <? in file $1 (Line $lc) "
exit 1
fi
continue;
fi
# End tag
if echo "$line" | grep -q "?>$";then
if [[ $flag -eq 1 ]];then
flag=0
echo "${line/?>}" >> "$2"
else
echo "ERROR : Unmatched ?> in file $1 (Line $lc)"
exit 1
fi
continue;
fi
# Take action on current line based on flag
if [[ $flag -eq 0 ]];then
line=${line//\\/\\\\}
modline=$(echo -e "$line" | sed -e 's/"/\\\"/g')
modline=${modline//\$/\\$}
echo -e "echo \"$modline\"" >>"$2"
else
echo -e "${line}" >> "$2"
fi
done < "$1"
}
for file in *.htsh; do
if [[ "$file" -nt ${cgi_path}"${file//htsh/cgi}" ]];then
echo -e "\\033[0;32m$file \\033[0;31m--->>\\033[0;32m ${cgi_path}${file//htsh/cgi}\\033[0m"
bos "$file" ${cgi_path}"${file//htsh/cgi}"
chmod +x ${cgi_path}"${file//htsh/cgi}"
fi
done