From 175b7b89e49db78c3d23eb92bc513a62f5f472a9 Mon Sep 17 00:00:00 2001 From: zzz <41989224+zengzhuozhen@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:03:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:firewalld=E5=92=8Cufw=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6,=E4=B8=8D=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=20(#6688)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zengzz01 --- backend/utils/firewall/client.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/utils/firewall/client.go b/backend/utils/firewall/client.go index de88fca35..3eb5ad537 100644 --- a/backend/utils/firewall/client.go +++ b/backend/utils/firewall/client.go @@ -29,10 +29,17 @@ type FirewallClient interface { } func NewFirewallClient() (FirewallClient, error) { - if _, err := os.Stat("/usr/sbin/firewalld"); err == nil { + _, firewalldErr := os.Stat("/usr/sbin/firewalld") + _, ufwErr := os.Stat("/usr/sbin/ufw") + + if firewalldErr == nil && ufwErr == nil { + return nil, buserr.New("firewalld and ufw both found, only one firewall should be active") + } + + if firewalldErr == nil { return client.NewFirewalld() } - if _, err := os.Stat("/usr/sbin/ufw"); err == nil { + if ufwErr == nil { return client.NewUfw() } return nil, buserr.New(constant.ErrFirewall)