Skip to content

Commit

Permalink
fix: Fix the issue of failure to retrieve firewall status (#7597)
Browse files Browse the repository at this point in the history
Refs #7527
  • Loading branch information
ssongliu authored Dec 30, 2024
1 parent 6dbb6d2 commit 7c46f54
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions backend/utils/firewall/client/firewalld.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func (f *Firewall) Name() string {
}

func (f *Firewall) Status() (string, error) {
stdout, _ := cmd.Exec("firewall-cmd --state")
stdout, _ := cmd.Exec("LANGUAGE=en_US:en firewall-cmd --state")
if stdout == "running\n" {
return "running", nil
}
return "not running", nil
}

func (f *Firewall) Version() (string, error) {
stdout, err := cmd.Exec("firewall-cmd --version")
stdout, err := cmd.Exec("LANGUAGE=en_US:en firewall-cmd --version")
if err != nil {
return "", fmt.Errorf("load the firewall version failed, err: %s", stdout)
}
Expand Down
8 changes: 2 additions & 6 deletions backend/utils/firewall/client/ufw.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type Ufw struct {
func NewUfw() (*Ufw, error) {
var ufw Ufw
if cmd.HasNoPasswordSudo() {
ufw.CmdStr = "sudo ufw"
ufw.CmdStr = "LANGUAGE=en_US:en sudo ufw"
} else {
ufw.CmdStr = "ufw"
ufw.CmdStr = "LANGUAGE=en_US:en ufw"
}
return &ufw, nil
}
Expand All @@ -33,10 +33,6 @@ func (f *Ufw) Status() (string, error) {
if stdout == "Status: active\n" {
return "running", nil
}
stdout1, _ := cmd.Execf("%s status | grep 状态", f.CmdStr)
if stdout1 == "状态: 激活\n" {
return "running", nil
}
return "not running", nil
}

Expand Down

0 comments on commit 7c46f54

Please sign in to comment.