2020-11-15 16:28:25 +08:00
|
|
|
|
package dns
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
|
this.Nav("", "setting", "")
|
|
|
|
|
|
this.SecondMenu("dns")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
|
ClusterId int64
|
|
|
|
|
|
}) {
|
|
|
|
|
|
// 是否有域名可选
|
|
|
|
|
|
hasDomainsResp, err := this.RPC().DNSDomainRPC().ExistAvailableDomains(this.AdminContext(), &pb.ExistAvailableDomainsRequest{})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Data["hasDomains"] = hasDomainsResp.Exist
|
|
|
|
|
|
|
|
|
|
|
|
// 当前集群的DNS信息
|
|
|
|
|
|
this.Data["domainId"] = 0
|
|
|
|
|
|
this.Data["domainName"] = ""
|
|
|
|
|
|
this.Data["dnsName"] = ""
|
|
|
|
|
|
|
|
|
|
|
|
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Data["dnsName"] = dnsInfoResp.Name
|
2020-11-15 21:17:52 +08:00
|
|
|
|
this.Data["nodesAutoSync"] = dnsInfoResp.NodesAutoSync
|
|
|
|
|
|
this.Data["serversAutoSync"] = dnsInfoResp.ServersAutoSync
|
2020-11-15 16:28:25 +08:00
|
|
|
|
if dnsInfoResp.Domain != nil {
|
|
|
|
|
|
this.Data["domainId"] = dnsInfoResp.Domain.Id
|
|
|
|
|
|
this.Data["domainName"] = dnsInfoResp.Domain.Name
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-20 16:37:41 +08:00
|
|
|
|
if len(dnsInfoResp.CnameRecords) == 0 {
|
|
|
|
|
|
this.Data["cnameRecords"] = []string{}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.Data["cnameRecords"] = dnsInfoResp.CnameRecords
|
|
|
|
|
|
}
|
2021-09-20 20:01:15 +08:00
|
|
|
|
this.Data["ttl"] = dnsInfoResp.Ttl
|
2022-07-14 09:48:13 +08:00
|
|
|
|
this.Data["cnameAsDomain"] = dnsInfoResp.CnameAsDomain
|
2022-08-25 19:18:34 +08:00
|
|
|
|
this.Data["includingLnNodes"] = dnsInfoResp.IncludingLnNodes
|
2021-09-20 16:37:41 +08:00
|
|
|
|
|
2020-11-15 16:28:25 +08:00
|
|
|
|
this.Show()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
|
ClusterId int64
|
|
|
|
|
|
|
2022-08-25 19:18:34 +08:00
|
|
|
|
DnsDomainId int64
|
|
|
|
|
|
DnsName string
|
|
|
|
|
|
NodesAutoSync bool
|
|
|
|
|
|
ServersAutoSync bool
|
|
|
|
|
|
CnameRecords []string
|
|
|
|
|
|
Ttl int32
|
|
|
|
|
|
CnameAsDomain bool
|
|
|
|
|
|
IncludingLnNodes bool
|
2022-07-14 09:48:13 +08:00
|
|
|
|
|
|
|
|
|
|
ConfirmResetDomain bool // 是否确认重置域名
|
2020-11-15 16:28:25 +08:00
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
|
CSRF *actionutils.CSRF
|
|
|
|
|
|
}) {
|
|
|
|
|
|
// 创建日志
|
2020-11-20 15:32:42 +08:00
|
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "修改集群 %d DNS设置", params.ClusterId)
|
2020-11-15 16:28:25 +08:00
|
|
|
|
|
2022-07-14 09:48:13 +08:00
|
|
|
|
if !params.ConfirmResetDomain {
|
|
|
|
|
|
if params.DnsDomainId <= 0 {
|
|
|
|
|
|
this.Fail("请选择集群的主域名")
|
|
|
|
|
|
}
|
2021-07-31 22:23:07 +08:00
|
|
|
|
|
2022-07-14 09:48:13 +08:00
|
|
|
|
params.Must.
|
|
|
|
|
|
Field("dnsName", params.DnsName).
|
|
|
|
|
|
Require("请输入DNS子域名")
|
|
|
|
|
|
}
|
2021-07-31 22:23:07 +08:00
|
|
|
|
|
2020-11-15 16:28:25 +08:00
|
|
|
|
// 检查DNS名称
|
|
|
|
|
|
if len(params.DnsName) > 0 {
|
|
|
|
|
|
if !domainutils.ValidateDomainFormat(params.DnsName) {
|
|
|
|
|
|
this.FailField("dnsName", "请输入正确的DNS子域名")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已经被使用
|
|
|
|
|
|
resp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSName(this.AdminContext(), &pb.CheckNodeClusterDNSNameRequest{
|
|
|
|
|
|
NodeClusterId: params.ClusterId,
|
|
|
|
|
|
DnsName: params.DnsName,
|
|
|
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if resp.IsUsed {
|
|
|
|
|
|
this.FailField("dnsName", "此DNS子域名已经被使用,请换一个再试")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, err := this.RPC().NodeClusterRPC().UpdateNodeClusterDNS(this.AdminContext(), &pb.UpdateNodeClusterDNSRequest{
|
2022-08-25 19:18:34 +08:00
|
|
|
|
NodeClusterId: params.ClusterId,
|
|
|
|
|
|
DnsName: params.DnsName,
|
|
|
|
|
|
DnsDomainId: params.DnsDomainId,
|
|
|
|
|
|
NodesAutoSync: params.NodesAutoSync,
|
|
|
|
|
|
ServersAutoSync: params.ServersAutoSync,
|
|
|
|
|
|
CnameRecords: params.CnameRecords,
|
|
|
|
|
|
Ttl: params.Ttl,
|
|
|
|
|
|
CnameAsDomain: params.CnameAsDomain,
|
|
|
|
|
|
IncludingLnNodes: params.IncludingLnNodes,
|
2020-11-15 16:28:25 +08:00
|
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Success()
|
|
|
|
|
|
}
|