Files
EdgeAdmin/internal/web/actions/default/servers/server/settings/https/index.go

94 lines
2.0 KiB
Go
Raw Normal View History

2020-08-21 21:09:42 +08:00
package https
import (
2020-09-16 09:09:10 +08:00
"encoding/json"
2020-08-21 21:09:42 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-09-16 09:09:10 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
2020-08-21 21:09:42 +08:00
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "index")
this.SecondMenu("https")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
2020-09-21 19:51:50 +08:00
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
2020-09-16 09:09:10 +08:00
if !isOk {
return
}
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
if len(server.HttpsJSON) > 0 {
err := json.Unmarshal(server.HttpsJSON, httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
} else {
httpsConfig.IsOn = true
}
this.Data["serverType"] = server.Type
this.Data["httpsConfig"] = maps.Map{
"isOn": httpsConfig.IsOn,
"addresses": httpsConfig.Listen,
}
2020-08-21 21:09:42 +08:00
this.Show()
}
2020-09-16 09:09:10 +08:00
func (this *IndexAction) RunPost(params struct {
ServerId int64
2020-09-28 16:25:26 +08:00
IsOn bool
2020-09-16 09:09:10 +08:00
Addresses string
Must *actions.Must
}) {
addresses := []*serverconfigs.NetworkAddressConfig{}
err := json.Unmarshal([]byte(params.Addresses), &addresses)
if err != nil {
this.Fail("端口地址解析失败:" + err.Error())
}
2020-09-21 19:51:50 +08:00
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
2020-09-16 09:09:10 +08:00
if !isOk {
return
}
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
if len(server.HttpsJSON) > 0 {
err = json.Unmarshal(server.HttpsJSON, httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
}
2020-09-28 16:25:26 +08:00
httpsConfig.IsOn = params.IsOn
2020-09-16 09:09:10 +08:00
httpsConfig.Listen = addresses
configData, err := json.Marshal(httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerHTTPS(this.AdminContext(), &pb.UpdateServerHTTPSRequest{
ServerId: params.ServerId,
Config: configData,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}