Skip to content

Commit ac82a14

Browse files
committed
add *TLS protocol change port
1 parent 1948bf0 commit ac82a14

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/caddy.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
caddy_config() {
22
is_caddy_site_file=$is_caddy_conf/${host}.conf
3+
[[ ! $tlsport ]] && tlsport=443
34
case $1 in
45
new)
56
mkdir -p $is_caddy_dir $is_caddy_dir/sites $is_caddy_conf
@@ -14,21 +15,21 @@ EOF
1415
;;
1516
*ws*)
1617
cat >${is_caddy_site_file} <<<"
17-
${host} {
18+
${host}:${tlsport} {
1819
reverse_proxy ${path} 127.0.0.1:${port}
1920
import ${is_caddy_site_file}.add
2021
}"
2122
;;
2223
*h2*)
2324
cat >${is_caddy_site_file} <<<"
24-
${host} {
25+
${host}:${tlsport} {
2526
reverse_proxy ${path} h2c://127.0.0.1:${port}
2627
import ${is_caddy_site_file}.add
2728
}"
2829
;;
2930
*grpc*)
3031
cat >${is_caddy_site_file} <<<"
31-
${host} {
32+
${host}:${tlsport} {
3233
reverse_proxy /${path}/* h2c://127.0.0.1:${port}
3334
import ${is_caddy_site_file}.add
3435
}"

src/core.sh

+29-12
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,23 @@ change() {
517517
1)
518518
# new port
519519
is_new_port=$3
520-
[[ $host ]] && err "($is_config_file) 不支持更改端口, 因为没啥意义."
520+
[[ $host && ! $is_caddy ]] && err "($is_config_file) 不支持更改端口, 因为没啥意义."
521+
if [[ $is_new_port && ! $is_auto ]]; then
522+
[[ ! $(is_test port $is_new_port) ]] && err "请输入正确的端口, 可选(1-65535)"
523+
[[ $is_new_port != 443 && $(is_test port_used $is_new_port) ]] && err "无法使用 ($is_new_port) 端口"
524+
fi
521525
[[ $is_auto ]] && get_port && is_new_port=$tmp_port
522526
[[ ! $is_new_port ]] && ask string is_new_port "请输入新端口:"
523-
add $net $is_new_port
527+
if [[ $is_caddy && $host ]]; then
528+
net=$is_old_net
529+
tlsport=$is_new_port
530+
load caddy.sh
531+
caddy_config $net
532+
manage restart caddy &
533+
info
534+
else
535+
add $net $is_new_port
536+
fi
524537
;;
525538
2)
526539
# new host
@@ -1192,7 +1205,11 @@ get() {
11921205
is_dynamic_port_range=$(jq -r '.inbounds[0].port' $is_dynamic_port_file)
11931206
[[ $? != 0 ]] && err "无法读取动态端口文件: $is_dynamic_port"
11941207
fi
1195-
[[ $is_client && $host ]] && port=443
1208+
if [[ $is_caddy && $host ]]; then
1209+
tlsport=$(egrep -o "$host:[1-9][0-9]?+" $is_caddy_conf/$host.conf | sed s/.*://)
1210+
fi
1211+
[[ ! $tlsport ]] && tlsport=443
1212+
[[ $is_client && $host ]] && port=$tlsport
11961213
get protocol $is_protocol-$net
11971214
fi
11981215
;;
@@ -1446,39 +1463,39 @@ info() {
14461463
ss)
14471464
is_can_change=(0 1 4 6)
14481465
is_info_show=(0 1 2 10 11)
1449-
is_url="ss://$(echo -n ${ss_method}:${ss_password} | base64 -w 0)@${is_addr}:${port}#233boy-ss-${is_addr}"
1466+
is_url="ss://$(echo -n ${ss_method}:${ss_password} | base64 -w 0)@${is_addr}:${port}#233boy-$net-${is_addr}"
14501467
is_info_str=($is_protocol $is_addr $port $ss_password $ss_method)
14511468
;;
14521469
ws | h2 | grpc)
14531470
is_color=45
1454-
is_can_change=(0 2 3 5)
1471+
is_can_change=(0 1 2 3 5)
14551472
is_info_show=(0 1 2 3 4 6 7 8)
14561473
is_url_path=path
14571474
[[ $net == 'grpc' ]] && {
14581475
path=$(sed 's#/##g' <<<$path)
14591476
is_url_path=serviceName
14601477
}
14611478
[[ $is_protocol == 'vmess' ]] && {
1462-
is_vmess_url=$(jq -c '{v:2,ps:'\"233boy-$host\"',add:'\"$is_addr\"',port:'\"443\"',id:'\"$uuid\"',aid:"0",net:'\"$net\"',host:'\"$host\"',path:'\"$path\"',tls:'\"tls\"'}' <<<{})
1479+
is_vmess_url=$(jq -c '{v:2,ps:'\"233boy-$net-$host\"',add:'\"$is_addr\"',port:'\"$tlsport\"',id:'\"$uuid\"',aid:"0",net:'\"$net\"',host:'\"$host\"',path:'\"$path\"',tls:'\"tls\"'}' <<<{})
14631480
is_url=vmess://$(echo -n $is_vmess_url | base64 -w 0)
14641481
} || {
14651482
[[ $is_trojan ]] && {
14661483
uuid=$trojan_password
1467-
is_info_str=($is_protocol $is_addr 443 $trojan_password $net $host $path 'tls')
1468-
is_can_change=(0 2 3 4)
1484+
is_info_str=($is_protocol $is_addr $tlsport $trojan_password $net $host $path 'tls')
1485+
is_can_change=(0 1 2 3 4)
14691486
is_info_show=(0 1 2 10 4 6 7 8)
14701487
}
1471-
is_url="$is_protocol://$uuid@$host:443?encryption=none&security=tls&type=$net&host=$host&${is_url_path}=$(sed 's#/#%2F#g' <<<$path)#233boy-$host"
1488+
is_url="$is_protocol://$uuid@$host:$tlsport?encryption=none&security=tls&type=$net&host=$host&${is_url_path}=$(sed 's#/#%2F#g' <<<$path)#233boy-$net-$host"
14721489
}
14731490
[[ $is_caddy ]] && is_can_change+=(13)
1474-
is_info_str=($is_protocol $is_addr 443 $uuid $net $host $path 'tls')
1491+
is_info_str=($is_protocol $is_addr $tlsport $uuid $net $host $path 'tls')
14751492
;;
14761493
reality)
14771494
is_color=41
14781495
is_can_change=(0 1 5 10 11)
14791496
is_info_show=(0 1 2 3 15 8 16 17 18)
14801497
is_info_str=($is_protocol $is_addr $port $uuid xtls-rprx-vision reality $is_servername "ios" $is_public_key)
1481-
is_url="$is_protocol://$uuid@$ip:$port?encryption=none&security=reality&flow=xtls-rprx-vision&type=tcp&sni=$is_servername&pbk=$is_public_key&fp=ios#233boy-$is_addr"
1498+
is_url="$is_protocol://$uuid@$ip:$port?encryption=none&security=reality&flow=xtls-rprx-vision&type=tcp&sni=$is_servername&pbk=$is_public_key&fp=ios#233boy-$net-$is_addr"
14821499
;;
14831500
door)
14841501
is_can_change=(0 1 8 9)
@@ -1489,7 +1506,7 @@ info() {
14891506
is_can_change=(0 1 15 4)
14901507
is_info_show=(0 1 2 19 10)
14911508
is_info_str=($is_protocol $is_addr $port $is_socks_user $is_socks_pass)
1492-
is_url="socks://$(echo -n ${is_socks_user}:${is_socks_pass} | base64 -w 0)@${is_addr}:${port}#233boy-socks-${is_addr}"
1509+
is_url="socks://$(echo -n ${is_socks_user}:${is_socks_pass} | base64 -w 0)@${is_addr}:${port}#233boy-$net-${is_addr}"
14931510
;;
14941511
http)
14951512
is_can_change=(0 1)

xray.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
args=$@
4-
is_sh_ver=v1.09
4+
is_sh_ver=v1.10
55

66
. /etc/xray/sh/src/init.sh

0 commit comments

Comments
 (0)