实现基本的集群DNS列表、设置、简单数据同步

This commit is contained in:
GoEdgeLab
2020-11-13 18:22:35 +08:00
parent 78560620e8
commit dd4b190b78
32 changed files with 743 additions and 26 deletions

View File

@@ -0,0 +1,39 @@
package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
// 域名列表选项
type DomainOptionsAction struct {
actionutils.ParentAction
}
func (this *DomainOptionsAction) RunPost(params struct {
ProviderId int64
}) {
domainsResp, err := this.RPC().DNSDomainRPC().FindAllEnabledBasicDNSDomainsWithDNSProviderId(this.AdminContext(), &pb.FindAllEnabledBasicDNSDomainsWithDNSProviderIdRequest{
DnsProviderId: params.ProviderId,
})
if err != nil {
this.ErrorPage(err)
return
}
domainMaps := []maps.Map{}
for _, domain := range domainsResp.DnsDomains {
// 未开启的先跳过
if !domain.IsOn {
continue
}
domainMaps = append(domainMaps, maps.Map{
"id": domain.Id,
"name": domain.Name,
})
}
this.Data["domains"] = domainMaps
this.Success()
}

View File

@@ -0,0 +1,30 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type RoutesPopupAction struct {
actionutils.ParentAction
}
func (this *RoutesPopupAction) Init() {
this.Nav("", "", "")
}
func (this *RoutesPopupAction) RunGet(params struct {
DomainId int64
}) {
routesResp, err := this.RPC().DNSDomainRPC().FindAllDNSDomainRoutes(this.AdminContext(), &pb.FindAllDNSDomainRoutesRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
if len(routesResp.Routes) == 0 {
routesResp.Routes = []string{}
}
this.Data["routes"] = routesResp.Routes
this.Show()
}

View File

@@ -0,0 +1,33 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type SyncAction struct {
actionutils.ParentAction
}
func (this *SyncAction) RunPost(params struct {
DomainId int64
}) {
// 记录日志
this.CreateLog(oplogs.LevelInfo, "同步DNS域名数据 %d", params.DomainId)
// 执行同步
resp, err := this.RPC().DNSDomainRPC().SyncDNSDomainData(this.AdminContext(), &pb.SyncDNSDomainDataRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
if resp.IsOk {
this.Success()
} else {
this.Data["shouldFix"] = resp.ShouldFix
this.Fail(resp.Error)
}
this.Success()
}

View File

@@ -1,6 +1,14 @@
package domains
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
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"
"github.com/iwind/TeaGo/maps"
"strings"
)
type UpdatePopupAction struct {
actionutils.ParentAction
@@ -10,6 +18,62 @@ func (this *UpdatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdatePopupAction) RunGet(params struct{}) {
func (this *UpdatePopupAction) RunGet(params struct {
DomainId int64
}) {
domainResp, err := this.RPC().DNSDomainRPC().FindEnabledDNSDomain(this.AdminContext(), &pb.FindEnabledDNSDomainRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
domain := domainResp.DnsDomain
if domain == nil {
this.NotFound("dnsDomain", params.DomainId)
return
}
this.Data["domain"] = maps.Map{
"id": domain.Id,
"name": domain.Name,
"isOn": domain.IsOn,
}
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
DomainId int64
Name string
IsOn bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// TODO 检查DomainId
// 记录日志
this.CreateLog(oplogs.LevelInfo, "修改管理域名到DNS服务商 %d", params.DomainId)
params.Must.
Field("name", params.Name).
Require("请输入域名")
// 校验域名
domain := strings.ToLower(params.Name)
domain = strings.Replace(domain, " ", "", -1)
if !domainutils.ValidateDomainFormat(domain) {
this.Fail("域名格式不正确,请修改后重新提交")
}
_, err := this.RPC().DNSDomainRPC().UpdateDNSDomain(this.AdminContext(), &pb.UpdateDNSDomainRequest{
DnsDomainId: params.DomainId,
Name: domain,
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,6 +1,10 @@
package dns
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
@@ -11,5 +15,66 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
page := this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.Clusters {
domainId := cluster.DnsDomainId
domainName := ""
providerId := int64(0)
providerName := ""
providerTypeName := ""
if cluster.DnsDomainId > 0 {
domainResp, err := this.RPC().DNSDomainRPC().FindEnabledBasicDNSDomain(this.AdminContext(), &pb.FindEnabledBasicDNSDomainRequest{DnsDomainId: domainId})
if err != nil {
this.ErrorPage(err)
return
}
domain := domainResp.DnsDomain
if domain == nil {
domainId = 0
} else {
domainName = domain.Name
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.AdminContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: domain.ProviderId})
if err != nil {
this.ErrorPage(err)
return
}
if providerResp.DnsProvider != nil {
providerId = providerResp.DnsProvider.Id
providerName = providerResp.DnsProvider.Name
providerTypeName = providerResp.DnsProvider.TypeName
}
}
}
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"dnsName": cluster.DnsName,
"domainId": domainId,
"domainName": domainName,
"providerId": providerId,
"providerName": providerName,
"providerTypeName": providerTypeName,
})
}
this.Data["clusters"] = clusterMaps
this.Show()
}

View File

@@ -2,6 +2,7 @@ package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/issues"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/providers"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
@@ -14,6 +15,9 @@ func init() {
Helper(new(Helper)).
Prefix("/dns").
Get("", new(IndexAction)).
GetPost("/updateClusterPopup", new(UpdateClusterPopupAction)).
Post("/providerOptions", new(ProviderOptionsAction)).
Post("/domainOptions", new(DomainOptionsAction)).
// 服务商
Prefix("/dns/providers").
@@ -31,6 +35,14 @@ func init() {
GetPost("/createPopup", new(domains.CreatePopupAction)).
GetPost("/updatePopup", new(domains.UpdatePopupAction)).
Post("/delete", new(domains.DeleteAction)).
Post("/sync", new(domains.SyncAction)).
Get("/routesPopup", new(domains.RoutesPopupAction)).
EndData().
// 问题修复
Prefix("/dns/issues").
Data("teaSubMenu", "issue").
Get("", new(issues.IndexAction)).
EndData().
EndAll()

View File

@@ -0,0 +1,15 @@
package issues
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
this.Show()
}

View File

@@ -0,0 +1,32 @@
package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
// 服务商选项
type ProviderOptionsAction struct {
actionutils.ParentAction
}
func (this *ProviderOptionsAction) RunPost(params struct {
Type string
}) {
providersResp, err := this.RPC().DNSProviderRPC().FindAllEnabledDNSProvidersWithType(this.AdminContext(), &pb.FindAllEnabledDNSProvidersWithTypeRequest{ProviderTypeCode: params.Type})
if err != nil {
this.ErrorPage(err)
return
}
providerMaps := []maps.Map{}
for _, provider := range providersResp.DnsProviders {
providerMaps = append(providerMaps, maps.Map{
"id": provider.Id,
"name": provider.Name,
})
}
this.Data["providers"] = providerMaps
this.Success()
}

View File

@@ -60,10 +60,15 @@ func (this *ProviderAction) RunGet(params struct {
dataUpdatedTime = timeutil.FormatTime("Y-m-d H:i:s", domain.DataUpdatedAt)
}
domainMaps = append(domainMaps, maps.Map{
"id": domain.Id,
"name": domain.Name,
"isOn": domain.IsOn,
"dataUpdatedTime": dataUpdatedTime,
"id": domain.Id,
"name": domain.Name,
"isOn": domain.IsOn,
"dataUpdatedTime": dataUpdatedTime,
"countRoutes": len(domain.Routes),
"countServerRecords": domain.ServerRecords,
"allServersResolved": domain.AllServersResolved,
"countClusterRecords": domain.ClusterRecords,
"allClustersResolved": domain.AllClustersResolved,
})
}
this.Data["domains"] = domainMaps

View File

@@ -0,0 +1,103 @@
package dns
import (
"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"
"github.com/iwind/TeaGo/maps"
)
// 修改集群的DNS设置
type UpdateClusterPopupAction struct {
actionutils.ParentAction
}
func (this *UpdateClusterPopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdateClusterPopupAction) RunGet(params struct {
ClusterId int64
}) {
this.Data["clusterId"] = params.ClusterId
dnsResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["dnsName"] = dnsResp.Name
if dnsResp.Domain != nil {
this.Data["domainId"] = dnsResp.Domain.Id
this.Data["domain"] = dnsResp.Domain.Name
} else {
this.Data["domainId"] = 0
this.Data["domain"] = ""
}
if dnsResp.Provider != nil {
this.Data["providerType"] = dnsResp.Provider.Type
this.Data["providerId"] = dnsResp.Provider.Id
} else {
this.Data["providerType"] = ""
this.Data["providerId"] = 0
}
// 所有服务商
providerTypesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &pb.FindAllDNSProviderTypesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
providerTypeMaps := []maps.Map{}
for _, providerType := range providerTypesResp.ProviderTypes {
providerTypeMaps = append(providerTypeMaps, maps.Map{
"name": providerType.Name,
"code": providerType.Code,
})
}
this.Data["providerTypes"] = providerTypeMaps
this.Show()
}
func (this *UpdateClusterPopupAction) RunPost(params struct {
ClusterId int64
DnsName string
DomainId int64
Must *actions.Must
CSRF *actionutils.CSRF
}) {
params.Must.
Field("dnsName", params.DnsName).
Require("请输入子域名")
if !domainutils.ValidateDomainFormat(params.DnsName) {
this.FailField("dnsName", "子域名格式错误")
}
checkResp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSName(this.AdminContext(), &pb.CheckNodeClusterDNSNameRequest{
NodeClusterId: params.ClusterId,
DnsName: params.DnsName,
})
if err != nil {
this.ErrorPage(err)
return
}
if checkResp.IsUsed {
this.FailField("dnsName", "此子域名已经被占用,请修改后重新提交")
}
_, err = this.RPC().NodeClusterRPC().UpdateNodeClusterDNS(this.AdminContext(), &pb.UpdateNodeClusterDNSRequest{
NodeClusterId: params.ClusterId,
DnsName: params.DnsName,
DnsDomainId: params.DomainId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}