Merge pull request #1114 from sofia-riese/patch-4

refactor(set_adv_config): replace recursion with while loop
This commit is contained in:
juewuy
2026-01-15 17:04:09 +08:00
committed by GitHub

View File

@@ -281,22 +281,27 @@ set_redir_mod() {
done
}
set_adv_config() { #端口设置
inputport() {
read -p "请输入端口号(1-65535) > " portx
. "$CRASHDIR"/menus/check_port.sh # 加载测试函数
if check_port "$portx"; then
setconfig "$xport" "$portx"
echo -e "\033[32m设置成功\033[0m"
return 0
else
echo -e "\033[31m设置失败\033[0m"
sleep 1
return 1
fi
}
# 端口设置
set_adv_config() {
while true; do
. "$CFG_PATH" >/dev/null
[ -z "$secret" ] && secret=未设置
[ -z "$table" ] && table=100
[ -z "$authentication" ] && auth=未设置 || auth=******
inputport() {
read -p "请输入端口号(1-65535) > " portx
. "$CRASHDIR"/menus/check_port.sh #加载测试函数
if check_port "$portx"; then
setconfig "$xport" "$portx"
echo -e "\033[32m设置成功\033[0m"
set_adv_config
else
sleep 1
fi
}
echo "-----------------------------------------------"
echo -e " 1 修改Http/Sock5端口 \033[36m$mix_port\033[0m"
echo -e " 2 设置Http/Sock5密码 \033[36m$auth\033[0m"
@@ -309,10 +314,18 @@ set_adv_config() { #端口设置
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0) ;;
"" | 0)
break
;;
1)
xport=mix_port
inputport
ret=$?
if [ "$ret" -eq 1 ]; then
break
else
continue
fi
;;
2)
echo "-----------------------------------------------"
@@ -324,14 +337,14 @@ set_adv_config() { #端口设置
if [ "$input" = "0" ]; then
authentication=""
setconfig authentication
echo 密码已移除!
echo "密码已移除!"
else
if [ "$local_proxy" = "ON" -a "$local_type" = "环境变量" ]; then
if [ "$local_proxy" = "ON" ] && [ "$local_type" = "环境变量" ]; then
echo "-----------------------------------------------"
echo -e "\033[33m请先禁用本机劫持功能或使用增强模式\033[0m"
sleep 1
else
authentication=$(echo $input | grep :)
authentication=$(echo "$input" | grep :)
if [ -n "$authentication" ]; then
setconfig authentication "'$authentication'"
echo -e "\033[32m设置成功\033[0m"
@@ -340,28 +353,54 @@ set_adv_config() { #端口设置
fi
fi
fi
set_adv_config
ret=$?
if [ "$ret" -eq 1 ]; then
break
else
continue
fi
;;
3)
xport=redir_port
inputport
ret=$?
if [ "$ret" -eq 1 ]; then
break
else
continue
fi
;;
4)
xport=dns_port
inputport
ret=$?
if [ "$ret" -eq 1 ]; then
break
else
continue
fi
;;
5)
xport=db_port
inputport
ret=$?
if [ "$ret" -eq 1 ]; then
break
else
continue
fi
;;
6)
read -p "请输入面板访问密码(输入0删除密码) > " secret
if [ -n "$secret" ]; then
[ "$secret" = "0" ] && secret=""
setconfig secret $secret
setconfig secret "$secret"
echo -e "\033[32m设置成功\033[0m"
fi
set_adv_config
;;
8)
echo "-----------------------------------------------"
@@ -374,7 +413,7 @@ set_adv_config() { #端口设置
setconfig host "$host"
echo -e "\033[32m已经移除自定义host地址请重新运行脚本以自动获取host\033[0m"
exit 0
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
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
setconfig host "$host"
echo -e "\033[32m设置成功\033[0m"
else
@@ -382,7 +421,6 @@ set_adv_config() { #端口设置
echo -e "\033[31m输入错误请仔细核对\033[0m"
fi
sleep 1
set_adv_config
;;
9)
echo "-----------------------------------------------"
@@ -393,13 +431,15 @@ set_adv_config() { #端口设置
setconfig table "$table"
echo -e "\033[32m设置成功\033[0m"
fi
set_adv_config
;;
*)
errornum
sleep 1
;;
esac
done
}
set_firewall_area() { #路由范围设置
[ -z "$vm_redir" ] && vm_redir='OFF'
echo "-----------------------------------------------"