2020-09-16 09:09:10 +08:00
|
|
|
package tls
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TLS设置
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "setting", "index")
|
|
|
|
|
this.SecondMenu("tls")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
tlsConfig := &serverconfigs.TLSProtocolConfig{}
|
|
|
|
|
if len(server.TlsJSON) > 0 {
|
|
|
|
|
err := json.Unmarshal(server.TlsJSON, tlsConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
tlsConfig.IsOn = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Data["serverType"] = server.Type
|
|
|
|
|
this.Data["tlsConfig"] = tlsConfig
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
ServerType string
|
|
|
|
|
Addresses string
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
}) {
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addresses := []*serverconfigs.NetworkAddressConfig{}
|
|
|
|
|
err := json.Unmarshal([]byte(params.Addresses), &addresses)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("端口地址解析失败:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tlsConfig := &serverconfigs.TLSProtocolConfig{}
|
|
|
|
|
if len(server.TlsJSON) > 0 {
|
|
|
|
|
err := json.Unmarshal(server.TlsJSON, tlsConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
tlsConfig.IsOn = true
|
|
|
|
|
}
|
|
|
|
|
tlsConfig.Listen = addresses
|
|
|
|
|
|
|
|
|
|
configData, err := json.Marshal(tlsConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = this.RPC().ServerRPC().UpdateServerTLS(this.AdminContext(), &pb.UpdateServerTLSRequest{
|
|
|
|
|
ServerId: params.ServerId,
|
|
|
|
|
Config: configData,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|