feat(脚本): 增加sing-box VLESS ws

pull/1006/head
mack-a 2024-04-10 11:10:11 +08:00
parent 4ae549a5bb
commit 064eb02dab
1 changed files with 79 additions and 13 deletions

View File

@ -183,6 +183,7 @@ initVar() {
singBoxTuicPort= singBoxTuicPort=
singBoxNaivePort= singBoxNaivePort=
singBoxVMessWSPort= singBoxVMessWSPort=
singBoxVLESSWSPort=
# nginx订阅端口 # nginx订阅端口
subscribePort= subscribePort=
@ -396,8 +397,6 @@ readInstallProtocolType() {
xrayVLESSRealityPort= xrayVLESSRealityPort=
xrayVLESSRealityServerName= xrayVLESSRealityServerName=
# xrayVLESSRealityPrivateKey=
# xrayVLESSRealityPublicKey=
currentRealityPrivateKey= currentRealityPrivateKey=
currentRealityPublicKey= currentRealityPublicKey=
@ -426,6 +425,10 @@ readInstallProtocolType() {
fi fi
if echo "${row}" | grep -q VLESS_WS_inbounds; then if echo "${row}" | grep -q VLESS_WS_inbounds; then
currentInstallProtocolType="${currentInstallProtocolType}1," currentInstallProtocolType="${currentInstallProtocolType}1,"
if [[ "${coreInstallType}" == "2" ]]; then
frontingType=03_VLESS_WS_inbounds
singBoxVLESSWSPort=$(jq .inbounds[0].listen_port "${row}.json")
fi
fi fi
if echo "${row}" | grep -q trojan_gRPC_inbounds; then if echo "${row}" | grep -q trojan_gRPC_inbounds; then
currentInstallProtocolType="${currentInstallProtocolType}2," currentInstallProtocolType="${currentInstallProtocolType}2,"
@ -717,6 +720,7 @@ readConfigHostPathUUID() {
currentPort= currentPort=
currentCDNAddress= currentCDNAddress=
singBoxVMessWSPath= singBoxVMessWSPath=
singBoxVLESSWSPath=
if [[ "${coreInstallType}" == "1" ]]; then if [[ "${coreInstallType}" == "1" ]]; then
@ -789,6 +793,10 @@ readConfigHostPathUUID() {
elif [[ "${coreInstallType}" == "2" && -f "${singBoxConfigPath}05_VMess_WS_inbounds.json" ]]; then elif [[ "${coreInstallType}" == "2" && -f "${singBoxConfigPath}05_VMess_WS_inbounds.json" ]]; then
singBoxVMessWSPath=$(jq -r .inbounds[0].transport.path "${singBoxConfigPath}05_VMess_WS_inbounds.json") singBoxVMessWSPath=$(jq -r .inbounds[0].transport.path "${singBoxConfigPath}05_VMess_WS_inbounds.json")
currentPath=$(jq -r .inbounds[0].transport.path "${singBoxConfigPath}05_VMess_WS_inbounds.json" | awk -F "[/]" '{print $2}') currentPath=$(jq -r .inbounds[0].transport.path "${singBoxConfigPath}05_VMess_WS_inbounds.json" | awk -F "[/]" '{print $2}')
elif [[ "${coreInstallType}" == "2" && -f "${singBoxConfigPath}03_VLESS_WS_inbounds.json" ]]; then
singBoxVLESSWSPath=$(jq -r .inbounds[0].transport.path "${singBoxConfigPath}03_VLESS_WS_inbounds.json")
currentPath=$(jq -r .inbounds[0].transport.path "${singBoxConfigPath}03_VLESS_WS_inbounds.json" | awk -F "[/]" '{print $2}')
currentPath=${currentPath::-2}
fi fi
fi fi
if [[ -f "/etc/v2ray-agent/cdn" ]] && grep -q "address" "/etc/v2ray-agent/cdn"; then if [[ -f "/etc/v2ray-agent/cdn" ]] && grep -q "address" "/etc/v2ray-agent/cdn"; then
@ -2715,6 +2723,11 @@ initSingBoxClients() {
currentUser="{\"uuid\":\"${uuid}\",\"flow\":\"xtls-rprx-vision\",\"name\":\"${name}-VLESS_TCP/TLS_Vision\"}" currentUser="{\"uuid\":\"${uuid}\",\"flow\":\"xtls-rprx-vision\",\"name\":\"${name}-VLESS_TCP/TLS_Vision\"}"
users=$(echo "${users}" | jq -r ". +=[${currentUser}]") users=$(echo "${users}" | jq -r ". +=[${currentUser}]")
fi fi
# VLESS WS
if echo "${type}" | grep -q ",1,"; then
currentUser="{\"uuid\":\"${uuid}\",\"name\":\"${name}-VLESS_WS\"}"
users=$(echo "${users}" | jq -r ". +=[${currentUser}]")
fi
# VMess ws # VMess ws
if echo "${type}" | grep -q ",3,"; then if echo "${type}" | grep -q ",3,"; then
currentUser="{\"uuid\":\"${uuid}\",\"name\":\"${name}-VMess_WS\",\"alterId\": 0}" currentUser="{\"uuid\":\"${uuid}\",\"name\":\"${name}-VMess_WS\",\"alterId\": 0}"
@ -4161,6 +4174,47 @@ EOF
rm /etc/v2ray-agent/sing-box/conf/config/02_VLESS_TCP_inbounds.json >/dev/null 2>&1 rm /etc/v2ray-agent/sing-box/conf/config/02_VLESS_TCP_inbounds.json >/dev/null 2>&1
fi fi
if echo "${selectCustomInstallType}" | grep -q ",1," || [[ "$1" == "all" ]]; then
echoContent yellow "\n===================== 配置VLESS+WS =====================\n"
echoContent skyBlue "\n开始配置VLESS+WS协议端口"
echo
mapfile -t result < <(initSingBoxPort "${singBoxVLESSWSPort}")
echoContent green "\n ---> VLESS_WS端口${result[-1]}"
checkDNSIP "${domain}"
removeNginxDefaultConf
handleSingBox stop
randomPathFunction
checkPortOpen "${result[-1]}" "${domain}"
cat <<EOF >/etc/v2ray-agent/sing-box/conf/config/03_VLESS_WS_inbounds.json
{
"inbounds":[
{
"type": "vless",
"listen":"::",
"listen_port":${result[-1]},
"tag":"VLESSWS",
"users":$(initSingBoxClients 1),
"tls":{
"server_name": "${sslDomain}",
"enabled": true,
"certificate_path": "/etc/v2ray-agent/tls/${sslDomain}.crt",
"key_path": "/etc/v2ray-agent/tls/${sslDomain}.key"
},
"transport": {
"type": "ws",
"path": "/${currentPath}ws",
"max_early_data": 2048,
"early_data_header_name": "Sec-WebSocket-Protocol"
}
}
]
}
EOF
elif [[ -z "$3" ]]; then
rm /etc/v2ray-agent/sing-box/conf/config/03_VLESS_WS_inbounds.json >/dev/null 2>&1
fi
if echo "${selectCustomInstallType}" | grep -q ",3," || [[ "$1" == "all" ]]; then if echo "${selectCustomInstallType}" | grep -q ",3," || [[ "$1" == "all" ]]; then
echoContent yellow "\n===================== 配置VMess+ws =====================\n" echoContent yellow "\n===================== 配置VMess+ws =====================\n"
echoContent skyBlue "\n开始配置VMess+ws协议端口" echoContent skyBlue "\n开始配置VMess+ws协议端口"
@ -4512,13 +4566,13 @@ EOF
elif [[ "${type}" == "vlessws" ]]; then elif [[ "${type}" == "vlessws" ]]; then
echoContent yellow " ---> 通用格式(VLESS+WS+TLS)" echoContent yellow " ---> 通用格式(VLESS+WS+TLS)"
echoContent green " vless://${id}@${add}:${port}?encryption=none&security=tls&type=ws&host=${currentHost}&sni=${currentHost}&fp=chrome&path=/${currentPath}ws#${email}\n" echoContent green " vless://${id}@${add}:${port}?encryption=none&security=tls&type=ws&host=${currentHost}&sni=${currentHost}&fp=chrome&path=${path}#${email}\n"
echoContent yellow " ---> 格式化明文(VLESS+WS+TLS)" echoContent yellow " ---> 格式化明文(VLESS+WS+TLS)"
echoContent green " 协议类型:VLESS地址:${add},伪装域名/SNI:${currentHost},端口:${port}client-fingerprint: chrome,用户ID:${id},安全:tls传输方式:ws路径:/${currentPath}ws,账户名:${email}\n" echoContent green " 协议类型:VLESS地址:${add},伪装域名/SNI:${currentHost},端口:${port}client-fingerprint: chrome,用户ID:${id},安全:tls传输方式:ws路径:${path},账户名:${email}\n"
cat <<EOF >>"/etc/v2ray-agent/subscribe_local/default/${user}" cat <<EOF >>"/etc/v2ray-agent/subscribe_local/default/${user}"
vless://${id}@${add}:${port}?encryption=none&security=tls&type=ws&host=${currentHost}&sni=${currentHost}&fp=chrome&path=/${currentPath}ws#${email} vless://${id}@${add}:${port}?encryption=none&security=tls&type=ws&host=${currentHost}&sni=${currentHost}&fp=chrome&path=${path}#${email}
EOF EOF
cat <<EOF >>"/etc/v2ray-agent/subscribe_local/clashMeta/${user}" cat <<EOF >>"/etc/v2ray-agent/subscribe_local/clashMeta/${user}"
- name: "${email}" - name: "${email}"
@ -4532,16 +4586,16 @@ EOF
client-fingerprint: chrome client-fingerprint: chrome
servername: ${currentHost} servername: ${currentHost}
ws-opts: ws-opts:
path: /${currentPath}ws path: ${path}
headers: headers:
Host: ${currentHost} Host: ${currentHost}
EOF EOF
singBoxSubscribeLocalConfig=$(jq -r ". += [{\"tag\":\"${email}\",\"type\":\"vless\",\"server\":\"${add}\",\"server_port\":${port},\"uuid\":\"${id}\",\"flow\":\"\",\"tls\":{\"enabled\":true,\"server_name\":\"${currentHost}\",\"utls\":{\"enabled\":true,\"fingerprint\":\"chrome\"}},\"multiplex\":{\"enabled\":false,\"protocol\":\"smux\",\"max_streams\":32},\"packet_encoding\":\"xudp\",\"transport\":{\"type\":\"ws\",\"path\":\"/${currentPath}ws\",\"headers\":{\"Host\":\"${port}\"}}}]" "/etc/v2ray-agent/subscribe_local/sing-box/${user}") singBoxSubscribeLocalConfig=$(jq -r ". += [{\"tag\":\"${email}\",\"type\":\"vless\",\"server\":\"${add}\",\"server_port\":${port},\"uuid\":\"${id}\",\"tls\":{\"enabled\":true,\"server_name\":\"${currentHost}\",\"utls\":{\"enabled\":true,\"fingerprint\":\"chrome\"}},\"multiplex\":{\"enabled\":false,\"protocol\":\"smux\",\"max_streams\":32},\"packet_encoding\":\"xudp\",\"transport\":{\"type\":\"ws\",\"path\":\"${path}\",\"headers\":{\"Host\":\"${currentHost}\"}}}]" "/etc/v2ray-agent/subscribe_local/sing-box/${user}")
echo "${singBoxSubscribeLocalConfig}" | jq . >"/etc/v2ray-agent/subscribe_local/sing-box/${user}" echo "${singBoxSubscribeLocalConfig}" | jq . >"/etc/v2ray-agent/subscribe_local/sing-box/${user}"
echoContent yellow " ---> 二维码 VLESS(VLESS+WS+TLS)" echoContent yellow " ---> 二维码 VLESS(VLESS+WS+TLS)"
echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3A%2F%2F${id}%40${add}%3A${port}%3Fencryption%3Dnone%26security%3Dtls%26type%3Dws%26host%3D${currentHost}%26fp%3Dchrome%26sni%3D${currentHost}%26path%3D%252f${currentPath}ws%23${email}" echoContent green " https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=vless%3A%2F%2F${id}%40${add}%3A${port}%3Fencryption%3Dnone%26security%3Dtls%26type%3Dws%26host%3D${currentHost}%26fp%3Dchrome%26sni%3D${currentHost}%26path%3D${path}%23${email}"
elif [[ "${type}" == "vlessgrpc" ]]; then elif [[ "${type}" == "vlessgrpc" ]]; then
@ -4825,17 +4879,28 @@ showAccounts() {
if echo ${currentInstallProtocolType} | grep -q ",1,"; then if echo ${currentInstallProtocolType} | grep -q ",1,"; then
echoContent skyBlue "\n================================ VLESS WS TLS [仅CDN推荐] ================================\n" echoContent skyBlue "\n================================ VLESS WS TLS [仅CDN推荐] ================================\n"
jq .inbounds[0].settings.clients ${configPath}03_VLESS_WS_inbounds.json | jq -c '.[]' | while read -r user; do jq .inbounds[0].settings.clients//.inbounds[0].users ${configPath}03_VLESS_WS_inbounds.json | jq -c '.[]' | while read -r user; do
local email= local email=
email=$(echo "${user}" | jq -r .email) email=$(echo "${user}" | jq -r .email//.name)
local vlessWSPort=${currentDefaultPort}
if [[ "${coreInstallType}" == "2" ]]; then
vlessWSPort="${singBoxVLESSWSPort}"
fi
echo echo
local path="${currentPath}ws" local path="${currentPath}ws"
if [[ ${coreInstallType} == "1" ]]; then
path="/${currentPath}ws"
elif [[ "${coreInstallType}" == "2" ]]; then
path="${singBoxVLESSWSPath}"
fi
local count= local count=
while read -r line; do while read -r line; do
echoContent skyBlue "\n ---> 账号:${email}${count}" echoContent skyBlue "\n ---> 账号:${email}${count}"
if [[ -n "${line}" ]]; then if [[ -n "${line}" ]]; then
defaultBase64Code vlessws "${currentDefaultPort}" "${email}${count}" "$(echo "${user}" | jq -r .id)" "${line}" defaultBase64Code vlessws "${vlessWSPort}" "${email}${count}" "$(echo "${user}" | jq -r .id//.uuid)" "${line}" "${path}"
count=$((count + 1)) count=$((count + 1))
echo echo
fi fi
@ -7326,6 +7391,7 @@ EOF
customSingBoxInstall() { customSingBoxInstall() {
echoContent skyBlue "\n========================个性化安装============================" echoContent skyBlue "\n========================个性化安装============================"
echoContent yellow "0.VLESS+Vision+TCP" echoContent yellow "0.VLESS+Vision+TCP"
echoContent yellow "1.VLESS+TLS+WS[仅CDN推荐]"
echoContent yellow "3.VMess+TLS+WS[仅CDN推荐]" echoContent yellow "3.VMess+TLS+WS[仅CDN推荐]"
echoContent yellow "4.Trojan+TLS[不推荐]" echoContent yellow "4.Trojan+TLS[不推荐]"
echoContent yellow "6.Hysteria2" echoContent yellow "6.Hysteria2"
@ -7356,7 +7422,7 @@ customSingBoxInstall() {
totalProgress=9 totalProgress=9
installTools 1 installTools 1
# 申请tls # 申请tls
if echo "${selectCustomInstallType}" | grep -q -E ",0,|,3,|,4,|,6,|,9,|,10,"; then if echo "${selectCustomInstallType}" | grep -q -E ",0,|,1,|,3,|,4,|,6,|,9,|,10,"; then
initTLSNginxConfig 2 initTLSNginxConfig 2
installTLS 3 installTLS 3
handleNginx stop handleNginx stop
@ -8824,7 +8890,7 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v3.2.38" echoContent green "当前版本v3.2.39"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c" echoContent green "描述:八合一共存脚本\c"
showInstallStatus showInstallStatus