refactor(set_adv_config): replace recursion with while loop

This commit is contained in:
Sofia
2026-01-11 12:51:18 +08:00
committed by GitHub
parent 55b8266dfd
commit 7676a3f607

View File

@@ -281,125 +281,130 @@ set_redir_mod() {
done done
} }
set_adv_config() { #端口设置 inputport() {
. "$CFG_PATH" >/dev/null read -p "请输入端口号(1-65535) > " portx
[ -z "$secret" ] && secret=未设置 . "$CRASHDIR"/menus/check_port.sh # 加载测试函数
[ -z "$table" ] && table=100 if check_port "$portx"; then
[ -z "$authentication" ] && auth=未设置 || auth=****** setconfig "$xport" "$portx"
inputport() { echo -e "\033[32m设置成功\033[0m"
read -p "请输入端口号(1-65535) > " portx else
. "$CRASHDIR"/menus/check_port.sh #加载测试函数 echo -e "\033[31m设置失败\033[0m"
if check_port "$portx"; then fi
setconfig "$xport" "$portx" sleep 1
echo -e "\033[32m设置成功\033[0m" }
set_adv_config
else # 端口设置
sleep 1 set_adv_config() {
fi while true; do
} . "$CFG_PATH" >/dev/null
echo "-----------------------------------------------" [ -z "$secret" ] && secret=未设置
echo -e " 1 修改Http/Sock5端口 \033[36m$mix_port\033[0m" [ -z "$table" ] && table=100
echo -e " 2 设置Http/Sock5密码 \033[36m$auth\033[0m" [ -z "$authentication" ] && auth=未设置 || auth=******
echo -e " 3 修改Redir/Tproxy端口\033[36m$redir_port,$((redir_port + 1))\033[0m"
echo -e " 4 修改DNS监听端口 \033[36m$dns_port\033[0m"
echo -e " 5 修改面板访问端口: \033[36m$db_port\033[0m"
echo -e " 6 设置面板访问密码: \033[36m$secret\033[0m"
echo -e " 8 自定义本机host地址 \033[36m$host\033[0m"
echo -e " 9 自定义路由表: \033[36m$table,$((table + 1))\033[0m"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0) ;;
1)
xport=mix_port
inputport
;;
2)
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "格式必须是\033[32m 用户名:密码 \033[0m的形式注意用小写冒号分隔" echo -e " 1 修改Http/Sock5端口 \033[36m$mix_port\033[0m"
echo -e "请尽量不要使用特殊符号!避免产生未知错误!" echo -e " 2 设置Http/Sock5密码 \033[36m$auth\033[0m"
echo "输入 0 删除密码" echo -e " 3 修改Redir/Tproxy端口\033[36m$redir_port,$((redir_port + 1))\033[0m"
echo "-----------------------------------------------" echo -e " 4 修改DNS监听端口 \033[36m$dns_port\033[0m"
read -p "请输入Http/Sock5用户名及密码 > " input echo -e " 5 修改面板访问端口: \033[36m$db_port\033[0m"
if [ "$input" = "0" ]; then echo -e " 6 设置面板访问密码: \033[36m$secret\033[0m"
authentication="" echo -e " 8 自定义本机host地址 \033[36m$host\033[0m"
setconfig authentication echo -e " 9 自定义路由表: \033[36m$table,$((table + 1))\033[0m"
echo 密码已移除! echo -e " 0 返回上级菜单"
else read -p "请输入对应数字 > " num
if [ "$local_proxy" = "ON" -a "$local_type" = "环境变量" ]; then case "$num" in
echo "-----------------------------------------------" "" | 0)
echo -e "\033[33m请先禁用本机劫持功能或使用增强模式\033[0m" break
sleep 1 ;;
1)
xport=mix_port
inputport
;;
2)
echo "-----------------------------------------------"
echo -e "格式必须是\033[32m 用户名:密码 \033[0m的形式注意用小写冒号分隔"
echo -e "请尽量不要使用特殊符号!避免产生未知错误!"
echo "输入 0 删除密码"
echo "-----------------------------------------------"
read -p "请输入Http/Sock5用户名及密码 > " input
if [ "$input" = "0" ]; then
authentication=""
setconfig authentication
echo "密码已移除!"
else else
authentication=$(echo $input | grep :) if [ "$local_proxy" = "ON" -a "$local_type" = "环境变量" ]; then
if [ -n "$authentication" ]; then echo "-----------------------------------------------"
setconfig authentication "'$authentication'" echo -e "\033[33m请先禁用本机劫持功能或使用增强模式\033[0m"
echo -e "\033[32m设置成功\033[0m" sleep 1
else else
echo -e "\033[31m输入有误请重新输入\033[0m" authentication=$(echo $input | grep :)
if [ -n "$authentication" ]; then
setconfig authentication "'$authentication'"
echo -e "\033[32m设置成功\033[0m"
else
echo -e "\033[31m输入有误请重新输入\033[0m"
fi
fi fi
fi fi
fi ;;
set_adv_config 3)
;; xport=redir_port
3) inputport
xport=redir_port ;;
inputport 4)
;; xport=dns_port
4) inputport
xport=dns_port ;;
inputport 5)
;; xport=db_port
5) inputport
xport=db_port ;;
inputport 6)
;; read -p "请输入面板访问密码(输入0删除密码) > " secret
6) if [ -n "$secret" ]; then
read -p "请输入面板访问密码(输入0删除密码) > " secret [ "$secret" = "0" ] && secret=""
if [ -n "$secret" ]; then setconfig secret $secret
[ "$secret" = "0" ] && secret="" echo -e "\033[32m设置成功\033[0m"
setconfig secret $secret fi
echo -e "\033[32m设置成功\033[0m" ;;
fi 8)
set_adv_config echo "-----------------------------------------------"
;; echo -e "\033[33m如果你的局域网网段不是192.168.x或172.16.x或10.x开头请务必修改\033[0m"
8) echo -e "\033[31m设置后如本机host地址有变动请务必重新修改\033[0m"
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "\033[33m如果你的局域网网段不是192.168.x或172.16.x或10.x开头请务必修改\033[0m" read -p "请输入自定义host地址(输入0移除自定义host) > " host
echo -e "\033[31m设置后如本机host地址有变动请务必重新修改\033[0m" if [ "$host" = "0" ]; then
echo "-----------------------------------------------" host=""
read -p "请输入自定义host地址(输入0移除自定义host) > " host setconfig host "$host"
if [ "$host" = "0" ]; then echo -e "\033[32m已经移除自定义host地址请重新运行脚本以自动获取host\033[0m"
host="" exit 0
setconfig host "$host" elif [ -n "$(echo $host | grep -E -o '\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[01][0-9]|22[0-3])\>(\.\<([0-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>){2}\.\<([1-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4])\>')" ]; then
echo -e "\033[32m已经移除自定义host地址请重新运行脚本以自动获取host\033[0m" setconfig host "$host"
exit 0 echo -e "\033[32m设置成功\033[0m"
elif [ -n "$(echo $host | grep -E -o '\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[01][0-9]|22[0-3])\>(\.\<([0-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>){2}\.\<([1-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4])\>')" ]; then else
setconfig host "$host" host=""
echo -e "\033[32m设置成功\033[0m" echo -e "\033[31m输入错误请仔细核对\033[0m"
else fi
host="" sleep 1
echo -e "\033[31m输入错误请仔细核对\033[0m" ;;
fi 9)
sleep 1 echo "-----------------------------------------------"
set_adv_config echo -e "\033[33m仅限Tproxy、Tun或混合模式路由表出现冲突时才需要设置\033[0m"
;; read -p "请输入路由表地址(不明勿动建议102-125之间) > " table
9) if [ -n "$table" ]; then
echo "-----------------------------------------------" [ "$table" = "0" ] && table="100"
echo -e "\033[33m仅限Tproxy、Tun或混合模式路由表出现冲突时才需要设置\033[0m" setconfig table "$table"
read -p "请输入路由表地址(不明勿动建议102-125之间) > " table echo -e "\033[32m设置成功\033[0m"
if [ -n "$table" ]; then fi
[ "$table" = "0" ] && table="100" ;;
setconfig table "$table" *)
echo -e "\033[32m设置成功\033[0m" errornum
fi sleep 1
set_adv_config break
;; ;;
*) esac
errornum done
;;
esac
} }
set_firewall_area() { #路由范围设置 set_firewall_area() { #路由范围设置
[ -z "$vm_redir" ] && vm_redir='OFF' [ -z "$vm_redir" ] && vm_redir='OFF'
echo "-----------------------------------------------" echo "-----------------------------------------------"