mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-12 00:11:31 +00:00
refactor(set_common_ports): replace recursion with while loop
This commit is contained in:
@@ -105,80 +105,82 @@ set_fw_filter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_common_ports() {
|
set_common_ports() {
|
||||||
[ -z "$multiport" ] && multiport='22,80,443,8080,8443'
|
while true; do
|
||||||
echo "-----------------------------------------------"
|
[ -z "$multiport" ] && multiport='22,80,443,8080,8443'
|
||||||
echo -e "\033[31m注意:\033[0mMIX模式下,所有fake-ip来源的非常用端口流量不会被过滤"
|
echo "-----------------------------------------------"
|
||||||
[ -n "$common_ports" ] &&
|
echo -e "\033[31m注意:\033[0mMIX模式下,所有fake-ip来源的非常用端口流量不会被过滤"
|
||||||
echo -e "当前放行端口:\033[36m$multiport\033[0m"
|
[ -n "$common_ports" ] &&
|
||||||
echo "-----------------------------------------------"
|
echo -e "当前放行端口:\033[36m$multiport\033[0m"
|
||||||
echo -e " 1 启用/关闭端口过滤: \033[36m$common_ports\033[0m"
|
echo "-----------------------------------------------"
|
||||||
echo -e " 2 添加放行端口"
|
echo -e " 1 启用/关闭端口过滤: \033[36m$common_ports\033[0m"
|
||||||
echo -e " 3 移除指定放行端口"
|
echo -e " 2 添加放行端口"
|
||||||
echo -e " 4 重置默认放行端口"
|
echo -e " 3 移除指定放行端口"
|
||||||
echo -e " 5 重置为旧版放行端口"
|
echo -e " 4 重置默认放行端口"
|
||||||
echo -e " 0 返回上级菜单"
|
echo -e " 5 重置为旧版放行端口"
|
||||||
echo "-----------------------------------------------"
|
echo -e " 0 返回上级菜单"
|
||||||
read -p "请输入对应数字 > " num
|
echo "-----------------------------------------------"
|
||||||
case $num in
|
read -r -p "请输入对应数字 > " num
|
||||||
1)
|
case "$num" in
|
||||||
if [ "$common_ports" = ON ];then
|
"" | 0)
|
||||||
common_ports=OFF
|
break
|
||||||
else
|
;;
|
||||||
common_ports=ON
|
1)
|
||||||
fi
|
if [ "$common_ports" = ON ]; then
|
||||||
setconfig common_ports "$common_ports"
|
common_ports=OFF
|
||||||
set_common_ports
|
else
|
||||||
;;
|
common_ports=ON
|
||||||
2)
|
fi
|
||||||
port_count=$(echo "$multiport" | awk -F',' '{print NF}' )
|
setconfig common_ports "$common_ports"
|
||||||
if [ "$port_count" -ge 15 ];then
|
;;
|
||||||
echo -e "\033[31m最多支持设置放行15个端口,请先减少一些!\033[0m"
|
2)
|
||||||
else
|
port_count=$(echo "$multiport" | awk -F',' '{print NF}')
|
||||||
read -p "请输入要放行的端口号 > " port
|
if [ "$port_count" -ge 15 ]; then
|
||||||
if echo ",$multiport," | grep -q ",$port,";then
|
echo -e "\033[31m最多支持设置放行15个端口,请先减少一些!\033[0m"
|
||||||
echo -e "\033[31m输入错误!请勿重复添加!\033[0m"
|
else
|
||||||
elif [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
read -r -p "请输入要放行的端口号 > " port
|
||||||
echo -e "\033[31m输入错误!请输入正确的数值(1-65535)!\033[0m"
|
if echo ",$multiport," | grep -q ",$port,"; then
|
||||||
else
|
echo -e "\033[31m输入错误!请勿重复添加!\033[0m"
|
||||||
multiport=$(echo "$multiport,$port" | sed "s/^,//")
|
elif [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
||||||
setconfig multiport "$multiport"
|
echo -e "\033[31m输入错误!请输入正确的数值(1-65535)!\033[0m"
|
||||||
fi
|
else
|
||||||
fi
|
multiport=$(echo "$multiport,$port" | sed "s/^,//")
|
||||||
sleep 1
|
setconfig multiport "$multiport"
|
||||||
set_common_ports
|
fi
|
||||||
;;
|
fi
|
||||||
3)
|
sleep 1
|
||||||
read -p "请输入要移除的端口号 > " port
|
;;
|
||||||
if echo ",$multiport," | grep -q ",$port,";then
|
3)
|
||||||
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
read -r -p "请输入要移除的端口号 > " port
|
||||||
echo -e "\033[31m输入错误!请输入正确的数值(1-65535)!\033[0m"
|
if echo ",$multiport," | grep -q ",$port,"; then
|
||||||
else
|
if [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
||||||
multiport=$(echo ",$multiport," | sed "s/,$port//; s/^,//; s/,$//")
|
echo -e "\033[31m输入错误!请输入正确的数值(1-65535)!\033[0m"
|
||||||
setconfig multiport "$multiport"
|
else
|
||||||
fi
|
multiport=$(echo ",$multiport," | sed "s/,$port//; s/^,//; s/,$//")
|
||||||
else
|
setconfig multiport "$multiport"
|
||||||
echo -e "\033[31m输入错误!请输入已添加过的端口!\033[0m"
|
fi
|
||||||
fi
|
else
|
||||||
sleep 1
|
echo -e "\033[31m输入错误!请输入已添加过的端口!\033[0m"
|
||||||
set_common_ports
|
fi
|
||||||
;;
|
sleep 1
|
||||||
4)
|
;;
|
||||||
multiport=''
|
4)
|
||||||
setconfig multiport
|
multiport=''
|
||||||
sleep 1
|
setconfig multiport
|
||||||
set_common_ports
|
sleep 1
|
||||||
;;
|
;;
|
||||||
5)
|
5)
|
||||||
multiport='22,80,143,194,443,465,587,853,993,995,5222,8080,8443'
|
multiport='22,80,143,194,443,465,587,853,993,995,5222,8080,8443'
|
||||||
setconfig multiport "$multiport"
|
setconfig multiport "$multiport"
|
||||||
sleep 1
|
sleep 1
|
||||||
set_common_ports
|
;;
|
||||||
;;
|
*)
|
||||||
*)
|
errornum
|
||||||
errornum
|
sleep 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
set_cust_host_ipv4() { #自定义ipv4透明路由网段
|
set_cust_host_ipv4() { #自定义ipv4透明路由网段
|
||||||
[ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user