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,104 +228,103 @@ set_bot_tg(){
;; ;;
esac esac
} }
#自定义入站
set_vmess(){ # 自定义入站
echo "-----------------------------------------------" set_vmess() {
echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!" while true; do
echo -e " \033[31m切勿用于搭建违法翻墙节点违者后果自负\033[0m" echo "-----------------------------------------------"
echo "-----------------------------------------------" echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!"
echo -e " 1 \033[32m启用/关闭\033[0mVmess入站 \033[32m$vms_service\033[0m" echo -e " \033[31m切勿用于搭建违法翻墙节点违者后果自负\033[0m"
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e " 2 设置\033[36m监听端口\033[0m \033[36m$vms_port\033[0m" echo -e " 1 \033[32m启用/关闭\033[0mVmess入站 \033[32m$vms_service\033[0m"
echo -e " 3 设置\033[33mWS-path(可选)\033[0m \033[33m$vms_ws_path\033[0m" echo "-----------------------------------------------"
echo -e " 4 设置\033[36m秘钥-uuid\033[0m \033[36m$vms_uuid\033[0m" echo -e " 2 设置\033[36m监听端口\033[0m \033[36m$vms_port\033[0m"
echo -e " 5 一键生成\033[32m随机秘钥\033[0m" echo -e " 3 设置\033[33mWS-path(可选)\033[0m \033[33m$vms_ws_path\033[0m"
echo -e " 6 设置\033[36m混淆host(可选)\033[0m \033[33m$vms_host\033[0m" echo -e " 4 设置\033[36m秘钥-uuid\033[0m \033[36m$vms_uuid\033[0m"
gen_base64 1 >/dev/null 2>&1 && echo -e " 5 一键生成\033[32m随机秘钥\033[0m"
echo -e " 7 一键生成\033[32m分享链接\033[0m" echo -e " 6 设置\033[36m混淆host(可选)\033[0m \033[33m$vms_host\033[0m"
echo -e " 0 返回上级菜单 \033[0m" gen_base64 1 >/dev/null 2>&1 &&
echo "-----------------------------------------------" echo -e " 7 一键生成\033[32m分享链接\033[0m"
read -p "请输入对应数字 > " num echo -e " 0 返回上级菜单 \033[0m"
case "$num" in echo "-----------------------------------------------"
0) ;; read -p "请输入对应数字 > " num
1) case "$num" in
if [ "$vms_service" = ON ];then "" | 0)
vms_service=OFF break
setconfig vms_service "$vms_service" ;;
else 1)
if [ -n "$vms_port" ] && [ -n "$vms_uuid" ];then if [ "$vms_service" = ON ]; then
vms_service=ON vms_service=OFF
setconfig vms_service "$vms_service" setconfig vms_service "$vms_service"
else else
echo -e "\033[31m请先完成必选设置\033[0m" if [ -n "$vms_port" ] && [ -n "$vms_uuid" ]; then
sleep 1 vms_service=ON
fi setconfig vms_service "$vms_service"
fi else
set_vmess echo -e "\033[31m请先完成必选设置\033[0m"
;; sleep 1
2) fi
read -p "请输入端口号(输入0删除) > " text fi
if [ "$text" = 0 ];then ;;
vms_port='' 2)
setconfig vms_port "" "$GT_CFG_PATH" read -p "请输入端口号(输入0删除) > " text
elif check_port "$text"; then if [ "$text" = 0 ]; then
vms_port="$text" vms_port=''
setconfig vms_port "$text" "$GT_CFG_PATH" setconfig vms_port "" "$GT_CFG_PATH"
else elif check_port "$text"; then
sleep 1 vms_port="$text"
fi setconfig vms_port "$text" "$GT_CFG_PATH"
set_vmess else
;; sleep 1
3) fi
read -p "请输入ws-path路径(输入0删除) > " text ;;
if [ "$text" = 0 ];then 3)
vms_ws_path='' read -p "请输入ws-path路径(输入0删除) > " text
setconfig vms_ws_path "" "$GT_CFG_PATH" if [ "$text" = 0 ]; then
elif echo "$text" |grep -qE '^/';then vms_ws_path=''
vms_ws_path="$text" setconfig vms_ws_path "" "$GT_CFG_PATH"
setconfig vms_ws_path "$text" "$GT_CFG_PATH" elif echo "$text" | grep -qE '^/'; then
else vms_ws_path="$text"
echo -e "\033[31m不是合法的path路径必须以【/】开头!\033[0m" setconfig vms_ws_path "$text" "$GT_CFG_PATH"
sleep 1 else
fi echo -e "\033[31m不是合法的path路径必须以【/】开头!\033[0m"
set_vmess sleep 1
;; fi
4) ;;
read -p "请输入UUID(输入0删除) > " text 4)
if [ "$text" = 0 ];then read -p "请输入UUID(输入0删除) > " text
vms_uuid='' if [ "$text" = 0 ]; then
setconfig vms_uuid "" "$GT_CFG_PATH" vms_uuid=''
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 setconfig vms_uuid "" "$GT_CFG_PATH"
vms_uuid="$text" 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
setconfig vms_uuid "$text" "$GT_CFG_PATH" vms_uuid="$text"
else setconfig vms_uuid "$text" "$GT_CFG_PATH"
echo -e "\033[31m不是合法的UUID格式请重新输入或使用随机生成功能\033[0m" else
sleep 1 echo -e "\033[31m不是合法的UUID格式请重新输入或使用随机生成功能\033[0m"
fi sleep 1
set_vmess fi
;; ;;
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)
;; read -p "请输入本机公网IP(4/6)或域名 > " host_wan
7) if [ -n "$host_wan" ] && [ -n "$vms_port" ] && [ -n "$vms_uuid" ]; then
read -p "请输入本机公网IP(4/6)或域名 > " host_wan [ -n "$vms_ws_path" ] && vms_net=ws
if [ -n "$host_wan" ] && [ -n "$vms_port" ] && [ -n "$vms_uuid" ];then vms_json=$(
[ -n "$vms_ws_path" ] && vms_net=ws cat <<EOF
vms_json=$(cat <<EOF
{ {
"v": "2", "v": "2",
"ps": "ShellCrash_vms_in", "ps": "ShellCrash_vms_in",
@@ -339,19 +338,24 @@ 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"
else else
echo -e "\033[31m请先完成必选设置\033[0m" echo -e "\033[31m请先完成必选设置\033[0m"
fi fi
sleep 1 sleep 1
set_vmess ;;
;; *)
*) errornum ;; errornum
esac sleep 1
break
;;
esac
done
} }
set_shadowsocks(){ set_shadowsocks(){
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!" echo -e "\033[31m注意\033[0m设置的端口会添加到公网访问防火墙并自动放行\n 脚本只提供基础功能,更多需求请用自定义配置文件功能!"