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

refactor(set_common_ports): replace recursion with while loop
This commit is contained in:
juewuy
2026-01-18 18:25:09 +08:00
committed by GitHub

View File

@@ -105,6 +105,7 @@ set_fw_filter() {
}
set_common_ports() {
while true; do
[ -z "$multiport" ] && multiport='22,80,443,8080,8443'
echo "-----------------------------------------------"
echo -e "\033[31m注意\033[0mMIX模式下所有fake-ip来源的非常用端口流量不会被过滤"
@@ -118,8 +119,11 @@ set_common_ports() {
echo -e " 5 重置为旧版放行端口"
echo -e " 0 返回上级菜单"
echo "-----------------------------------------------"
read -p "请输入对应数字 > " num
case $num in
read -r -p "请输入对应数字 > " num
case "$num" in
"" | 0)
break
;;
1)
if [ "$common_ports" = ON ]; then
common_ports=OFF
@@ -127,14 +131,13 @@ set_common_ports() {
common_ports=ON
fi
setconfig common_ports "$common_ports"
set_common_ports
;;
2)
port_count=$(echo "$multiport" | awk -F',' '{print NF}')
if [ "$port_count" -ge 15 ]; then
echo -e "\033[31m最多支持设置放行15个端口请先减少一些\033[0m"
else
read -p "请输入要放行的端口号 > " port
read -r -p "请输入要放行的端口号 > " port
if echo ",$multiport," | grep -q ",$port,"; then
echo -e "\033[31m输入错误请勿重复添加\033[0m"
elif [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
@@ -145,10 +148,9 @@ set_common_ports() {
fi
fi
sleep 1
set_common_ports
;;
3)
read -p "请输入要移除的端口号 > " port
read -r -p "请输入要移除的端口号 > " port
if echo ",$multiport," | grep -q ",$port,"; then
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
echo -e "\033[31m输入错误请输入正确的数值(1-65535)\033[0m"
@@ -160,25 +162,25 @@ set_common_ports() {
echo -e "\033[31m输入错误请输入已添加过的端口\033[0m"
fi
sleep 1
set_common_ports
;;
4)
multiport=''
setconfig multiport
sleep 1
set_common_ports
;;
5)
multiport='22,80,143,194,443,465,587,853,993,995,5222,8080,8443'
setconfig multiport "$multiport"
sleep 1
set_common_ports
;;
*)
errornum
sleep 1
;;
esac
done
}
set_cust_host_ipv4() { #自定义ipv4透明路由网段
[ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF"
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip