mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-28 23:40:26 +08:00
阶段性提交
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
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
|
||||
}) {
|
||||
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
|
||||
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
|
||||
}) {
|
||||
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user