Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 解决更新端口不更新防火墙规则的问题 #7169

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/server/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
"github.com/1Panel-dev/1Panel/backend/utils/firewall"
fireClient "github.com/1Panel-dev/1Panel/backend/utils/firewall/client"
"github.com/spf13/cobra"
"golang.org/x/term"
)
Expand Down Expand Up @@ -187,6 +189,23 @@ func port() {
fmt.Printf("错误:初始化数据库连接失败,%v\n", err)
return
}

if client, err := firewall.NewFirewallClient(); err == nil {
if err := client.Port(fireClient.FireInfo{Port: newPortStr, Protocol: "tcp", Strategy: "accept"}, "add"); err != nil {
fmt.Printf("错误:防火墙端口添加失败,%v\n", err)
return
}
oldPortStr := getSettingByKey(db, "ServerPort")
if err := client.Port(fireClient.FireInfo{Port: oldPortStr, Protocol: "tcp", Strategy: "accept"}, "remove"); err != nil {
fmt.Printf("错误:防火墙端口删除失败,%v\n", err)
return
}
if err := client.Reload(); err != nil {
fmt.Printf("错误:防火墙重载失败,%v\n", err)
return
}
}

if err := setSettingByKey(db, "ServerPort", newPortStr); err != nil {
fmt.Printf("错误:面板端口修改失败,%v\n", err)
return
Expand Down
Loading