1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

feat: 应用更新端口之后放开相应防火墙端口 (#563)

This commit is contained in:
zhengkunwang223 2023-04-10 16:26:22 +08:00 committed by GitHub
parent 1bba2664b6
commit cca1406f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -221,27 +221,35 @@ func (a *AppInstallService) Update(req request.AppInstalledUpdate) error {
return err
}
changePort := false
var (
oldPorts []int
newPorts []int
)
port, ok := req.Params["PANEL_APP_PORT_HTTP"]
if ok {
portN := int(math.Ceil(port.(float64)))
if portN != installed.HttpPort {
oldPorts = append(oldPorts, installed.HttpPort)
changePort = true
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", req.Params)
if err != nil {
return err
}
installed.HttpPort = httpPort
newPorts = append(newPorts, httpPort)
}
}
ports, ok := req.Params["PANEL_APP_PORT_HTTPS"]
if ok {
portN := int(math.Ceil(ports.(float64)))
if portN != installed.HttpsPort {
oldPorts = append(oldPorts, installed.HttpsPort)
httpsPort, err := checkPort("PANEL_APP_PORT_HTTPS", req.Params)
if err != nil {
return err
}
installed.HttpsPort = httpsPort
newPorts = append(newPorts, httpsPort)
}
}
@ -286,6 +294,11 @@ func (a *AppInstallService) Update(req request.AppInstalledUpdate) error {
return buserr.WithErr(constant.ErrUpdateBuWebsite, err)
}
}
if changePort {
go func() {
_ = OperateFirewallPort(oldPorts, newPorts)
}()
}
return nil
}