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

This commit is contained in:
刘祥超
2020-11-13 18:22:35 +08:00
parent a609a36795
commit 8b749fbc60
32 changed files with 743 additions and 26 deletions

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()
}