mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-29 10:15:20 +08:00
增加DNS域名管理
This commit is contained in:
60
internal/web/actions/default/dns/domains/createPopup.go
Normal file
60
internal/web/actions/default/dns/domains/createPopup.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package domains
|
||||
|
||||
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"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
this.Data["providerId"] = params.ProviderId
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
Name string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
// TODO 检查ProviderId
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入域名")
|
||||
|
||||
// 校验域名
|
||||
domain := strings.ToLower(params.Name)
|
||||
domain = strings.Replace(domain, " ", "", -1)
|
||||
if !domainutils.ValidateDomainFormat(domain) {
|
||||
this.Fail("域名格式不正确,请修改后重新提交")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().DNSDomainRPC().CreateDNSDomain(this.AdminContext(), &pb.CreateDNSDomainRequest{
|
||||
DnsProviderId: params.ProviderId,
|
||||
Name: domain,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.CreateLog(oplogs.LevelInfo, "添加管理域名到DNS服务商 %d", createResp.DnsDomainId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
38
internal/web/actions/default/dns/domains/delete.go
Normal file
38
internal/web/actions/default/dns/domains/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 记录日志
|
||||
this.CreateLog(oplogs.LevelInfo, "从DNS服务商中删除域名 %d", params.DomainId)
|
||||
|
||||
// 检查是否正在使用
|
||||
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithDNSDomainId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithDNSDomainIdRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if countResp.Count > 0 {
|
||||
this.Fail("当前域名正在被" + numberutils.FormatInt64(countResp.Count) + "个集群所使用,所以不能删除。请修改后再操作。")
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
_, err = this.RPC().DNSDomainRPC().DeleteDNSDomain(this.AdminContext(), &pb.DeleteDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package domainutils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 校验域名格式
|
||||
func ValidateDomainFormat(domain string) bool {
|
||||
pieces := strings.Split(domain, ".")
|
||||
for _, piece := range pieces {
|
||||
if !regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(piece) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
15
internal/web/actions/default/dns/domains/updatePopup.go
Normal file
15
internal/web/actions/default/dns/domains/updatePopup.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package domains
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user