From 5ce1b1591a4b9d52d1e1b3d58128fef3b49cdb3f Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 14 Apr 2023 17:14:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=98=B2=E7=81=AB=E5=A2=99=E7=A6=81=20p?= =?UTF-8?q?ing=20=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=96=87=E4=BB=B6=E5=88=99?= =?UTF-8?q?=E9=9A=90=E8=97=8F=20(#643)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/firewall.go | 20 ++++++++++--------- backend/constant/status.go | 1 + .../src/views/host/firewall/status/index.vue | 20 ++++++++++--------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/backend/app/service/firewall.go b/backend/app/service/firewall.go index 6a8a2cbbf..74ea476b6 100644 --- a/backend/app/service/firewall.go +++ b/backend/app/service/firewall.go @@ -36,10 +36,14 @@ func NewIFirewallService() IFirewallService { func (u *FirewallService) LoadBaseInfo() (dto.FirewallBaseInfo, error) { var baseInfo dto.FirewallBaseInfo + baseInfo.PingStatus = u.pingStatus() + baseInfo.Status = "not running" + baseInfo.Version = "-" + baseInfo.Name = "-" client, err := firewall.NewFirewallClient() if err != nil { if err.Error() == "no such type" { - return dto.FirewallBaseInfo{Name: "-", Version: "-", Status: "not running", PingStatus: "Disable"}, nil + return baseInfo, nil } return baseInfo, err } @@ -48,12 +52,7 @@ func (u *FirewallService) LoadBaseInfo() (dto.FirewallBaseInfo, error) { if err != nil { return baseInfo, err } - baseInfo.PingStatus, err = u.pingStatus() - if err != nil { - return baseInfo, err - } if baseInfo.Status == "not running" { - baseInfo.Version = "-" return baseInfo, err } baseInfo.Version, err = client.Version() @@ -365,12 +364,15 @@ func (u *FirewallService) loadPortByApp() []portOfApp { return datas } -func (u *FirewallService) pingStatus() (string, error) { +func (u *FirewallService) pingStatus() string { + if _, err := os.Stat("/etc/sysctl.conf"); err != nil { + return constant.StatusNone + } stdout, _ := cmd.Exec("sudo cat /etc/sysctl.conf | grep net/ipv4/icmp_echo_ignore_all= ") if stdout == "net/ipv4/icmp_echo_ignore_all=1\n" { - return constant.StatusEnable, nil + return constant.StatusEnable } - return constant.StatusDisable, nil + return constant.StatusDisable } func (u *FirewallService) updatePingStatus(enabel string) error { diff --git a/backend/constant/status.go b/backend/constant/status.go index 864be16c3..a7bdab663 100644 --- a/backend/constant/status.go +++ b/backend/constant/status.go @@ -9,4 +9,5 @@ const ( StatusUploading = "Uploading" StatusEnable = "Enable" StatusDisable = "Disable" + StatusNone = "None" ) diff --git a/frontend/src/views/host/firewall/status/index.vue b/frontend/src/views/host/firewall/status/index.vue index 8b24eb659..4e47a0bea 100644 --- a/frontend/src/views/host/firewall/status/index.vue +++ b/frontend/src/views/host/firewall/status/index.vue @@ -22,15 +22,17 @@ {{ $t('commons.button.start') }} - - {{ $t('firewall.noPing') }} - + + + {{ $t('firewall.noPing') }} + +