refactor(set_fw_wan): replace recursion with while loop

This commit is contained in:
Sofia
2026-01-15 16:14:33 +08:00
committed by GitHub
parent 281595f79f
commit 174cbabb93

View File

@@ -78,6 +78,7 @@ gateway() {
# 公网防火墙 # 公网防火墙
set_fw_wan() { set_fw_wan() {
while true; do
[ -z "$fw_wan" ] && fw_wan=ON [ -z "$fw_wan" ] && fw_wan=ON
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "\033[31m注意\033[0m如在vps运行还需在vps安全策略对相关端口同时放行" echo -e "\033[31m注意\033[0m如在vps运行还需在vps安全策略对相关端口同时放行"
@@ -95,6 +96,9 @@ set_fw_wan() {
echo "-----------------------------------------------" echo "-----------------------------------------------"
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
case $num in case $num in
"" | 0)
break
;;
1) 1)
if [ "$fw_wan" = ON ]; then if [ "$fw_wan" = ON ]; then
read -p "确认关闭防火墙?这会带来极大的安全隐患!(1/0) > " res read -p "确认关闭防火墙?这会带来极大的安全隐患!(1/0) > " res
@@ -103,7 +107,6 @@ set_fw_wan() {
fw_wan=ON fw_wan=ON
fi fi
setconfig fw_wan "$fw_wan" setconfig fw_wan "$fw_wan"
set_fw_wan
;; ;;
2) 2)
port_count=$(echo "$fw_wan_ports" | awk -F',' '{print NF}') port_count=$(echo "$fw_wan_ports" | awk -F',' '{print NF}')
@@ -121,7 +124,6 @@ set_fw_wan() {
fi fi
fi fi
sleep 1 sleep 1
set_fw_wan
;; ;;
3) 3)
read -p "请输入要移除的端口号 > " port read -p "请输入要移除的端口号 > " port
@@ -136,19 +138,20 @@ set_fw_wan() {
echo -e "\033[31m输入错误请输入已添加过的端口\033[0m" echo -e "\033[31m输入错误请输入已添加过的端口\033[0m"
fi fi
sleep 1 sleep 1
set_fw_wan
;; ;;
4) 4)
fw_wan_ports='' fw_wan_ports=''
setconfig fw_wan_ports setconfig fw_wan_ports
sleep 1 sleep 1
set_fw_wan
;; ;;
*) *)
errornum errornum
sleep 1
;; ;;
esac esac
done
} }
#tg_BOT相关 #tg_BOT相关
set_bot_tg_config(){ set_bot_tg_config(){
setconfig TG_TOKEN "$TOKEN" "$GT_CFG_PATH" setconfig TG_TOKEN "$TOKEN" "$GT_CFG_PATH"