From 8d1322af37c74fd0219ad3a95aabd2c535f5c386 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:49:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99=20(#5711?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/firewall.go | 15 +++++++++++++++ .../views/host/firewall/forward/operate/index.vue | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/app/service/firewall.go b/backend/app/service/firewall.go index cef2fab59..b5a45860a 100644 --- a/backend/app/service/firewall.go +++ b/backend/app/service/firewall.go @@ -306,6 +306,21 @@ func (u *FirewallService) OperateForwardRule(req dto.ForwardRuleOperate) error { return err } + rules, _ := client.ListForward() + for _, rule := range rules { + for _, reqRule := range req.Rules { + if reqRule.Operation == "remove" { + continue + } + if reqRule.TargetIP == "" { + reqRule.TargetIP = "127.0.0.1" + } + if reqRule.Port == rule.Port && reqRule.TargetPort == rule.TargetPort && reqRule.TargetIP == rule.TargetIP { + return constant.ErrRecordExist + } + } + } + sort.SliceStable(req.Rules, func(i, j int) bool { n1, _ := strconv.Atoi(req.Rules[i].Num) n2, _ := strconv.Atoi(req.Rules[j].Num) diff --git a/frontend/src/views/host/firewall/forward/operate/index.vue b/frontend/src/views/host/firewall/forward/operate/index.vue index 6f2fe21c6..8da6e289c 100644 --- a/frontend/src/views/host/firewall/forward/operate/index.vue +++ b/frontend/src/views/host/firewall/forward/operate/index.vue @@ -58,7 +58,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; import { MsgSuccess } from '@/utils/message'; import { Host } from '@/api/interface/host'; import { operateForwardRule } from '@/api/modules/host'; -import { checkCidr, checkIpV4V6, checkPort, deepCopy } from '@/utils/util'; +import { checkCidr, checkIp, checkPort, deepCopy } from '@/utils/util'; const loading = ref(); const oldRule = ref(); @@ -89,14 +89,14 @@ const handleClose = () => { const rules = reactive({ protocol: [Rules.requiredSelect], - port: [{ validator: checkPortRule, trigger: 'blur' }], - targetPort: [{ validator: checkPortRule, trigger: 'blur' }], + port: [{ validator: checkPortRule, trigger: 'blur', required: true }], + targetPort: [{ validator: checkPortRule, trigger: 'blur', required: true }], targetIP: [{ validator: checkAddress, trigger: 'blur' }], }); function checkPortRule(rule: any, value: string, callback: any) { if (!value) { - return callback(); + return callback(new Error(i18n.global.t('firewall.portFormatError'))); } if (checkPort(value)) { return callback(new Error(i18n.global.t('firewall.portFormatError'))); @@ -114,7 +114,7 @@ function checkAddress(rule: any, value: string, callback: any) { return callback(new Error(i18n.global.t('firewall.addressFormatError'))); } } else { - if (checkIpV4V6(item)) { + if (checkIp(item)) { return callback(new Error(i18n.global.t('firewall.addressFormatError'))); } }