修复端口重复检查逻辑,保持函数职责单一

- check_port 函数只负责检查端口范围和占用,移除重复检查逻辑
- 端口重复检查移到 inputport 函数中,只排除当前编辑的端口变量
- 修复编辑端口时错误地跳过所有已配置端口重复检查的 bug
This commit is contained in:
Feng Yu
2026-03-22 23:52:43 +08:00
parent 7ed66026be
commit c61c637e0d
2 changed files with 17 additions and 18 deletions

View File

@@ -393,14 +393,26 @@ inputport() {
line_break line_break
read -r -p "$INPUT_PORT165535> " portx read -r -p "$INPUT_PORT165535> " portx
. "$CRASHDIR"/menus/check_port.sh . "$CRASHDIR"/menus/check_port.sh
if check_port "$portx" "$protocol"; then
setconfig "$xport" "$portx" if ! check_port "$portx" "$protocol"; then
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
return 0
else
msg_alert "\033[31m$COMMON_FAILED\033[0m" msg_alert "\033[31m$COMMON_FAILED\033[0m"
return 1 return 1
fi fi
local ports_to_check=""
[ "$xport" != "mix_port" ] && ports_to_check="$ports_to_check|$mix_port"
[ "$xport" != "redir_port" ] && ports_to_check="$ports_to_check|$redir_port"
[ "$xport" != "dns_port" ] && ports_to_check="$ports_to_check|$dns_port"
[ "$xport" != "db_port" ] && ports_to_check="$ports_to_check|$db_port"
if echo "$ports_to_check|" | grep -q "|$portx|"; then
msg_alert "\033[31m$CHECK_PORT_DUP_ERR\033[0m"
return 1
fi
setconfig "$xport" "$portx"
msg_alert "\033[32m$COMMON_SUCCESS\033[0m"
return 0
} }
# 端口设置 # 端口设置

View File

@@ -20,19 +20,6 @@ check_port() {
return 1 return 1
fi fi
local current_port_name=""
case "$port" in
"$mix_port") current_port_name="mix_port" ;;
"$redir_port") current_port_name="redir_port" ;;
"$dns_port") current_port_name="dns_port" ;;
"$db_port") current_port_name="db_port" ;;
esac
if [ -z "$current_port_name" ] && echo "|$mix_port|$redir_port|$dns_port|$db_port|" | grep -q "|$port|"; then
msg_alert "\033[31m$CHECK_PORT_DUP_ERR\033[0m"
return 1
fi
local check_cmd local check_cmd
check_cmd=$(_get_netstat_cmd "$protocol") check_cmd=$(_get_netstat_cmd "$protocol")