Skip to content

Commit

Permalink
fix: Fixed the fault in determining the firewall port forwarding vers…
Browse files Browse the repository at this point in the history
…ion (#7150)
  • Loading branch information
ssongliu authored Nov 22, 2024
1 parent ce30a7d commit 7fdb0a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/utils/firewall/client/firewalld.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
)

Expand Down Expand Up @@ -118,6 +119,9 @@ func (f *Firewall) ListPort() ([]FireInfo, error) {
}

func (f *Firewall) ListForward() ([]FireInfo, error) {
if err := f.EnableForward(); err != nil {
global.LOG.Errorf("init port forward failed, err: %v", err)
}
stdout, err := cmd.Exec("firewall-cmd --zone=public --list-forward-ports")
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/firewall/client/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (iptables *Iptables) Check() error {
}

func (iptables *Iptables) NatNewChain() error {
return iptables.runf("-t nat -N %s", NatChain)
return iptables.runf("-N %s", NatChain)
}

func (iptables *Iptables) NatAppendChain() error {
Expand Down
7 changes: 7 additions & 0 deletions backend/utils/firewall/client/ufw.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
)

Expand Down Expand Up @@ -108,6 +109,12 @@ func (f *Ufw) ListForward() ([]FireInfo, error) {
if err != nil {
return nil, err
}
panelChian, _ := cmd.Execf("%s iptables -t nat -L -n | grep 'Chain 1PANEL'", iptables.CmdStr)
if len(strings.ReplaceAll(panelChian, "\n", "")) == 0 {
if err := f.EnableForward(); err != nil {
global.LOG.Errorf("init port forward failed, err: %v", err)
}
}
rules, err := iptables.NatList()
if err != nil {
return nil, err
Expand Down

0 comments on commit 7fdb0a5

Please sign in to comment.