145 lines
3.5 KiB
Go
145 lines
3.5 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
//go:build plus
|
|
|
|
package domains
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/actions"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
type UpdateAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *UpdateAction) Init() {
|
|
this.Nav("", "", "update")
|
|
}
|
|
|
|
func (this *UpdateAction) RunGet(params struct {
|
|
DomainId int64
|
|
}) {
|
|
// 初始化域名信息
|
|
err := domainutils.InitDomain(this.Parent(), params.DomainId)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var countRecords = this.Data.GetMap("domain").GetInt64("countRecords")
|
|
var countKeys = this.Data.GetMap("domain").GetInt64("countKeys")
|
|
|
|
// 域名信息
|
|
domainResp, err := this.RPC().NSDomainRPC().FindNSDomain(this.AdminContext(), &pb.FindNSDomainRequest{NsDomainId: params.DomainId})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var domain = domainResp.NsDomain
|
|
if domain == nil {
|
|
this.NotFound("nsDomain", params.DomainId)
|
|
return
|
|
}
|
|
|
|
var clusterId = int64(0)
|
|
if domain.NsCluster != nil {
|
|
clusterId = domain.NsCluster.Id
|
|
}
|
|
|
|
// 用户信息
|
|
var userId = int64(0)
|
|
if domain.User != nil {
|
|
userId = domain.User.Id
|
|
}
|
|
|
|
// 分组信息
|
|
var groupId int64
|
|
if len(domain.NsDomainGroups) > 0 {
|
|
groupId = domain.NsDomainGroups[0].Id
|
|
}
|
|
|
|
// 健康检查
|
|
var healthCheckConfig = dnsconfigs.NewNSRecordsHealthCheckConfig()
|
|
if len(domain.RecordsHealthCheckJSON) > 0 {
|
|
err = json.Unmarshal(domain.RecordsHealthCheckJSON, healthCheckConfig)
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
this.Data["domain"] = maps.Map{
|
|
"id": domain.Id,
|
|
"name": domain.Name,
|
|
"isOn": domain.IsOn,
|
|
"clusterId": clusterId,
|
|
"userId": userId,
|
|
"countRecords": countRecords,
|
|
"countKeys": countKeys,
|
|
"groupId": groupId,
|
|
"enableHealthCheck": healthCheckConfig.IsOn,
|
|
}
|
|
|
|
// DNS服务器
|
|
if domain.NsCluster == nil || domain.NsCluster.Id <= 0 {
|
|
this.WriteString("当前域名(" + domain.Name + ")所在集群已被删除,请删除当前域名后重新添加")
|
|
return
|
|
}
|
|
|
|
hostsResp, err := this.RPC().NSClusterRPC().FindNSClusterHosts(this.AdminContext(), &pb.FindNSClusterHostsRequest{
|
|
NsClusterId: domain.NsCluster.Id,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var hosts = hostsResp.Hosts
|
|
if hosts == nil {
|
|
hosts = []string{}
|
|
}
|
|
this.Data["dnsHosts"] = hosts
|
|
|
|
this.Show()
|
|
}
|
|
|
|
func (this *UpdateAction) RunPost(params struct {
|
|
DomainId int64
|
|
ClusterId int64
|
|
UserId int64
|
|
GroupId int64
|
|
IsOn bool
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
defer this.CreateLogInfo(codes.NSDomain_LogUpdateNSDomain, params.DomainId)
|
|
|
|
params.Must.
|
|
Field("clusterId", params.ClusterId).
|
|
Gt(0, "请选择所属集群")
|
|
|
|
var groupIds = []int64{}
|
|
if params.GroupId > 0 {
|
|
groupIds = append(groupIds, params.GroupId)
|
|
}
|
|
|
|
_, err := this.RPC().NSDomainRPC().UpdateNSDomain(this.AdminContext(), &pb.UpdateNSDomainRequest{
|
|
NsDomainId: params.DomainId,
|
|
NsClusterId: params.ClusterId,
|
|
UserId: params.UserId,
|
|
NsDomainGroupIds: groupIds,
|
|
IsOn: params.IsOn,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Success()
|
|
}
|