1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 00:09:16 +08:00

fix: Fix the issue of failure to retrieve firewall status (#7597)

Refs #7527
This commit is contained in:
ssongliu 2024-12-30 13:37:49 +08:00 committed by GitHub
parent 6dbb6d2247
commit 7c46f54e15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 8 deletions

View File

@ -25,7 +25,7 @@ func (f *Firewall) Name() string {
} }
func (f *Firewall) Status() (string, error) { 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" { if stdout == "running\n" {
return "running", nil return "running", nil
} }
@ -33,7 +33,7 @@ func (f *Firewall) Status() (string, error) {
} }
func (f *Firewall) Version() (string, error) { 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 { if err != nil {
return "", fmt.Errorf("load the firewall version failed, err: %s", stdout) return "", fmt.Errorf("load the firewall version failed, err: %s", stdout)
} }

View File

@ -17,9 +17,9 @@ type Ufw struct {
func NewUfw() (*Ufw, error) { func NewUfw() (*Ufw, error) {
var ufw Ufw var ufw Ufw
if cmd.HasNoPasswordSudo() { if cmd.HasNoPasswordSudo() {
ufw.CmdStr = "sudo ufw" ufw.CmdStr = "LANGUAGE=en_US:en sudo ufw"
} else { } else {
ufw.CmdStr = "ufw" ufw.CmdStr = "LANGUAGE=en_US:en ufw"
} }
return &ufw, nil return &ufw, nil
} }
@ -33,10 +33,6 @@ func (f *Ufw) Status() (string, error) {
if stdout == "Status: active\n" { if stdout == "Status: active\n" {
return "running", nil return "running", nil
} }
stdout1, _ := cmd.Execf("%s status | grep 状态", f.CmdStr)
if stdout1 == "状态: 激活\n" {
return "running", nil
}
return "not running", nil return "not running", nil
} }