fix: Fixed the fault in determining the firewall port forwarding version

This commit is contained in:
ssongliu 2024-11-21 14:48:46 +08:00
parent aaae8a5d3b
commit 773cf96bb7
6 changed files with 4 additions and 29 deletions

View File

@ -10,7 +10,6 @@ import (
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/cmd"
@ -87,11 +86,6 @@ func (u *FirewallService) SearchWithPage(req dto.RuleSearch) (int64, interface{}
case "port": case "port":
rules, err = client.ListPort() rules, err = client.ListPort()
case "forward": case "forward":
isSupport, errSup := checkIsSupport()
if !isSupport {
return 0, nil, errSup
}
rules, err = client.ListForward() rules, err = client.ListForward()
case "address": case "address":
rules, err = client.ListAddress() rules, err = client.ListAddress()
@ -312,11 +306,6 @@ func (u *FirewallService) OperatePortRule(req dto.PortRuleOperate, reload bool)
} }
func (u *FirewallService) OperateForwardRule(req dto.ForwardRuleOperate) error { func (u *FirewallService) OperateForwardRule(req dto.ForwardRuleOperate) error {
isSupport, errSup := checkIsSupport()
if !isSupport {
return errSup
}
client, err := firewall.NewFirewallClient() client, err := firewall.NewFirewallClient()
if err != nil { if err != nil {
return err return err
@ -737,14 +726,3 @@ func checkPortUsed(ports, proto string, apps []portOfApp) string {
} }
return "" return ""
} }
func checkIsSupport() (bool, error) {
std, err := cmd.Exec("iptables --version")
if err != nil {
return false, fmt.Errorf("handle iptables --version failed, stdout: %s, err: %v", std, err)
}
if strings.Contains(std, "nf_tables") {
return false, buserr.New(constant.ErrNFTables)
}
return true, nil
}

View File

@ -148,7 +148,6 @@ var (
var ( var (
ErrFirewallNone = "ErrFirewallNone" ErrFirewallNone = "ErrFirewallNone"
ErrFirewallBoth = "ErrFirewallBoth" ErrFirewallBoth = "ErrFirewallBoth"
ErrNFTables = "ErrNFTables"
) )
// cronjob // cronjob

View File

@ -169,7 +169,6 @@ ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}"
#ssh #ssh
ErrFirewallNone: "No firewalld or ufw service detected on the system. Please check and try again!" ErrFirewallNone: "No firewalld or ufw service detected on the system. Please check and try again!"
ErrFirewallBoth: "Both firewalld and ufw services are detected on the system. To avoid conflicts, please uninstall one and try again!" ErrFirewallBoth: "Both firewalld and ufw services are detected on the system. To avoid conflicts, please uninstall one and try again!"
ErrNFTables: "Port forwarding functionality relies on the iptables service and is currently not compatible with nftables operations!"
#cronjob #cronjob
ErrBashExecute: "Script execution error, please check the specific information in the task output text area." ErrBashExecute: "Script execution error, please check the specific information in the task output text area."

View File

@ -169,7 +169,6 @@ ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}"
#ssh #ssh
ErrFirewallNone: "未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!" ErrFirewallNone: "未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"
ErrFirewallBoth: "檢測到系統同時存在 firewalld 或 ufw 服務,為避免衝突,請卸載後重試!" ErrFirewallBoth: "檢測到系統同時存在 firewalld 或 ufw 服務,為避免衝突,請卸載後重試!"
ErrNFTables: "端口轉發功能依賴於 iptables 服務,暫不兼容 nftables 操作!"
#cronjob #cronjob
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。" ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。"

View File

@ -172,7 +172,6 @@ ErrUserFindErr: "用户 {{ .name }} 查找失败 {{ .err }}"
#ssh #ssh
ErrFirewallNone: "未检测到系统 firewalld 或 ufw 服务,请检查后重试!" ErrFirewallNone: "未检测到系统 firewalld 或 ufw 服务,请检查后重试!"
ErrFirewallBoth: "检测到系统同时存在 firewalld 或 ufw 服务,为避免冲突,请卸载后重试!" ErrFirewallBoth: "检测到系统同时存在 firewalld 或 ufw 服务,为避免冲突,请卸载后重试!"
ErrNFTables: "端口转发功能依赖于 iptables 服务,暂不兼容 nftables 操作!"
#cronjob #cronjob
ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。" ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。"

View File

@ -2,11 +2,12 @@ package client
import ( import (
"fmt" "fmt"
"regexp"
"strings"
"github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/cmd"
"regexp"
"strings"
) )
const NatChain = "1PANEL" const NatChain = "1PANEL"
@ -51,7 +52,7 @@ func (iptables *Iptables) Check() error {
} }
func (iptables *Iptables) NatNewChain() error { func (iptables *Iptables) NatNewChain() error {
return iptables.runf("-N %s", NatChain) return iptables.runf("-t nat -N %s", NatChain)
} }
func (iptables *Iptables) NatAppendChain() error { func (iptables *Iptables) NatAppendChain() error {