-
Notifications
You must be signed in to change notification settings - Fork 245
/
Copy pathvless_ws_tls.sh
368 lines (352 loc) · 11 KB
/
vless_ws_tls.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/bash
blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
source /etc/os-release
RELEASE=$ID
VERSION=$VERSION_ID
check_release(){
if [ "$RELEASE" == "centos" ]; then
yum install -y wget
systemPackage="yum"
if [ -n "$(grep ' 6\.' /etc/redhat-release)" ] ;then
red "CentOS 6 is not supported."
exit
fi
if [ -n "$(grep ' 5\.' /etc/redhat-release)" ] ;then
red "CentOS 5 is not supported."
exit
fi
if [ -f "/etc/selinux/config" ]; then
CHECK=$(grep SELINUX= /etc/selinux/config | grep -v "#")
if [ "$CHECK" == "SELINUX=enforcing" ]; then
green "$(date +"%Y-%m-%d %H:%M:%S") - SELinux状态非disabled,关闭SELinux."
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#loggreen "SELinux is not disabled, add port 80/443 to SELinux rules."
#loggreen "==== Install semanage"
#logcmd "yum install -y policycoreutils-python"
#semanage port -a -t http_port_t -p tcp 80
#semanage port -a -t http_port_t -p tcp 443
#semanage port -a -t http_port_t -p tcp 37212
#semanage port -a -t http_port_t -p tcp 37213
elif [ "$CHECK" == "SELINUX=permissive" ]; then
green "$(date +"%Y-%m-%d %H:%M:%S") - SELinux状态非disabled,关闭SELinux."
setenforce 0
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
fi
fi
firewall_status=`firewall-cmd --state`
if [ "$firewall_status" == "running" ]; then
green "FireWalld is not disabled, add port 80/443 to FireWalld rules."
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
fi
while [ ! -f "nginx-release-centos-7-0.el7.ngx.noarch.rpm" ]
do
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
if [ ! -f "nginx-release-centos-7-0.el7.ngx.noarch.rpm" ]; then
red "$(date +"%Y-%m-%d %H:%M:%S") - 下载nginx rpm包失败,继续重试..."
fi
done
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm --force --nodeps
#green "Prepare to install nginx."
#yum install -y libtool perl-core zlib-devel gcc pcre* >/dev/null 2>&1
yum install -y epel-release
elif [ "$RELEASE" == "ubuntu" ]; then
systemPackage="apt-get"
if [ -n "$(grep ' 14\.' /etc/os-release)" ] ;then
red "Ubuntu 14 is not supported."
exit
fi
if [ -n "$(grep ' 12\.' /etc/os-release)" ] ;then
red "Ubuntu 12 is not supported."
exit
fi
ufw_status=`systemctl status ufw | grep "Active: active"`
if [ -n "$ufw_status" ]; then
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
fi
apt-get update >/dev/null 2>&1
elif [ "$RELEASE" == "debian" ]; then
systemPackage="apt-get"
ufw_status=`systemctl status ufw | grep "Active: active"`
if [ -n "$ufw_status" ]; then
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
fi
apt-get update >/dev/null 2>&1
fi
}
check_port(){
$systemPackage install -y unzip >/dev/null 2>&1
green "Check ports..."
sleep 1s
$systemPackage -y install net-tools >/dev/null 2>&1
Port80=`netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 80`
Port443=`netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 443`
if [ -n "$Port80" ]; then
process80=`netstat -tlpn | awk -F '[: ]+' '$5=="80"{print $9}'`
red "Port 80 is occupied, Process name : ${process80}, exit."
exit 1
fi
if [ -n "$Port443" ]; then
process443=`netstat -tlpn | awk -F '[: ]+' '$5=="443"{print $9}'`
red "Port 443 is occupied, Process name : ${process443}, exit."
exit 1
fi
}
install_nginx(){
green "Install nginx..."
sleep 1s
$systemPackage install -y nginx >/dev/null 2>&1
if [ -f "/etc/nginx" ]; then
red "It seems that nginx installation is not successful. Please use the uninstall function in the script first."
exit 1
fi
mkdir /etc/nginx/ssl
newpath=$(cat /dev/urandom | head -1 | md5sum | head -c 4)
cat > /etc/nginx/nginx.conf <<-EOF
user root;
worker_processes 1;
#error_log /etc/nginx/error.log warn;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
#access_log /etc/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
client_max_body_size 20m;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
EOF
cat > /etc/nginx/conf.d/default.conf<<-EOF
server {
listen 80;
server_name $your_domain;
root /usr/share/nginx/html;
index index.php index.html;
#rewrite ^(.*)$ https://\$host\$1 permanent;
}
EOF
systemctl enable nginx.service
systemctl restart nginx.service
green "Use acme.sh apply https certificate."
curl https://get.acme.sh | sh
~/.acme.sh/acme.sh --issue -d $your_domain --webroot /usr/share/nginx/html/
if test -s /root/.acme.sh/$your_domain/fullchain.cer; then
green "Apply https certificate successful."
else
cert_failed="1"
red "Apply https certificate failed, please apply for certificate manually."
fi
cat > /etc/nginx/conf.d/default.conf<<-EOF
server {
listen 80;
server_name $your_domain;
root /usr/share/nginx/html;
index index.php index.html;
#rewrite ^(.*)$ https://\$host\$1 permanent;
}
server {
listen 443 ssl http2;
server_name $your_domain;
root /usr/share/nginx/html;
index index.php index.html;
ssl_certificate /etc/nginx/ssl/fullchain.cer;
ssl_certificate_key /etc/nginx/ssl/private.key;
location /$newpath {
proxy_redirect off;
proxy_pass http://127.0.0.1:11234;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
}
}
EOF
~/.acme.sh/acme.sh --installcert -d $your_domain \
--key-file /etc/nginx/ssl/private.key \
--fullchain-file /etc/nginx/ssl/fullchain.cer \
--reloadcmd "systemctl restart nginx.service"
install_v2ray
}
install_v2ray(){
mkdir /usr/local/etc/v2ray/
bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
cd /usr/local/etc/v2ray/
rm -f config.json
v2uuid=$(cat /proc/sys/kernel/random/uuid)
cat > /usr/local/etc/v2ray/config.json<<-EOF
{
"log" : {
"loglevel": "warning"
},
"inbound": {
"port": 11234,
"listen":"127.0.0.1",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$v2uuid",
"level": 0,
"email": "a@b.com"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/$newpath"
}
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
}
}
EOF
if [ -d "/usr/share/nginx/html/" ]; then
cd /usr/share/nginx/html/
rm -f ./*
#wget https://github.com/atrandys/v2ray-ws-tls/raw/master/web.zip >/dev/null 2>&1
wget https://github.com/atrandys/trojan/raw/master/fakesite.zip >/dev/null 2>&1
unzip fakesite.zip >/dev/null 2>&1
#unzip web.zip >/dev/null 2>&1
fi
systemctl enable v2ray.service
systemctl restart v2ray.service
cat > /usr/local/etc/v2ray/myconfig.json<<-EOF
{
===========配置参数=============
地址:${your_domain}
端口:443
uuid:${v2uuid}
额外id:64
加密方式:aes-128-gcm
传输协议:ws
别名:myws
路径:${newpath}
底层传输:tls
}
EOF
green "Installation is complete."
if [ "$cert_failed" == "1" ]; then
green "======nginx info======"
red "Apply https certificate failed, please apply for certificate manually."
fi
green "======v2ray config======"
green "Address :${your_domain}"
green "Port :443"
green "UUID :${v2uuid}"
green "Protocol :ws"
green "Path :${newpath}"
green "TLSSetting :tls"
green "AllowInsecure:False"
green
}
check_domain(){
blue "Eenter your domain:"
read your_domain
real_addr=`ping ${your_domain} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'`
local_addr=`curl ipv4.icanhazip.com`
if [ $real_addr == $local_addr ] ; then
green "DNS records are correct."
install_nginx
else
red "DNS records are not correct."
read -p "Still process ? Please enter [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
sleep 1s
install_nginx
else
exit 1
fi
fi
}
remove_v2ray(){
systemctl stop v2ray.service
systemctl disable v2ray.service
systemctl stop nginx
systemctl disable nginx
if [ "$RELEASE" == "centos" ]; then
yum remove -y nginx
else
apt-get -y autoremove nginx
apt-get -y --purge remove nginx
apt-get -y autoremove && apt-get -y autoclean
find / | grep nginx | sudo xargs rm -rf
fi
rm -rf /usr/local/share/v2ray/ /usr/local/etc/v2ray/
rm -rf /etc/systemd/system/v2ray*
rm -f /usr/local/bin/v2ray /usr/local/bin/v2ctl
rm -rf /etc/nginx
rm -rf /usr/share/nginx/html/*
rm -rf /root/.acme.sh/
green "nginx & v2ray has been deleted."
}
function start_menu(){
clear
green " ====================================================="
green " Onekey script install v2ray(vless) + ws + tls"
green " centos7/debian9+/ubuntu16.04+ supported "
green " by atrandys"
green " ====================================================="
echo
green " 1. Install vless + ws + tls"
green " 2. Update v2ray"
red " 3. Remove v2ray"
yellow " 0. Exit"
echo
read -p "Enter a number:" num
case "$num" in
1)
check_release
check_port
check_domain
;;
2)
bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
systemctl restart v2ray
;;
3)
remove_v2ray
;;
0)
exit 1
;;
*)
clear
red "Enter a correct number"
sleep 2s
start_menu
;;
esac
}
start_menu