From 9a38dcd2a76a5769968ecdc9fb332b75dc506763 Mon Sep 17 00:00:00 2001
From: ssongliu <73214554+ssongliu@users.noreply.github.com>
Date: Thu, 4 Jul 2024 16:04:33 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=98=B2=E7=81=AB?=
=?UTF-8?q?=E5=A2=99=E7=AD=9B=E9=80=89=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98=20(#5677)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app/service/firewall.go | 5 ++++-
backend/utils/firewall/client/firewalld.go | 6 ++++++
backend/utils/firewall/client/ufw.go | 8 +++++++-
frontend/src/views/host/firewall/forward/index.vue | 7 +------
4 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/backend/app/service/firewall.go b/backend/app/service/firewall.go
index fe6f948c5..cef2fab59 100644
--- a/backend/app/service/firewall.go
+++ b/backend/app/service/firewall.go
@@ -96,7 +96,10 @@ func (u *FirewallService) SearchWithPage(req dto.RuleSearch) (int64, interface{}
if len(req.Info) != 0 {
for _, addr := range rules {
- if strings.Contains(addr.Address, req.Info) {
+ if strings.Contains(addr.Address, req.Info) ||
+ strings.Contains(addr.Port, req.Info) ||
+ strings.Contains(addr.TargetPort, req.Info) ||
+ strings.Contains(addr.TargetIP, req.Info) {
datas = append(datas, addr)
}
}
diff --git a/backend/utils/firewall/client/firewalld.go b/backend/utils/firewall/client/firewalld.go
index 84fa4e016..61e084c51 100644
--- a/backend/utils/firewall/client/firewalld.go
+++ b/backend/utils/firewall/client/firewalld.go
@@ -129,6 +129,12 @@ func (f *Firewall) ListForward() ([]FireInfo, error) {
})
if ForwardListRegex.MatchString(line) {
match := ForwardListRegex.FindStringSubmatch(line)
+ if len(match) < 4 {
+ continue
+ }
+ if len(match[4]) == 0 {
+ match[4] = "127.0.0.1"
+ }
datas = append(datas, FireInfo{
Port: match[1],
Protocol: match[2],
diff --git a/backend/utils/firewall/client/ufw.go b/backend/utils/firewall/client/ufw.go
index 86e3f4554..678a9afa0 100644
--- a/backend/utils/firewall/client/ufw.go
+++ b/backend/utils/firewall/client/ufw.go
@@ -115,7 +115,13 @@ func (f *Ufw) ListForward() ([]FireInfo, error) {
var list []FireInfo
for _, rule := range rules {
- dest := strings.SplitN(rule.DestPort, ":", 2)
+ dest := strings.Split(rule.DestPort, ":")
+ if len(dest) < 2 {
+ continue
+ }
+ if len(dest[0]) == 0 {
+ dest[0] = "127.0.0.1"
+ }
list = append(list, FireInfo{
Num: rule.Num,
Protocol: rule.Protocol,
diff --git a/frontend/src/views/host/firewall/forward/index.vue b/frontend/src/views/host/firewall/forward/index.vue
index 69b1443e0..9bde10fba 100644
--- a/frontend/src/views/host/firewall/forward/index.vue
+++ b/frontend/src/views/host/firewall/forward/index.vue
@@ -44,12 +44,7 @@
-
-
- {{ row.targetIP }}
- 127.0.0.1
-
-
+