Skip to content
This repository was archived by the owner on Aug 22, 2021. It is now read-only.

Commit 2076e67

Browse files
committed
ready to merge
2 parents c08bf87 + 41ea7f5 commit 2076e67

File tree

8 files changed

+215
-52
lines changed

8 files changed

+215
-52
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# v2ray tcp+tls+web
2-
automated script for v2Ray (TCP+TLS+Web) [中文](https://github.com/phlinhng/v2ray-tcp-tls-web/wiki)
1+
# v2ray tcp+tls+web (beta)
2+
automated script for v2Ray (TCP+TLS+Web)
33

44
## Usage
55
```
6-
bash <(curl -sL https://raw.githubusercontent.com/phlinhng/v2ray-tcp-tls-web/master/install.sh) && v2script
6+
bash <(curl -sL https://raw.githubusercontent.com/phlinhng/v2ray-tcp-tls-web/beta/install.sh) && v2script
77
```
88
The above command will download the script, save it to `/usr/local/bin/v2script`, make it excutable and start it. To run the script again once installed, just use the following command:
99
```
@@ -32,4 +32,4 @@ v2script
3232
+ [@ylx2016/Linux-NetSpeed](https://github.com/ylx2016/Linux-NetSpeed)
3333
+ [@LemonBench/LemonBench](https://github.com/LemonBench/LemonBench)
3434
+ [@tindy2013/subconverter](https://github.com/tindy2013/subconverter)
35-
+ [@9seconds/mtg](https://github.com/9seconds/mtg)
35+
+ [@9seconds/mtg](https://github.com/9seconds/mtg)

config/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ vhosts:
77
##V2RAY@alpn: h2,http/1.1
88
##V2RAY@protocols: tls12,tls13
99
##V2RAY@http:
10+
##CDN@paths:
11+
##CDN@- path: /FAKECDNPATH
12+
##CDN@ handler: proxyPass
13+
##CDN@ args: 127.0.0.1:3566
1014
##V2RAY@handler: fileServer
1115
##V2RAY@args: /var/www/html
1216
##V2RAY@default:

config/v2ray.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"protocol": "vmess",
55
"listen": "127.0.0.1",
6-
"port": "FAKEPORT",
6+
"port": FAKEPORT,
77
"settings": {
88
"clients": [
99
{

config/v2script.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
22
"v2ray": {
33
"installed": false,
4-
"tlsHeader": ""
4+
"tlsHeader": "",
5+
"cloudflare": false
56
},
67
"sub": {
78
"enabled": false,
8-
"nodes": [],
9+
"nodesList": {
10+
"tcp": "",
11+
"wss": "",
12+
"trojan": ""
13+
},
914
"uri": "",
1015
"api": {
1116
"installed": false,

install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
4949
fi
5050

5151
# install requirements
52-
#${sudoCmd} ${systemPackage} update
53-
${sudoCmd} ${systemPackage} install curl wget jq lsof -y -qq
52+
${sudoCmd} ${systemPackage} update -q
53+
${sudoCmd} ${systemPackage} install curl wget jq lsof coreutils unzip -y -qq
5454

5555
${sudoCmd} mkdir -p /usr/local/etc/v2script
5656

src/v2script.sh

Lines changed: 142 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ write_json() {
7373
show_menu() {
7474
echo ""
7575
echo "1) 安装TCP+TLS+WEB"
76-
echo "2) 更新v2ray-core"
77-
echo "3) 更新tls-shunt-proxy"
78-
echo "4) 卸载TCP+TLS+WEB"
79-
echo "5) 显示vmess链接"
80-
echo "6) 管理订阅"
81-
echo "7) 设置电报代理"
82-
echo "8) VPS工具"
76+
echo "2) 显示vmess链接"
77+
echo "3) 管理订阅"
78+
echo "4) 设置CDN"
79+
echo "5) 设置电报代理"
80+
echo "6) VPS工具"
81+
echo "7) 更新v2ray-core"
82+
echo "8) 更新tls-shunt-proxy"
83+
echo "9) 卸载TCP+TLS+WEB"
8384
}
8485

8586
continue_prompt() {
@@ -91,12 +92,11 @@ continue_prompt() {
9192
}
9293

9394
display_vmess() {
94-
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.install') != "true" ]]; then
95-
local V2_DOMAIN="$(read_json /usr/local/etc/v2script/config.json '.v2ray.tlsHeader')"
96-
local uuid="$(read_json /etc/v2ray/config.json '.inbounds[0].settings.clients[0].id')"
97-
local json="{\"add\":\"${V2_DOMAIN}\",\"aid\":\"0\",\"host\":\"\",\"id\":\"${uuid}\",\"net\":\"\",\"path\":\"\",\"port\":\"443\",\"ps\":\"${V2_DOMAIN}:443\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}"
98-
local uri="$(printf "${json}" | base64)"
99-
echo "vmess://${uri}" | tr -d '\n' && printf "\n"
95+
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.installed') == "true" ]]; then
96+
echo "$(read_json /usr/local/etc/v2script/config.json '.sub.nodesList.tcp')" | tr -d '\n' && printf "\n"
97+
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.cloudflare') == "true" ]]; then
98+
echo "$(read_json /usr/local/etc/v2script/config.json '.sub.nodesList.wss')" | tr -d '\n' && printf "\n"
99+
fi
100100
else
101101
colorEcho ${RED} "配置文件不存在"
102102
return 1
@@ -115,13 +115,13 @@ display_vmess_full() {
115115
#${sudoCmd} ${systemPackage} install coreutils jq -y
116116
local V2_DOMAIN="$(read_json /usr/local/etc/v2script/config.json '.v2ray.tlsHeader')"
117117
local uuid="$(read_json /etc/v2ray/config.json '.inbounds[0].settings.clients[0].id')"
118-
local json="{\"add\":\"${V2_DOMAIN}\",\"aid\":\"0\",\"host\":\"\",\"id\":\"${uuid}\",\"net\":\"\",\"path\":\"\",\"port\":\"443\",\"ps\":\"${V2_DOMAIN}:443\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}"
119-
local uri="$(printf "${json}" | base64)"
120-
write_json /usr/local/etc/v2script/config.json '.sub.nodes[0]' "$(printf "\"vmess://${uri}\"" | tr -d '\n')"
118+
local json="{\"add\":\"${V2_DOMAIN}\",\"aid\":\"0\",\"host\":\"\",\"id\":\"${uuid}\",\"net\":\"\",\"path\":\"\",\"port\":\"443\",\"ps\":\"${V2_DOMAIN}\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}"
119+
local uri="$(printf %s "${json}" | base64 | tr -d '\n')"
120+
write_json /usr/local/etc/v2script/config.json '.sub.nodesList.tcp' "$(printf %s "\"vmess://${uri}\"" | tr -d '\n')"
121121

122122
echo "${V2_DOMAIN}:443"
123123
echo "${uuid} (aid: 0)" && echo ""
124-
echo "vmess://${uri}" | tr -d '\n' && printf "\n"
124+
display_vmess
125125
}
126126

127127
generate_link() {
@@ -148,17 +148,29 @@ generate_link() {
148148
read -p "输入节点名称[留空则使用默认值]: " remark
149149

150150
if [ -z "${remark}" ]; then
151-
remark="${V2_DOMAIN}:443"
151+
remark="${V2_DOMAIN}"
152152
fi
153153

154154
local json="{\"add\":\"${V2_DOMAIN}\",\"aid\":\"0\",\"host\":\"\",\"id\":\"${uuid}\",\"net\":\"\",\"path\":\"\",\"port\":\"443\",\"ps\":\"${remark}\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}"
155-
local uri="$(printf "${json}" | base64)"
156-
local sub="$(printf "vmess://${uri}" | tr -d '\n' | base64)"
155+
local uri="$(printf %s "${json}" | base64 | tr -d '\n')"
156+
local sub="$(printf %s "vmess://${uri}" | base64 | tr -d '\n')"
157157

158-
local randomName="$(cat '/proc/sys/kernel/random/uuid' | sed -e 's/-//g' | tr '[:upper:]' '[:lower:]' | head -c 16)" #random file name for subscription
158+
local randomName="$(uuidgen | sed -e 's/-//g' | tr '[:upper:]' '[:lower:]' | head -c 16)" #random file name for subscription
159159
write_json /usr/local/etc/v2script/config.json '.sub.uri' "\"${randomName}\""
160+
write_json /usr/local/etc/v2script/config.json '.sub.nodesList.tcp' "$(printf %s "\"vmess://${uri}\"" | tr -d '\n')"
161+
162+
printf %s "${sub}" | tr -d '\n' | ${sudoCmd} tee /var/www/html/$(read_json /usr/local/etc/v2script/config.json '.sub.uri') >/dev/null
163+
164+
if [[ "$(read_json /usr/local/etc/v2script/config.json '.v2ray.cloudflare')" == "true" ]]; then
165+
local cfUrl="amp.cloudflare.com"
166+
local currentRemark="$(read_json /usr/local/etc/v2script/config.json '.sub.nodesList.tcp' | sed 's/^vmess:\/\///g' | base64 -d | jq --raw-output '.ps' | tr -d '\n')"
167+
local json="{\"add\":\"${cfUrl}\",\"aid\":\"0\",\"host\":\"${sni}\",\"id\":\"${uuid}\",\"net\":\"ws\",\"path\":\"/${wssPath}\",\"port\":\"${port}\",\"ps\":\"${currentRemark} (CDN)\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}"
168+
local uri="$(printf %s "${json}" | base64 | tr -d '\n')"
169+
write_json /usr/local/etc/v2script/config.json '.sub.nodesList.wss' "$(printf %s "\"vmess://${uri}\"" | tr -d '\n')"
170+
local sub="$(printf "\nvmess://${uri}" | base64 | tr -d '\n')"
171+
printf %s "${sub}" | tr -d '\n' | ${sudoCmd} tee -a /var/www/html/$(read_json /usr/local/etc/v2script/config.json '.sub.uri') >/dev/null
172+
fi
160173

161-
printf "${sub}" | tr -d '\n' | ${sudoCmd} tee /var/www/html/${randomName} >/dev/null
162174
echo "https://${V2_DOMAIN}/${randomName}" | tr -d '\n' && printf "\n"
163175
}
164176

@@ -211,6 +223,11 @@ set_proxy() {
211223
sed -i "s/##V2RAY@//g" /tmp/config_new.yaml
212224
fi
213225

226+
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.cloudflare') == "true" ]]; then
227+
sed -i "s/FAKECDNPATH/$(read_json /etc/v2ray/config.json '.inbounds[1].streamSettings.wsSettings.path')/g" /tmp/config_new.yaml
228+
sed -i "s/##CDN@//g" /tmp/config_new.yaml
229+
fi
230+
214231
if [[ $(read_json /usr/local/etc/v2script/config.json '.sub.api.installed') == "true" ]]; then
215232
sed -i "s/FAKEAPIDOMAIN/$(read_json /usr/local/etc/v2script/config.json '.sub.api.tlsHeader')/g" /tmp/config_new.yaml
216233
sed -i "s/##SUBAPI@//g" /tmp/config_new.yaml
@@ -224,21 +241,79 @@ set_proxy() {
224241
${sudoCmd} /bin/cp -f /tmp/config_new.yaml /etc/tls-shunt-proxy/config.yaml
225242
}
226243

244+
set_v2ray_wss() {
245+
if [[ ! $(read_json /usr/local/etc/v2script/config.json '.v2ray.cloudflare') == "true" ]]; then
246+
local uuid="$(cat '/proc/sys/kernel/random/uuid')"
247+
local wssPath="$(cat '/proc/sys/kernel/random/uuid' | sed -e 's/-//g' | tr '[:upper:]' '[:lower:]' | head -c 12)"
248+
local sni="$(read_json /usr/local/etc/v2script/config.json '.v2ray.tlsHeader')"
249+
local wssInbound="{\"protocol\": \"vmess\",
250+
\"port\": 3566,
251+
\"settings\": {
252+
\"clients\": [{
253+
\"id\": \"${uuid}\",
254+
\"alterId\": 0
255+
}]
256+
},
257+
\"streamSettings\": {
258+
\"network\": \"ws\",
259+
\"wsSettings\": {
260+
\"path\": \"/${wssPath}\"
261+
}
262+
},
263+
\"sniffing\": {
264+
\"enabled\": true,
265+
\"destOverride\": [ \"http\", \"tls\" ]
266+
}
267+
}"
268+
269+
# setting v2ray
270+
${sudoCmd} /bin/cp /etc/v2ray/config.json /etc/v2ray/config.json.bak 2>/dev/null
271+
jq -r ".inbounds += [${wssInbound}]" /etc/v2ray/config.json > tmp.$$.json && ${sudoCmd} mv tmp.$$.json /etc/v2ray/config.json
272+
write_json /usr/local/etc/v2script/config.json '.v2ray.cloudflare' "true"
273+
274+
set_proxy
275+
276+
${sudoCmd} systemctl restart v2ray 2>/dev/null
277+
${sudoCmd} systemctl restart tls-shunt-proxy 2>/dev/null
278+
${sudoCmd} systemctl daemon-reload
279+
280+
colorEcho ${GREEN} "设置CDN成功!"
281+
282+
local cfUrl="amp.cloudflare.com"
283+
local currentRemark="$(read_json /usr/local/etc/v2script/config.json '.sub.nodesList.tcp' | sed 's/^vmess:\/\///g' | base64 -d | jq --raw-output '.ps' | tr -d '\n')"
284+
local json="{\"add\":\"${cfUrl}\",\"aid\":\"0\",\"host\":\"${sni}\",\"id\":\"${uuid}\",\"net\":\"ws\",\"path\":\"/${wssPath}\",\"port\":\"443\",\"ps\":\"${currentRemark} (CDN)\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}"
285+
local uri="$(printf %s "${json}" | base64 | tr -d '\n')"
286+
287+
# updating subscription
288+
if [[ $(read_json /usr/local/etc/v2script/config.json '.sub.enabled') == "true" ]]; then
289+
write_json /usr/local/etc/v2script/config.json '.sub.nodesList.wss' "$(printf %s "\"vmess://${uri}\"" | tr -d '\n')"
290+
local sub="$(printf "\nvmess://${uri}" | base64 | tr -d '\n')"
291+
printf %s "${sub}" | tr -d '\n' | ${sudoCmd} tee -a /var/www/html/$(read_json /usr/local/etc/v2script/config.json '.sub.uri') >/dev/null
292+
fi
293+
294+
echo "${cfUrl}:443"
295+
echo "${uuid} (aid: 0)"
296+
echo "Header: ${sni}, Path: /${wssPath}" && echo ""
297+
echo "vmess://${uri}" | tr -d '\n' && printf "\n"
298+
else
299+
display_vmess
300+
fi
301+
}
302+
227303
get_caddy() {
228304
if [ ! -f "/usr/local/bin/caddy" ]; then
229305
#${sudoCmd} ${systemPackage} install libcap2-bin -y -qq
230-
306+
231307
curl -sL https://getcaddy.com | ${sudoCmd} bash -s personal
232308
# Give the caddy binary the ability to bind to privileged ports (e.g. 80, 443) as a non-root user
233309
#${sudoCmd} setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
234310

235311
# create user for caddy
236312
${sudoCmd} useradd -d /usr/local/etc/caddy -M -s $(which nologin) -r -u 33 www-data
237-
238313
${sudoCmd} mkdir -p /usr/local/etc/caddy && ${sudoCmd} chown -R root:root /usr/local/etc/caddy
239314
${sudoCmd} mkdir -p /usr/local/etc/ssl/caddy && ${sudoCmd} chown -R root:www-data /usr/local/etc/ssl/caddy
240315
${sudoCmd} chmod 0770 /usr/local/etc/ssl/caddy
241-
316+
242317
wget -q https://raw.githubusercontent.com/phlinhng/v2ray-tcp-tls-web/${branch}/config/caddy.service -O /tmp/caddy.service
243318
${sudoCmd} mv /tmp/caddy.service /etc/systemd/system/caddy.service
244319
${sudoCmd} chown root:root /etc/systemd/system/caddy.service
@@ -333,6 +408,10 @@ EOF
333408
sed -i "s/FAKEPORT/$(read_json /etc/v2ray/config.json '.inbounds[0].port')/g" ./config/v2ray.json
334409
sed -i "s/FAKEUUID/$(read_json /etc/v2ray/config.json '.inbounds[0].settings.clients[0].id')/g" ./config/v2ray.json
335410
${sudoCmd} /bin/cp -f ./config/v2ray.json /etc/v2ray/config.json
411+
412+
# set crontab to auto update geoip.dat and geosite.dat
413+
(crontab -l 2>/dev/null; echo "0 7 * * * wget -q https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/geoip.dat -O /usr/bin/v2ray/geoip.dat >/dev/null >/dev/null") | ${sudoCmd} crontab -
414+
(crontab -l 2>/dev/null; echo "0 7 * * * wget -q https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/geosite.dat -O /usr/bin/v2ray/geosite.dat >/dev/null >/dev/null") | ${sudoCmd} crontab -
336415
fi
337416

338417
colorEcho ${BLUE} "Setting tls-shunt-proxy"
@@ -367,6 +446,12 @@ EOF
367446
colorEcho ${GREEN} "安装TCP+TLS+WEB成功!"
368447
display_vmess_full
369448

449+
read -p "设置CDN (yes/no)? " wssConfirm
450+
case "${wssConfirm}" in
451+
y|Y|[yY][eE][sS] ) set_v2ray_wss ;;
452+
* ) return 0 ;;
453+
esac
454+
370455
read -p "生成订阅链接 (yes/no)? " linkConfirm
371456
case "${linkConfirm}" in
372457
y|Y|[yY][eE][sS] ) generate_link ;;
@@ -404,8 +489,8 @@ install_mtproto() {
404489
write_json "/usr/local/etc/v2script/config.json" ".mtproto.installed" "true"
405490
write_json "/usr/local/etc/v2script/config.json" ".mtproto.fakeTlsHeader" "\"${FAKE_TLS_HEADER}\""
406491
write_json "/usr/local/etc/v2script/config.json" ".mtproto.secret" "\"${secret}\""
407-
set_proxy
408492

493+
set_proxy
409494
set_docker
410495

411496
# activate service
@@ -420,10 +505,32 @@ install_mtproto() {
420505
display_mtproto
421506
}
422507

508+
set_v2ray_wss_prompt() {
509+
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.installed') == "true" ]]; then
510+
echo "此选项会增加一个WS+TLS+CDN的连接入口做为备用连接方式"
511+
echo "备用连接方式的速度、延迟可能不如TCP+TLS"
512+
colorEcho ${YELLOW} "请确保域名己解析到 Cloudflare 并设置成 \"DNS Only\" (云朵为灰色)"
513+
colorEcho ${YELLOW} "请确保域名己解析到 Cloudflare 并设置成 \"DNS Only\" (云朵为灰色)"
514+
colorEcho ${YELLOW} "请确保域名己解析到 Cloudflare 并设置成 \"DNS Only\" (云朵为灰色)"
515+
read -p "确定设置CDN (yes/no)? " wssConfirm
516+
case "${wssConfirm}" in
517+
y|Y|[yY][eE][sS] ) set_v2ray_wss ;;
518+
* ) return 0 ;;
519+
esac
520+
else
521+
colorEcho ${YELLOW} "请先安装TCP+TLS+WEB!"
522+
return 1
523+
fi
524+
}
525+
423526
check_status() {
424527
printf "脚本状态: "
425528
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.installed') == "true" ]]; then
426-
colorEcho ${GREEN} "己安装"
529+
if [[ $(read_json /usr/local/etc/v2script/config.json '.v2ray.clouflare') == "true" ]]; then
530+
colorEcho ${GREEN} "TCP+TLS, WSS+CDN"
531+
else
532+
colorEcho ${GREEN} "TCP+TLS"
533+
fi
427534
else
428535
colorEcho ${YELLOW} "未安装"
429536
fi
@@ -456,7 +563,7 @@ check_status() {
456563

457564
vps_tools() {
458565
${sudoCmd} ${systemPackage} install wget -y -qq
459-
wget -q -N https://raw.githubusercontent.com/phlinhng/v2ray-tcp-tls-web/${branch}/tools/vps_tools.sh -O /tmp/vps_tools.sh && chmod +x /tmp/vps_tools.sh && ${sudoCmd} /tmp/vps_tools.sh
566+
wget -q https://raw.githubusercontent.com/phlinhng/v2ray-tcp-tls-web/${branch}/tools/vps_tools.sh -O /tmp/vps_tools.sh && chmod +x /tmp/vps_tools.sh && ${sudoCmd} /tmp/vps_tools.sh
460567
exit 0
461568
}
462569

@@ -469,22 +576,23 @@ menu() {
469576

470577
PS3="选择操作[输入任意值或按Ctrl+C退出]: "
471578
COLUMNS=woof
472-
options=("安装TCP+TLS+WEB" "更新v2ray-core" "更新tls-shunt-proxy" "卸载TCP+TLS+WEB" "显示vmess链接" "管理订阅" "设置电报代理" "VPS工具")
579+
options=("安装TCP+TLS+WEB" "显示vmess链接" "管理订阅" "设置CDN" "设置电报代理" "VPS工具" "更新v2ray-core" "更新tls-shunt-proxy" "卸载TCP+TLS+WEB")
473580
select opt in "${options[@]}"
474581
do
475582
case "${opt}" in
476583
"安装TCP+TLS+WEB") install_v2ray && continue_prompt ;;
477-
"更新v2ray-core") get_v2ray && continue_prompt ;;
478-
"更新tls-shunt-proxy") get_proxy && continue_prompt ;;
479-
"卸载TCP+TLS+WEB") rm_v2script ;;
480584
"显示vmess链接") display_vmess && continue_prompt ;;
481585
"管理订阅") v2sub && exit 0 ;;
482-
"设置电报代理") install_mtproto && continue_prompt;;
586+
"设置CDN") set_v2ray_wss_prompt && continue_prompt ;;
587+
"设置电报代理") install_mtproto && continue_prompt ;;
483588
"VPS工具") vps_tools ;;
589+
"更新v2ray-core") get_v2ray && continue_prompt ;;
590+
"更新tls-shunt-proxy") get_proxy && continue_prompt ;;
591+
"卸载TCP+TLS+WEB") rm_v2script ;;
484592
*) break ;;
485593
esac
486594
done
487595

488596
}
489597

490-
menu
598+
menu

0 commit comments

Comments
 (0)