Merge pull request #1152 from sofia-riese/patch-1

refactor(set_fw_filter): replace recursion with while loop
This commit is contained in:
juewuy
2026-01-18 17:21:29 +08:00
committed by GitHub

View File

@@ -4,7 +4,9 @@
[ -n "$__IS_MODULE_FW_FILTER_LOADED" ] && return [ -n "$__IS_MODULE_FW_FILTER_LOADED" ] && return
__IS_MODULE_FW_FILTER_LOADED=1 __IS_MODULE_FW_FILTER_LOADED=1
set_fw_filter(){ #流量过滤 # 流量过滤
set_fw_filter() {
while true; do
[ -z "$common_ports" ] && common_ports=ON [ -z "$common_ports" ] && common_ports=ON
[ -z "$quic_rj" ] && quic_rj=OFF [ -z "$quic_rj" ] && quic_rj=OFF
[ -z "$cn_ip_route" ] && cn_ip_route=OFF [ -z "$cn_ip_route" ] && cn_ip_route=OFF
@@ -20,19 +22,19 @@ set_fw_filter(){ #流量过滤
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e " 0 返回上级菜单 \033[0m" echo -e " 0 返回上级菜单 \033[0m"
echo "-----------------------------------------------" echo "-----------------------------------------------"
read -p "请输入对应数字 > " num read -r -p "请输入对应数字 > " num
case "$num" in case "$num" in
0) "" | 0)
break
;; ;;
1) 1)
echo "-----------------------------------------------" echo "-----------------------------------------------"
if [ -n "$(pidof CrashCore)" ] && [ "$firewall_mod" = 'iptables' ]; then if [ -n "$(pidof CrashCore)" ] && [ "$firewall_mod" = 'iptables' ]; then
read -p "切换时将停止服务,是否继续?(1/0) > " res read -r -p "切换时将停止服务,是否继续?(1/0) > " res
[ "$res" = 1 ] && "$CRASHDIR"/start.sh stop && set_common_ports [ "$res" = 1 ] && "$CRASHDIR"/start.sh stop && set_common_ports
else else
set_common_ports set_common_ports
fi fi
set_fw_filter
;; ;;
2) 2)
checkcfg_mac=$(cat "$CRASHDIR"/configs/mac) checkcfg_mac=$(cat "$CRASHDIR"/configs/mac)
@@ -41,11 +43,10 @@ set_fw_filter(){ #流量过滤
checkcfg_mac_new=$(cat "$CRASHDIR"/configs/mac) checkcfg_mac_new=$(cat "$CRASHDIR"/configs/mac)
[ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart [ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart
fi fi
set_fw_filter
;; ;;
3) 3)
echo "-----------------------------------------------" echo "-----------------------------------------------"
if [ -n "$(echo "$redir_mod" | grep -oE '混合|Tproxy|Tun')" ]; then if echo "$redir_mod" | grep -oqE '混合|Tproxy|Tun'; then
if [ "$quic_rj" = "OFF" ]; then if [ "$quic_rj" = "OFF" ]; then
echo -e "\033[33m已禁止QUIC流量通过ShellCrash内核\033[0m" echo -e "\033[33m已禁止QUIC流量通过ShellCrash内核\033[0m"
quic_rj=ON quic_rj=ON
@@ -58,7 +59,6 @@ set_fw_filter(){ #流量过滤
echo -e "\033[33m当前模式默认不会代理UDP流量无需设置\033[0m" echo -e "\033[33m当前模式默认不会代理UDP流量无需设置\033[0m"
fi fi
sleep 1 sleep 1
set_fw_filter
;; ;;
4) 4)
if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = 'nftables' ]; then if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = 'nftables' ]; then
@@ -76,20 +76,18 @@ set_fw_filter(){ #流量过滤
echo -e "\033[31m当前设备缺少ipset模块或未使用nftables模式无法启用绕过功能\033[0m" echo -e "\033[31m当前设备缺少ipset模块或未使用nftables模式无法启用绕过功能\033[0m"
sleep 1 sleep 1
fi fi
set_fw_filter
;; ;;
5) 5)
set_cust_host_ipv4 set_cust_host_ipv4
set_fw_filter
;; ;;
6) 6)
[ -z "$reserve_ipv4" ] && reserve_ipv4="0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 224.0.0.0/4 240.0.0.0/4" [ -z "$reserve_ipv4" ] && reserve_ipv4="0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 224.0.0.0/4 240.0.0.0/4"
echo -e "当前网段:\033[36m$reserve_ipv4\033[0m" echo -e "当前网段:\033[36m$reserve_ipv4\033[0m"
echo -e "\033[33m地址必须是空格分隔错误的设置可能导致网络回环或启动报错请务必谨慎\033[0m" echo -e "\033[33m地址必须是空格分隔错误的设置可能导致网络回环或启动报错请务必谨慎\033[0m"
read -p "请输入 > " text read -p "请输入 > " text
if [ -n "$( if
echo $text | grep -E "(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[1-2]?[0-9]))( +|$)+" echo "$text" | grep -Eq "(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[1-2]?[0-9]))( +|$)+"
)" ]; then then
reserve_ipv4="$text" reserve_ipv4="$text"
echo -e "已将保留地址网段设为:\033[32m$reserve_ipv4\033[0m" echo -e "已将保留地址网段设为:\033[32m$reserve_ipv4\033[0m"
setconfig reserve_ipv4 "'$reserve_ipv4'" setconfig reserve_ipv4 "'$reserve_ipv4'"
@@ -97,13 +95,15 @@ set_fw_filter(){ #流量过滤
echo -e "\033[31m输入有误操作已取消\033[0m" echo -e "\033[31m输入有误操作已取消\033[0m"
fi fi
sleep 1 sleep 1
set_fw_filter
;; ;;
*) *)
errornum errornum
sleep 1
;; ;;
esac esac
done
} }
set_common_ports() { set_common_ports() {
[ -z "$multiport" ] && multiport='22,80,443,8080,8443' [ -z "$multiport" ] && multiport='22,80,443,8080,8443'
echo "-----------------------------------------------" echo "-----------------------------------------------"