2020-09-16 09:09:10 +08:00
|
|
|
package serverNames
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2020-11-11 21:32:19 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-09-16 09:09:10 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
2020-12-19 19:08:39 +08:00
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
2020-09-16 09:09:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 域名管理
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.FirstMenu("index")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
}) {
|
2020-12-19 19:08:39 +08:00
|
|
|
serverNamesResp, err := this.RPC().ServerRPC().FindServerNames(this.AdminContext(), &pb.FindServerNamesRequest{ServerId: params.ServerId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
2020-09-16 09:09:10 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverNamesConfig := []*serverconfigs.ServerNameConfig{}
|
2020-12-19 19:08:39 +08:00
|
|
|
this.Data["isAuditing"] = serverNamesResp.IsAuditing
|
|
|
|
|
this.Data["auditingResult"] = maps.Map{
|
|
|
|
|
"isOk": true,
|
|
|
|
|
}
|
|
|
|
|
if serverNamesResp.IsAuditing {
|
|
|
|
|
serverNamesResp.ServerNamesJSON = serverNamesResp.AuditingServerNamesJSON
|
|
|
|
|
} else if serverNamesResp.AuditingResult != nil {
|
|
|
|
|
if !serverNamesResp.AuditingResult.IsOk {
|
|
|
|
|
serverNamesResp.ServerNamesJSON = serverNamesResp.AuditingServerNamesJSON
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Data["auditingResult"] = maps.Map{
|
|
|
|
|
"isOk": serverNamesResp.AuditingResult.IsOk,
|
|
|
|
|
"reason": serverNamesResp.AuditingResult.Reason,
|
|
|
|
|
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", serverNamesResp.AuditingResult.CreatedAt),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(serverNamesResp.ServerNamesJSON) > 0 {
|
|
|
|
|
err := json.Unmarshal(serverNamesResp.ServerNamesJSON, &serverNamesConfig)
|
2020-09-16 09:09:10 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.Data["serverNames"] = serverNamesConfig
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
ServerNames string
|
|
|
|
|
Must *actions.Must
|
2020-12-19 19:08:39 +08:00
|
|
|
CSRF *actionutils.CSRF
|
2020-09-16 09:09:10 +08:00
|
|
|
}) {
|
2020-11-11 21:32:19 +08:00
|
|
|
// 记录日志
|
2020-11-20 15:32:42 +08:00
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "修改代理服务 %d 域名", params.ServerId)
|
2020-11-11 21:32:19 +08:00
|
|
|
|
2020-09-16 09:09:10 +08:00
|
|
|
serverNames := []*serverconfigs.ServerNameConfig{}
|
|
|
|
|
err := json.Unmarshal([]byte(params.ServerNames), &serverNames)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("域名解析失败:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = this.RPC().ServerRPC().UpdateServerNames(this.AdminContext(), &pb.UpdateServerNamesRequest{
|
2020-12-19 15:53:57 +08:00
|
|
|
ServerId: params.ServerId,
|
|
|
|
|
ServerNamesJSON: []byte(params.ServerNames),
|
2020-09-16 09:09:10 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|