refactor(set_cust_host_ipv4): replace recursion with while loop

This commit is contained in:
Sofia
2026-01-19 13:44:56 +08:00
committed by GitHub
parent c98180fc4e
commit 7bf661ee3d

View File

@@ -181,45 +181,47 @@ set_common_ports() {
done done
} }
set_cust_host_ipv4() { #自定义ipv4透明路由网段 # 自定义ipv4透明路由网段
[ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF" set_cust_host_ipv4() {
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip while true; do
echo "-----------------------------------------------" [ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF"
echo -e "当前默认透明路由的网段为: \033[32m$host_ipv4 \033[0m" . "$CRASHDIR"/starts/fw_getlanip.sh && getlanip
echo -e "当前已添加的自定义网段为:\033[36m$cust_host_ipv4\033[0m" echo "-----------------------------------------------"
echo "-----------------------------------------------" echo -e "当前默认透明路由的网段为: \033[32m$host_ipv4 \033[0m"
echo -e " 1 移除所有自定义网段" echo -e "当前已添加的自定义网段为:\033[36m$cust_host_ipv4\033[0m"
echo -e " 2 使用自定义网段覆盖默认网段 \033[36m$replace_default_host_ipv4\033[0m" echo "-----------------------------------------------"
echo -e " 0 返回上级菜单" echo -e " 1 移除所有自定义网段"
read -p "请输入对应的序号或需要额外添加的网段 > " text echo -e " 2 使用自定义网段覆盖默认网段 \033[36m$replace_default_host_ipv4\033[0m"
case "$text" in echo -e " 0 返回上级菜单"
2) read -r -p "请输入对应的序号或需要额外添加的网段 > " text
if [ "$replace_default_host_ipv4" == "OFF" ]; then case "$text" in
replace_default_host_ipv4="ON" "" | 0)
else break
replace_default_host_ipv4="OFF" ;;
fi 1)
setconfig replace_default_host_ipv4 "$replace_default_host_ipv4" unset cust_host_ipv4
set_cust_host_ipv4 setconfig cust_host_ipv4
;; ;;
1) 2)
unset cust_host_ipv4 if [ "$replace_default_host_ipv4" == "OFF" ]; then
setconfig cust_host_ipv4 replace_default_host_ipv4="ON"
set_cust_host_ipv4 else
;; replace_default_host_ipv4="OFF"
0) ;; fi
*) setconfig replace_default_host_ipv4 "$replace_default_host_ipv4"
if [ -n "$(echo $text | grep -Eo '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}'$)" -a -z "$(echo $cust_host_ipv4 | grep "$text")" ]; then ;;
cust_host_ipv4="$cust_host_ipv4 $text" *)
setconfig cust_host_ipv4 "'$cust_host_ipv4'" if [ -n "$(echo "$text" | grep -Eo '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}'$)" ] && [ -z "$(echo "$cust_host_ipv4" | grep "$text")" ]; then
else cust_host_ipv4="$cust_host_ipv4 $text"
echo "-----------------------------------------------" setconfig cust_host_ipv4 "'$cust_host_ipv4'"
echo -e "\033[31m请输入正确的网段地址\033[0m" else
fi echo "-----------------------------------------------"
sleep 1 echo -e "\033[31m请输入正确的网段地址\033[0m"
set_cust_host_ipv4 fi
;; sleep 1
esac ;;
esac
done
} }
# 局域网设备过滤 # 局域网设备过滤