refactor: replace recursion with while loop in set_vmess

This commit is contained in:
Sofia
2026-01-09 10:10:25 +08:00
committed by GitHub
parent 2f796af178
commit 4003a80c56

View File

@@ -228,8 +228,10 @@ set_bot_tg(){
;; ;;
esac esac
} }
#自定义入站
set_vmess(){ # 自定义入站
set_vmess() {
while true; do
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!" echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!"
echo -e " \033[31m切勿用于搭建违法翻墙节点违者后果自负\033[0m" echo -e " \033[31m切勿用于搭建违法翻墙节点违者后果自负\033[0m"
@@ -247,13 +249,15 @@ set_vmess(){
echo "-----------------------------------------------" echo "-----------------------------------------------"
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
case "$num" in case "$num" in
0) ;; "" | 0)
break
;;
1) 1)
if [ "$vms_service" = ON ];then if [ "$vms_service" = ON ]; then
vms_service=OFF vms_service=OFF
setconfig vms_service "$vms_service" setconfig vms_service "$vms_service"
else else
if [ -n "$vms_port" ] && [ -n "$vms_uuid" ];then if [ -n "$vms_port" ] && [ -n "$vms_uuid" ]; then
vms_service=ON vms_service=ON
setconfig vms_service "$vms_service" setconfig vms_service "$vms_service"
else else
@@ -261,11 +265,10 @@ set_vmess(){
sleep 1 sleep 1
fi fi
fi fi
set_vmess
;; ;;
2) 2)
read -p "请输入端口号(输入0删除) > " text read -p "请输入端口号(输入0删除) > " text
if [ "$text" = 0 ];then if [ "$text" = 0 ]; then
vms_port='' vms_port=''
setconfig vms_port "" "$GT_CFG_PATH" setconfig vms_port "" "$GT_CFG_PATH"
elif check_port "$text"; then elif check_port "$text"; then
@@ -274,58 +277,54 @@ set_vmess(){
else else
sleep 1 sleep 1
fi fi
set_vmess
;; ;;
3) 3)
read -p "请输入ws-path路径(输入0删除) > " text read -p "请输入ws-path路径(输入0删除) > " text
if [ "$text" = 0 ];then if [ "$text" = 0 ]; then
vms_ws_path='' vms_ws_path=''
setconfig vms_ws_path "" "$GT_CFG_PATH" setconfig vms_ws_path "" "$GT_CFG_PATH"
elif echo "$text" |grep -qE '^/';then elif echo "$text" | grep -qE '^/'; then
vms_ws_path="$text" vms_ws_path="$text"
setconfig vms_ws_path "$text" "$GT_CFG_PATH" setconfig vms_ws_path "$text" "$GT_CFG_PATH"
else else
echo -e "\033[31m不是合法的path路径必须以【/】开头!\033[0m" echo -e "\033[31m不是合法的path路径必须以【/】开头!\033[0m"
sleep 1 sleep 1
fi fi
set_vmess
;; ;;
4) 4)
read -p "请输入UUID(输入0删除) > " text read -p "请输入UUID(输入0删除) > " text
if [ "$text" = 0 ];then if [ "$text" = 0 ]; then
vms_uuid='' vms_uuid=''
setconfig vms_uuid "" "$GT_CFG_PATH" setconfig vms_uuid "" "$GT_CFG_PATH"
elif echo "$text" |grep -qiE '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$';then elif echo "$text" | grep -qiE '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'; then
vms_uuid="$text" vms_uuid="$text"
setconfig vms_uuid "$text" "$GT_CFG_PATH" setconfig vms_uuid "$text" "$GT_CFG_PATH"
else else
echo -e "\033[31m不是合法的UUID格式请重新输入或使用随机生成功能\033[0m" echo -e "\033[31m不是合法的UUID格式请重新输入或使用随机生成功能\033[0m"
sleep 1 sleep 1
fi fi
set_vmess
;; ;;
5) 5)
vms_uuid=$(cat /proc/sys/kernel/random/uuid) vms_uuid=$(cat /proc/sys/kernel/random/uuid)
setconfig vms_uuid "$vms_uuid" "$GT_CFG_PATH" setconfig vms_uuid "$vms_uuid" "$GT_CFG_PATH"
sleep 1 sleep 1
set_vmess
;; ;;
6) 6)
read -p "请输入免流混淆host(输入0删除) > " text read -p "请输入免流混淆host(输入0删除) > " text
if [ "$text" = 0 ];then if [ "$text" = 0 ]; then
vms_host='' vms_host=''
setconfig vms_host "" "$GT_CFG_PATH" setconfig vms_host "" "$GT_CFG_PATH"
else else
vms_host="$text" vms_host="$text"
setconfig vms_host "$text" "$GT_CFG_PATH" setconfig vms_host "$text" "$GT_CFG_PATH"
fi fi
set_vmess
;; ;;
7) 7)
read -p "请输入本机公网IP(4/6)或域名 > " host_wan read -p "请输入本机公网IP(4/6)或域名 > " host_wan
if [ -n "$host_wan" ] && [ -n "$vms_port" ] && [ -n "$vms_uuid" ];then if [ -n "$host_wan" ] && [ -n "$vms_port" ] && [ -n "$vms_uuid" ]; then
[ -n "$vms_ws_path" ] && vms_net=ws [ -n "$vms_ws_path" ] && vms_net=ws
vms_json=$(cat <<EOF vms_json=$(
cat <<EOF
{ {
"v": "2", "v": "2",
"ps": "ShellCrash_vms_in", "ps": "ShellCrash_vms_in",
@@ -339,7 +338,7 @@ set_vmess(){
"host": "$vms_host" "host": "$vms_host"
} }
EOF EOF
) )
vms_link="vmess://$(gen_base64 "$vms_json")" vms_link="vmess://$(gen_base64 "$vms_json")"
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "你的分享链接是(请勿随意分享给他人):\n\033[32m$vms_link\033[0m" echo -e "你的分享链接是(请勿随意分享给他人):\n\033[32m$vms_link\033[0m"
@@ -347,11 +346,16 @@ EOF
echo -e "\033[31m请先完成必选设置\033[0m" echo -e "\033[31m请先完成必选设置\033[0m"
fi fi
sleep 1 sleep 1
set_vmess
;; ;;
*) errornum ;; *)
errornum
sleep 1
break
;;
esac esac
done
} }
set_shadowsocks(){ set_shadowsocks(){
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!" echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!"