Skip to content

Commit a8aa1f8

Browse files
authored
fix: Fixed the fault in determining the firewall port forwarding version (#7141)
1 parent 2ba17d8 commit a8aa1f8

File tree

6 files changed

+4
-29
lines changed

6 files changed

+4
-29
lines changed

backend/app/service/firewall.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/1Panel-dev/1Panel/backend/app/dto"
1212
"github.com/1Panel-dev/1Panel/backend/app/model"
13-
"github.com/1Panel-dev/1Panel/backend/buserr"
1413
"github.com/1Panel-dev/1Panel/backend/constant"
1514
"github.com/1Panel-dev/1Panel/backend/global"
1615
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
@@ -87,11 +86,6 @@ func (u *FirewallService) SearchWithPage(req dto.RuleSearch) (int64, interface{}
8786
case "port":
8887
rules, err = client.ListPort()
8988
case "forward":
90-
isSupport, errSup := checkIsSupport()
91-
if !isSupport {
92-
return 0, nil, errSup
93-
}
94-
9589
rules, err = client.ListForward()
9690
case "address":
9791
rules, err = client.ListAddress()
@@ -312,11 +306,6 @@ func (u *FirewallService) OperatePortRule(req dto.PortRuleOperate, reload bool)
312306
}
313307

314308
func (u *FirewallService) OperateForwardRule(req dto.ForwardRuleOperate) error {
315-
isSupport, errSup := checkIsSupport()
316-
if !isSupport {
317-
return errSup
318-
}
319-
320309
client, err := firewall.NewFirewallClient()
321310
if err != nil {
322311
return err
@@ -737,14 +726,3 @@ func checkPortUsed(ports, proto string, apps []portOfApp) string {
737726
}
738727
return ""
739728
}
740-
741-
func checkIsSupport() (bool, error) {
742-
std, err := cmd.Exec("iptables --version")
743-
if err != nil {
744-
return false, fmt.Errorf("handle iptables --version failed, stdout: %s, err: %v", std, err)
745-
}
746-
if strings.Contains(std, "nf_tables") {
747-
return false, buserr.New(constant.ErrNFTables)
748-
}
749-
return true, nil
750-
}

backend/constant/errs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ var (
148148
var (
149149
ErrFirewallNone = "ErrFirewallNone"
150150
ErrFirewallBoth = "ErrFirewallBoth"
151-
ErrNFTables = "ErrNFTables"
152151
)
153152

154153
// cronjob

backend/i18n/lang/en.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}"
169169
#ssh
170170
ErrFirewallNone: "No firewalld or ufw service detected on the system. Please check and try again!"
171171
ErrFirewallBoth: "Both firewalld and ufw services are detected on the system. To avoid conflicts, please uninstall one and try again!"
172-
ErrNFTables: "Port forwarding functionality relies on the iptables service and is currently not compatible with nftables operations!"
173172

174173
#cronjob
175174
ErrBashExecute: "Script execution error, please check the specific information in the task output text area."

backend/i18n/lang/zh-Hant.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}"
169169
#ssh
170170
ErrFirewallNone: "未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"
171171
ErrFirewallBoth: "檢測到系統同時存在 firewalld 或 ufw 服務,為避免衝突,請卸載後重試!"
172-
ErrNFTables: "端口轉發功能依賴於 iptables 服務,暫不兼容 nftables 操作!"
173172

174173
#cronjob
175174
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。"

backend/i18n/lang/zh.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ ErrUserFindErr: "用户 {{ .name }} 查找失败 {{ .err }}"
172172
#ssh
173173
ErrFirewallNone: "未检测到系统 firewalld 或 ufw 服务,请检查后重试!"
174174
ErrFirewallBoth: "检测到系统同时存在 firewalld 或 ufw 服务,为避免冲突,请卸载后重试!"
175-
ErrNFTables: "端口转发功能依赖于 iptables 服务,暂不兼容 nftables 操作!"
176175

177176
#cronjob
178177
ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。"

backend/utils/firewall/client/iptables.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package client
22

33
import (
44
"fmt"
5+
"regexp"
6+
"strings"
7+
58
"github.com/1Panel-dev/1Panel/backend/app/model"
69
"github.com/1Panel-dev/1Panel/backend/global"
710
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
8-
"regexp"
9-
"strings"
1011
)
1112

1213
const NatChain = "1PANEL"
@@ -51,7 +52,7 @@ func (iptables *Iptables) Check() error {
5152
}
5253

5354
func (iptables *Iptables) NatNewChain() error {
54-
return iptables.runf("-N %s", NatChain)
55+
return iptables.runf("-t nat -N %s", NatChain)
5556
}
5657

5758
func (iptables *Iptables) NatAppendChain() error {

0 commit comments

Comments
 (0)