From 7dc0a2f664de97f25129194b74ea95765fdbf151 Mon Sep 17 00:00:00 2001 From: igophper <34326532+igophper@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:12:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E4=B8=8D=E6=9B=B4=E6=96=B0=E9=98=B2=E7=81=AB?= =?UTF-8?q?=E5=A2=99=E8=A7=84=E5=88=99=E7=9A=84=E9=97=AE=E9=A2=98=20(#7169?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/cmd/update.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/server/cmd/update.go b/cmd/server/cmd/update.go index 706862cc5..7ac8e2b7e 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,7 @@ func port() { fmt.Printf("错误:初始化数据库连接失败,%v\n", err) return } + oldPortStr := getSettingByKey(db, "ServerPort") if err := setSettingByKey(db, "ServerPort", newPortStr); err != nil { fmt.Printf("错误:面板端口修改失败,%v\n", err) return @@ -195,6 +198,18 @@ func port() { fmt.Printf("修改成功!\n\n") fmt.Printf("面板端口:%s\n", newPortStr) + 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,请您手动将 %s 端口添加至防火墙规则中。\n", newPortStr, err) + } + if err := client.Port(fireClient.FireInfo{Port: oldPortStr, Protocol: "tcp", Strategy: "accept"}, "remove"); err != nil { + fmt.Printf("错误:防火墙端口删除失败,%v\n", err) + } + if err := client.Reload(); err != nil { + fmt.Printf("防火墙重载失败,%v,请您手动重载防火墙。\n", err) + } + } + std, err := cmd.Exec("1pctl restart") if err != nil { fmt.Println(std)