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