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