From 302d0f1becec82ec99d40df64d88cefc3ca888b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 26 Oct 2024 01:23:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=98=B2=E7=81=AB=E5=A2=99=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E7=8A=B6=E6=80=81=E4=B8=8Bping=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/safe.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/data/safe.go b/internal/data/safe.go index c2953aca..ccbff0ac 100644 --- a/internal/data/safe.go +++ b/internal/data/safe.go @@ -1,7 +1,8 @@ package data import ( - "errors" + "fmt" + "github.com/TheTNB/panel/pkg/firewall" "strings" "github.com/spf13/cast" @@ -61,8 +62,8 @@ func (r *safeRepo) UpdateSSH(port uint, status bool) error { func (r *safeRepo) GetPingStatus() (bool, error) { out, err := shell.Execf(`firewall-cmd --list-rich-rules`) - if err != nil { - return true, errors.New(out) + if err != nil { // 可能防火墙已关闭等 + return true, nil } if !strings.Contains(out, `rule protocol value="icmp" drop`) { @@ -73,7 +74,14 @@ func (r *safeRepo) GetPingStatus() (bool, error) { } func (r *safeRepo) UpdatePingStatus(status bool) error { - var err error + fw, err := firewall.NewFirewall().Status() + if err != nil { + return err + } + if !fw { + return fmt.Errorf("failed to update ping status: firewalld is not running") + } + if status { _, err = shell.Execf(`firewall-cmd --permanent --remove-rich-rule='rule protocol value=icmp drop'`) } else {