diff --git a/cmd/server/cmd/update.go b/cmd/server/cmd/update.go index 706862cc51eb..d84f27a0909d 100644 --- a/cmd/server/cmd/update.go +++ b/cmd/server/cmd/update.go @@ -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" ) @@ -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