-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvddos-add.sh
260 lines (200 loc) · 9.84 KB
/
vddos-add.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
# Command:
# chmod 700 /vddos/auto-add/vddos-add.sh
# ln -s /vddos/auto-add/vddos-add.sh /usr/bin/vddos-add
# vddos-add your-domain.com
# OR
# vddos-add Website="your-domain.com" Cache="no" Security="no" HTTP_Listen="http://0.0.0.0:80" HTTPS_Listen="https://0.0.0.0:443" HTTP_Backend="http://127.0.0.1:8080" HTTPS_Backend="https://127.0.0.1:8443"
if [ ! -f /usr/bin/vddos-autoadd ] || [ ! -f /usr/bin/vddos-add ]; then
chmod 700 /vddos/auto-add/*.sh >/dev/null 2>&1
ln -s /vddos/auto-add/vddos-autoadd.sh /usr/bin/vddos-autoadd >/dev/null 2>&1
ln -s /vddos/auto-add/vddos-add.sh /usr/bin/vddos-add >/dev/null 2>&1
fi
if [ ! -f /vddos/conf.d/website.conf ]; then
echo 'ERROR!
/vddos/conf.d/website.conf not found!
Please Install UpShield Firewall!'|tee -a /vddos/auto-add/log.txt
exit 0
fi
if [ ! -d /letsencrypt ] || [ ! -d /vddos/ssl ]; then
mkdir -p /letsencrypt; chmod 700 -R /letsencrypt
mkdir -p /vddos/ssl; chmod 700 -R /vddos/ssl
fi
Issetting="$2" ;
if [ "$Issetting" != "" ] && [ "$1" != "" ] && [ "$2" != "" ] && [ "$3" != "" ] && [ "$4" != "" ] && [ "$5" != "" ] && [ "$6" != "" ] && [ "$7" != "" ]; then
eval $1
eval $2
eval $3
eval $4
eval $5
eval $6
eval $7
fi
if [ "$Issetting" = "" ]; then
Website="$1" ;
Cache=`awk -F: '/^Cache/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
Security=`awk -F: '/^Security/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
HTTP_Listen=`awk -F: '/^HTTP_Listen/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
HTTPS_Listen=`awk -F: '/^HTTPS_Listen/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
HTTP_Backend=`awk -F: '/^HTTP_Backend/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
HTTPS_Backend=`awk -F: '/^HTTPS_Backend/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
fi
SSLmode=`awk -F: '/^SSL/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
DNS_sleep=`awk -F: '/^DNS_sleep/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
DNS_alias_mode=`awk -F: '/^DNS_alias_mode/' /vddos/auto-add/setting.conf | awk 'NR==1 {print $2}'` ;
function showerror()
{
echo 'ERROR!
Website is ['$Website'] ...
Cache is ['$Cache'] ...
Security is ['$Security'] ...
HTTP_Listen is ['$HTTP_Listen'] ...
HTTPS_Listen is ['$HTTPS_Listen'] ...
HTTP_Backend is ['$HTTP_Backend'] ...
HTTPS_Backend is ['$HTTPS_Backend'] ...
# Please put a value in the file /vddos/auto-add/setting.conf
# Example:
SSL auto
Cache no
Security no
HTTP_Listen http://0.0.0.0:80
HTTPS_Listen https://0.0.0.0:443
HTTP_Backend http://127.0.0.1:8080
HTTPS_Backend https://127.0.0.1:8443
# Example Command:
vddos-add your-domain.com
# OR:
vddos-add Website="your-domain.com" Cache="no" Security="no" HTTP_Listen="http://0.0.0.0:80" HTTPS_Listen="https://0.0.0.0:443" HTTP_Backend="http://127.0.0.1:8080" HTTPS_Backend="https://127.0.0.1:8443"
'|tee -a /vddos/auto-add/log.txt
return 0
}
if [ "$Website" = "" ] || [ "$HTTPS_Backend" = "" ] || [ "$HTTP_Backend" = "" ] || [ "$HTTPS_Listen" = "" ] || [ "$HTTP_Listen" = "" ] || [ "$Security" = "" ] || [ "$Cache" = "" ]; then
showerror
exit 0
fi
Websitestringcheck=`echo $Website | grep -P '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)'`
if [ "$Website" != "$Websitestringcheck" ]; then
echo '- Re-check: '$Website' the domain is not properly formatted ===> Skip!'|tee -a /vddos/auto-add/log.txt
exit 0
fi
echo "
[[[[[[[ `date` ]]]]]]]
" >> /vddos/auto-add/log.txt
if [ "$SSLmode" = "Auto" ]; then
SSLmode=auto
fi
if [ "$SSLmode" = "auto" ]; then
# Request FOR non-www
Available=`awk -F: "/^$Website/" /vddos/conf.d/website.conf`
if [ "$Available" != "" ]; then
echo '- Re-check: '$Website' is already in /vddos/conf.d/website.conf ===> Skip!'|tee -a /vddos/auto-add/log.txt
exit 0
fi
if [ "$Available" = "" ]; then
random=`cat /dev/urandom | tr -cd 'A-Z0-9' | head -c 5`
echo $random > /vddos/letsencrypt/.well-known/acme-challenge/$Website.txt
randomchecknonwww=`curl -s -L http://$Website/.well-known/acme-challenge/$Website.txt`
randomcheckwww=`curl -s -L http://www.$Website/.well-known/acme-challenge/$Website.txt`
rm -f /vddos/letsencrypt/.well-known/acme-challenge/$Website.txt
if [ "$randomchecknonwww" = "$random" ]; then
#mkdir -p /letsencrypt/
/root/.acme.sh/acme.sh --debug --issue -d $Website -w /vddos/letsencrypt --keylength ec-256 --key-file /letsencrypt/$Website.pri --fullchain-file /letsencrypt/$Website.crt >>/vddos/auto-add/log.txt 2>&1
if [ -f /letsencrypt/"$Website".crt ]; then
ln -s /letsencrypt/$Website.crt /vddos/ssl/$Website.crt
ln -s /letsencrypt/$Website.pri /vddos/ssl/$Website.pri
fi
if [ ! -f /vddos/ssl/$Website.crt ] && [ -f /root/.acme.sh/"$Website"_ecc/fullchain.cer ]; then
ln -s /root/.acme.sh/"$Website"_ecc/fullchain.cer /vddos/ssl/$Website.crt
ln -s /root/.acme.sh/"$Website"_ecc/"$Website".key /vddos/ssl/$Website.pri
fi
fi
if [ "$randomchecknonwww" != "$random" ] || [ ! -f /vddos/ssl/"$Website".crt ]; then
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /vddos/ssl/$Website.pri -out /vddos/ssl/$Website.crt -subj "/C=US/ST=$Website/L=$Website/O=$Website/OU=vddos/CN=$Website" >>/vddos/auto-add/log.txt 2>&1
chmod -R 750 /vddos/ssl/$Website.*
fi
echo "
$Website $HTTP_Listen $HTTP_Backend $Cache $Security no no
$Website $HTTPS_Listen $HTTPS_Backend $Cache $Security /vddos/ssl/$Website.pri /vddos/ssl/$Website.crt
" >> /vddos/conf.d/website.conf
echo '+ New-Success: '$Website' auto add to /vddos/conf.d/website.conf ===> Done!'|tee -a /vddos/auto-add/log.txt
sleep 1
fi
# Request FOR www
is2www=`echo "www.$Website"| awk '{print substr($0,1,8)}'`
if [ "$is2www" = "www.www." ]; then
exit 0
fi
Available=`awk -F: "/^www.$Website/" /vddos/conf.d/website.conf`
if [ "$Available" != "" ]; then
echo '- Re-check: 'www.$Website' is already in /vddos/conf.d/website.conf ===> Skip!' |tee -a /vddos/auto-add/log.txt
exit 0
fi
if [ "$Available" = "" ]; then
if [ "$randomcheckwww" = "$random" ]; then
/root/.acme.sh/acme.sh --debug --issue -d www.$Website -w /vddos/letsencrypt --keylength ec-256 --key-file /letsencrypt/www.$Website.pri --fullchain-file /letsencrypt/www.$Website.crt >>/vddos/auto-add/log.txt 2>&1
if [ -f /letsencrypt/www."$Website".crt ]; then
ln -s /letsencrypt/www.$Website.crt /vddos/ssl/www.$Website.crt
ln -s /letsencrypt/www.$Website.pri /vddos/ssl/www.$Website.pri
fi
if [ ! -f /vddos/ssl/www."$Website".crt ] && [ -f /root/.acme.sh/www."$Website"_ecc/fullchain.cer ]; then
ln -s /root/.acme.sh/www."$Website"_ecc/fullchain.cer /vddos/ssl/www.$Website.crt
ln -s /root/.acme.sh/www."$Website"_ecc/"$Website".key /vddos/ssl/www.$Website.pri
fi
if [ ! -f /vddos/ssl/www."$Website".crt ]; then
ln -s /vddos/ssl/$Website.crt /vddos/ssl/www.$Website.crt
ln -s /vddos/ssl/$Website.pri /vddos/ssl/www.$Website.pri
fi
echo "
www.$Website $HTTP_Listen $HTTP_Backend $Cache $Security no no
www.$Website $HTTPS_Listen $HTTPS_Backend $Cache $Security /vddos/ssl/www.$Website.pri /vddos/ssl/www.$Website.crt
" >> /vddos/conf.d/website.conf
echo '+ New-Success: 'www.$Website' auto add to /vddos/conf.d/website.conf ===> Done!'|tee -a /vddos/auto-add/log.txt
sleep 1
exit 0
fi
fi
fi
######## SSL DNS API MODE
if [ "$SSLmode" != "auto" ] && [ "$DNS_alias_mode" = "no" ]; then
/root/.acme.sh/acme.sh --debug --dnssleep $DNS_sleep --issue --dns $SSLmode -d $Website -d *.$Website --keylength ec-256 --key-file /letsencrypt/$Website.pri --fullchain-file /letsencrypt/$Website.crt >>/vddos/auto-add/log.txt 2>&1
if [ -f /letsencrypt/"$Website".crt ]; then
ln -s /letsencrypt/$Website.crt /vddos/ssl/$Website.crt
ln -s /letsencrypt/$Website.pri /vddos/ssl/$Website.pri
fi
if [ ! -f /vddos/ssl/$Website.crt ] && [ -f /root/.acme.sh/"$Website"_ecc/fullchain.cer ]; then
ln -s /root/.acme.sh/"$Website"_ecc/fullchain.cer /vddos/ssl/$Website.crt
ln -s /root/.acme.sh/"$Website"_ecc/"$Website".key /vddos/ssl/$Website.pri
fi
if [ ! -f /vddos/ssl/"$Website".crt ]; then
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /vddos/ssl/$Website.pri -out /vddos/ssl/$Website.crt -subj "/C=US/ST=$Website/L=$Website/O=$Website/OU=vddos/CN=$Website" >>/vddos/auto-add/log.txt 2>&1
chmod -R 750 /vddos/ssl/$Website.*
fi
echo "
$Website $HTTP_Listen $HTTP_Backend $Cache $Security no no
$Website $HTTPS_Listen $HTTPS_Backend $Cache $Security /vddos/ssl/$Website.pri /vddos/ssl/$Website.crt
" >> /vddos/conf.d/website.conf
echo '+ New-Success: '$Website' auto add to /vddos/conf.d/website.conf ===> Done!'|tee -a /vddos/auto-add/log.txt
sleep 1
fi
######## SSL DNS API ALIAS MODE
if [ "$SSLmode" != "auto" ] && [ "$DNS_alias_mode" != "no" ]; then
/root/.acme.sh/acme.sh --debug --dnssleep $DNS_sleep --issue --dns $SSLmode --challenge-alias $DNS_alias_mode -d $Website -d *.$Website --keylength ec-256 --key-file /letsencrypt/$Website.pri --fullchain-file /letsencrypt/$Website.crt >>/vddos/auto-add/log.txt 2>&1
if [ -f /letsencrypt/"$Website".crt ]; then
ln -s /letsencrypt/$Website.crt /vddos/ssl/$Website.crt
ln -s /letsencrypt/$Website.pri /vddos/ssl/$Website.pri
fi
if [ ! -f /vddos/ssl/$Website.crt ] && [ -f /root/.acme.sh/"$Website"_ecc/fullchain.cer ]; then
ln -s /root/.acme.sh/"$Website"_ecc/fullchain.cer /vddos/ssl/$Website.crt
ln -s /root/.acme.sh/"$Website"_ecc/"$Website".key /vddos/ssl/$Website.pri
fi
if [ ! -f /vddos/ssl/"$Website".crt ]; then
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /vddos/ssl/$Website.pri -out /vddos/ssl/$Website.crt -subj "/C=US/ST=$Website/L=$Website/O=$Website/OU=vddos/CN=$Website" >>/vddos/auto-add/log.txt 2>&1
chmod -R 750 /vddos/ssl/$Website.*
fi
echo "
$Website $HTTP_Listen $HTTP_Backend $Cache $Security no no
$Website $HTTPS_Listen $HTTPS_Backend $Cache $Security /vddos/ssl/$Website.pri /vddos/ssl/$Website.crt
" >> /vddos/conf.d/website.conf
echo '+ New-Success: '$Website' auto add to /vddos/conf.d/website.conf ===> Done!'|tee -a /vddos/auto-add/log.txt
sleep 1
fi