1.4.5.2
This commit is contained in:
39
EdgeUser/internal/web/actions/default/dns/domainOptions.go
Normal file
39
EdgeUser/internal/web/actions/default/dns/domainOptions.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// DomainOptionsAction 域名列表选项
|
||||
type DomainOptionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DomainOptionsAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
domainsResp, err := this.RPC().DNSDomainRPC().FindAllBasicDNSDomainsWithDNSProviderId(this.UserContext(), &pb.FindAllBasicDNSDomainsWithDNSProviderIdRequest{
|
||||
DnsProviderId: params.ProviderId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
domainMaps := []maps.Map{}
|
||||
for _, domain := range domainsResp.DnsDomains {
|
||||
// 未开启或者已删除的先跳过
|
||||
if !domain.IsOn || domain.IsDeleted {
|
||||
continue
|
||||
}
|
||||
|
||||
domainMaps = append(domainMaps, maps.Map{
|
||||
"id": domain.Id,
|
||||
"name": domain.Name,
|
||||
})
|
||||
}
|
||||
this.Data["domains"] = domainMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type ClustersPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ClustersPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ClustersPopupAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 域名信息
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindBasicDNSDomain(this.UserContext(), &pb.FindBasicDNSDomainRequest{
|
||||
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"] = domain.Name
|
||||
|
||||
// 集群
|
||||
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithDNSDomainId(this.UserContext(), &pb.FindAllEnabledNodeClustersWithDNSDomainIdRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
clusterMaps := []maps.Map{}
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
isOk := false
|
||||
if len(cluster.Name) > 0 {
|
||||
for _, recordType := range []string{"A", "AAAA"} {
|
||||
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.UserContext(), &pb.ExistDNSDomainRecordRequest{
|
||||
DnsDomainId: params.DomainId,
|
||||
Name: cluster.DnsName,
|
||||
Type: recordType,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if checkResp.IsOk {
|
||||
isOk = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
"dnsName": cluster.DnsName,
|
||||
"isOk": isOk,
|
||||
})
|
||||
}
|
||||
this.Data["clusters"] = clusterMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/dns/domains/domainutils"
|
||||
"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.UserContext(), &pb.CreateDNSDomainRequest{
|
||||
DnsProviderId: params.ProviderId,
|
||||
Name: domain,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer this.CreateLogInfo(codes.DNS_LogCreateDomain, createResp.DnsDomainId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
38
EdgeUser/internal/web/actions/default/dns/domains/delete.go
Normal file
38
EdgeUser/internal/web/actions/default/dns/domains/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 记录日志
|
||||
defer this.CreateLogInfo(codes.DNS_LogDeleteDomain, params.DomainId)
|
||||
|
||||
// 检查是否正在使用
|
||||
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithDNSDomainId(this.UserContext(), &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.UserContext(), &pb.DeleteDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package domainutils
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ValidateDomainFormat 校验域名格式
|
||||
func ValidateDomainFormat(domain string) bool {
|
||||
pieces := strings.Split(domain, ".")
|
||||
for _, piece := range pieces {
|
||||
if piece == "-" ||
|
||||
strings.HasPrefix(piece, "-") ||
|
||||
strings.HasSuffix(piece, "-") ||
|
||||
len(piece) > 63 ||
|
||||
// 我们允许中文、大写字母、下划线,防止有些特殊场景下需要
|
||||
!regexp.MustCompile(`^[\p{Han}_a-zA-Z0-9-]+$`).MatchString(piece) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 最后一段不能是全数字
|
||||
if regexp.MustCompile(`^(\d+)$`).MatchString(pieces[len(pieces)-1]) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// ConvertRoutesToMaps 转换线路列表
|
||||
func ConvertRoutesToMaps(info *pb.NodeDNSInfo) []maps.Map {
|
||||
if info == nil {
|
||||
return []maps.Map{}
|
||||
}
|
||||
result := []maps.Map{}
|
||||
for _, route := range info.Routes {
|
||||
result = append(result, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
"domainId": info.DnsDomainId,
|
||||
"domainName": info.DnsDomainName,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// FilterRoutes 筛选线路
|
||||
func FilterRoutes(routes []*pb.DNSRoute, allRoutes []*pb.DNSRoute) []*pb.DNSRoute {
|
||||
routeCodes := []string{}
|
||||
for _, route := range allRoutes {
|
||||
routeCodes = append(routeCodes, route.Code)
|
||||
}
|
||||
result := []*pb.DNSRoute{}
|
||||
for _, route := range routes {
|
||||
if lists.ContainsString(routeCodes, route.Code) {
|
||||
result = append(result, route)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// ValidateRecordName 校验记录名
|
||||
func ValidateRecordName(name string) bool {
|
||||
if name == "*" || name == "@" || len(name) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
pieces := strings.Split(name, ".")
|
||||
for index, piece := range pieces {
|
||||
if index == 0 && piece == "*" {
|
||||
continue
|
||||
}
|
||||
if piece == "-" ||
|
||||
strings.HasPrefix(piece, "-") ||
|
||||
strings.HasSuffix(piece, "-") ||
|
||||
//strings.Contains(piece, "--") ||
|
||||
len(piece) > 63 ||
|
||||
// 我们允许中文、大写字母、下划线,防止有些特殊场景下需要
|
||||
!regexp.MustCompile(`^[\p{Han}_a-zA-Z0-9-]+$`).MatchString(piece) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ValidateRecordValue 校验记录值
|
||||
func ValidateRecordValue(recordType dnsconfigs.RecordType, value string) (message string, ok bool) {
|
||||
switch recordType {
|
||||
case dnsconfigs.RecordTypeA:
|
||||
if !regexp.MustCompile(`^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$`).MatchString(value) {
|
||||
message = "请输入正确格式的IP"
|
||||
return
|
||||
}
|
||||
if net.ParseIP(value) == nil {
|
||||
message = "请输入正确格式的IP"
|
||||
return
|
||||
}
|
||||
case dnsconfigs.RecordTypeCNAME:
|
||||
value = strings.TrimSuffix(value, ".")
|
||||
if !strings.Contains(value, ".") || !ValidateDomainFormat(value) {
|
||||
message = "请输入正确的域名"
|
||||
return
|
||||
}
|
||||
case dnsconfigs.RecordTypeAAAA:
|
||||
if !strings.Contains(value, ":") {
|
||||
message = "请输入正确格式的IPv6地址"
|
||||
return
|
||||
}
|
||||
if net.ParseIP(value) == nil {
|
||||
message = "请输入正确格式的IPv6地址"
|
||||
return
|
||||
}
|
||||
case dnsconfigs.RecordTypeNS:
|
||||
value = strings.TrimSuffix(value, ".")
|
||||
if !strings.Contains(value, ".") || !ValidateDomainFormat(value) {
|
||||
message = "请输入正确的DNS服务器域名"
|
||||
return
|
||||
}
|
||||
case dnsconfigs.RecordTypeMX:
|
||||
value = strings.TrimSuffix(value, ".")
|
||||
if !strings.Contains(value, ".") || !ValidateDomainFormat(value) {
|
||||
message = "请输入正确的邮件服务器域名"
|
||||
return
|
||||
}
|
||||
case dnsconfigs.RecordTypeSRV:
|
||||
if len(value) == 0 {
|
||||
message = "请输入主机名"
|
||||
return
|
||||
}
|
||||
case dnsconfigs.RecordTypeTXT:
|
||||
if len(value) > 512 {
|
||||
message = "文本长度不能超出512字节"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(value) > 512 {
|
||||
message = "记录值长度不能超出512字节"
|
||||
return
|
||||
}
|
||||
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package domainutils
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateRecordValue(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
// A
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeA, "1.2")
|
||||
a.IsFalse(ok)
|
||||
}
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeA, "1.2.3.400")
|
||||
a.IsFalse(ok)
|
||||
}
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeA, "1.2.3.4")
|
||||
a.IsTrue(ok)
|
||||
}
|
||||
|
||||
// CNAME
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeCNAME, "example.com")
|
||||
a.IsTrue(ok)
|
||||
}
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeCNAME, "example.com.")
|
||||
a.IsTrue(ok)
|
||||
}
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeCNAME, "hello, world")
|
||||
a.IsFalse(ok)
|
||||
}
|
||||
|
||||
// AAAA
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeAAAA, "1.2.3.4")
|
||||
a.IsFalse(ok)
|
||||
}
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeAAAA, "2001:0db8:85a3:0000:0000:8a2e:0370:7334")
|
||||
a.IsTrue(ok)
|
||||
}
|
||||
|
||||
// NS
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeNS, "1.2.3.4")
|
||||
a.IsFalse(ok)
|
||||
}
|
||||
{
|
||||
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeNS, "example.com")
|
||||
a.IsTrue(ok)
|
||||
}
|
||||
}
|
||||
146
EdgeUser/internal/web/actions/default/dns/domains/nodesPopup.go
Normal file
146
EdgeUser/internal/web/actions/default/dns/domains/nodesPopup.go
Normal file
@@ -0,0 +1,146 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type NodesPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *NodesPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *NodesPopupAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
this.Data["domainId"] = params.DomainId
|
||||
|
||||
// 域名信息
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindBasicDNSDomain(this.UserContext(), &pb.FindBasicDNSDomainRequest{
|
||||
DnsDomainId: params.DomainId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var domain = domainResp.DnsDomain
|
||||
if domain == nil {
|
||||
this.NotFound("dnsDomain", params.DomainId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["domain"] = domain.Name
|
||||
|
||||
// 集群
|
||||
var clusterMaps = []maps.Map{}
|
||||
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithDNSDomainId(this.UserContext(), &pb.FindAllEnabledNodeClustersWithDNSDomainIdRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
// 默认值
|
||||
var defaultRoute = cluster.DnsDefaultRoute
|
||||
|
||||
// 节点DNS解析记录
|
||||
nodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesDNSWithNodeClusterId(this.UserContext(), &pb.FindAllEnabledNodesDNSWithNodeClusterIdRequest{
|
||||
NodeClusterId: cluster.Id,
|
||||
IsInstalled: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var nodeMaps = []maps.Map{}
|
||||
for _, node := range nodesResp.Nodes {
|
||||
if len(node.Routes) > 0 {
|
||||
for _, route := range node.Routes {
|
||||
// 检查是否有域名解析记录
|
||||
var isResolved = false
|
||||
if len(route.Name) > 0 && len(node.IpAddr) > 0 && len(cluster.DnsName) > 0 {
|
||||
var recordType = "A"
|
||||
if iputils.IsIPv6(node.IpAddr) {
|
||||
recordType = "AAAA"
|
||||
}
|
||||
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.UserContext(), &pb.ExistDNSDomainRecordRequest{
|
||||
DnsDomainId: params.DomainId,
|
||||
Name: cluster.DnsName,
|
||||
Type: recordType,
|
||||
Route: route.Code,
|
||||
Value: node.IpAddr,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isResolved = checkResp.IsOk
|
||||
}
|
||||
|
||||
nodeMaps = append(nodeMaps, maps.Map{
|
||||
"id": node.Id,
|
||||
"name": node.Name,
|
||||
"ipAddr": node.IpAddr,
|
||||
"route": maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
},
|
||||
"clusterId": node.NodeClusterId,
|
||||
"isOk": isResolved,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 默认线路
|
||||
var isResolved = false
|
||||
if len(defaultRoute) > 0 {
|
||||
var recordType = "A"
|
||||
if iputils.IsIPv6(node.IpAddr) {
|
||||
recordType = "AAAA"
|
||||
}
|
||||
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.UserContext(), &pb.ExistDNSDomainRecordRequest{
|
||||
DnsDomainId: cluster.DnsDomainId,
|
||||
Name: cluster.DnsName,
|
||||
Type: recordType,
|
||||
Route: defaultRoute,
|
||||
Value: node.IpAddr,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isResolved = checkResp.IsOk
|
||||
}
|
||||
nodeMaps = append(nodeMaps, maps.Map{
|
||||
"id": node.Id,
|
||||
"name": node.Name,
|
||||
"ipAddr": node.IpAddr,
|
||||
"route": maps.Map{
|
||||
"name": "",
|
||||
"code": "",
|
||||
},
|
||||
"clusterId": node.NodeClusterId,
|
||||
"isOk": isResolved,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(nodeMaps) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
"dnsName": cluster.DnsName,
|
||||
"nodes": nodeMaps,
|
||||
})
|
||||
}
|
||||
this.Data["clusters"] = clusterMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
27
EdgeUser/internal/web/actions/default/dns/domains/recover.go
Normal file
27
EdgeUser/internal/web/actions/default/dns/domains/recover.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type RecoverAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RecoverAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 记录日志
|
||||
defer this.CreateLogInfo(codes.DNS_LogRecoverDomain, params.DomainId)
|
||||
|
||||
// 执行恢复
|
||||
_, err := this.RPC().DNSDomainRPC().RecoverDNSDomain(this.UserContext(), &pb.RecoverDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
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.UserContext(), &pb.FindAllDNSDomainRoutesRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
routeMaps := []maps.Map{}
|
||||
for _, route := range routesResp.Routes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"name": route.Name,
|
||||
"code": route.Code,
|
||||
})
|
||||
}
|
||||
this.Data["routes"] = routeMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
105
EdgeUser/internal/web/actions/default/dns/domains/selectPopup.go
Normal file
105
EdgeUser/internal/web/actions/default/dns/domains/selectPopup.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type SelectPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *SelectPopupAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
this.Data["domainId"] = 0
|
||||
this.Data["domainName"] = ""
|
||||
this.Data["providerId"] = 0
|
||||
this.Data["providerType"] = ""
|
||||
|
||||
// 域名信息
|
||||
if params.DomainId > 0 {
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindDNSDomain(this.UserContext(), &pb.FindDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var domain = domainResp.DnsDomain
|
||||
if domain != nil {
|
||||
this.Data["domainId"] = domain.Id
|
||||
this.Data["domainName"] = domain.Name
|
||||
this.Data["providerId"] = domain.ProviderId
|
||||
|
||||
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.UserContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: domain.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if providerResp.DnsProvider != nil {
|
||||
this.Data["providerType"] = providerResp.DnsProvider.Type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 所有服务商
|
||||
providerTypesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.UserContext(), &pb.FindAllDNSProviderTypesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var 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 *SelectPopupAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
this.Data["domainId"] = params.DomainId
|
||||
this.Data["domainName"] = ""
|
||||
this.Data["providerName"] = ""
|
||||
|
||||
if params.DomainId > 0 {
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindDNSDomain(this.UserContext(), &pb.FindDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if domainResp.DnsDomain != nil {
|
||||
this.Data["domainName"] = domainResp.DnsDomain.Name
|
||||
|
||||
// 服务商名称
|
||||
var providerId = domainResp.DnsDomain.ProviderId
|
||||
if providerId > 0 {
|
||||
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.UserContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: providerId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if providerResp.DnsProvider != nil {
|
||||
this.Data["providerName"] = providerResp.DnsProvider.Name
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.Data["domainId"] = 0
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type ServersPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ServersPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ServersPopupAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
this.Data["domainId"] = params.DomainId
|
||||
|
||||
// 域名信息
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindBasicDNSDomain(this.UserContext(), &pb.FindBasicDNSDomainRequest{
|
||||
DnsDomainId: params.DomainId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var domain = domainResp.DnsDomain
|
||||
if domain == nil {
|
||||
this.NotFound("dnsDomain", params.DomainId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["domain"] = domain.Name
|
||||
|
||||
// 服务信息
|
||||
var clusterMaps = []maps.Map{}
|
||||
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithDNSDomainId(this.UserContext(), &pb.FindAllEnabledNodeClustersWithDNSDomainIdRequest{DnsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
serversResp, err := this.RPC().ServerRPC().FindAllEnabledServersDNSWithNodeClusterId(this.UserContext(), &pb.FindAllEnabledServersDNSWithNodeClusterIdRequest{NodeClusterId: cluster.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var serverMaps = []maps.Map{}
|
||||
for _, server := range serversResp.Servers {
|
||||
var isOk = false
|
||||
if len(cluster.DnsName) > 0 && len(server.DnsName) > 0 {
|
||||
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.UserContext(), &pb.ExistDNSDomainRecordRequest{
|
||||
DnsDomainId: params.DomainId,
|
||||
Name: server.DnsName,
|
||||
Type: "CNAME",
|
||||
Value: cluster.DnsName + "." + domain.Name,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isOk = checkResp.IsOk
|
||||
}
|
||||
|
||||
serverMaps = append(serverMaps, maps.Map{
|
||||
"id": server.Id,
|
||||
"name": server.Name,
|
||||
"dnsName": server.DnsName,
|
||||
"isOk": isOk,
|
||||
})
|
||||
}
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
"dnsName": cluster.DnsName,
|
||||
"servers": serverMaps,
|
||||
})
|
||||
}
|
||||
this.Data["clusters"] = clusterMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
33
EdgeUser/internal/web/actions/default/dns/domains/sync.go
Normal file
33
EdgeUser/internal/web/actions/default/dns/domains/sync.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type SyncAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SyncAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 记录日志
|
||||
defer this.CreateLogInfo(codes.DNS_LogSyncDomain, params.DomainId)
|
||||
|
||||
// 执行同步
|
||||
resp, err := this.RPC().DNSDomainRPC().SyncDNSDomainData(this.UserContext(), &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()
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package domains
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/dns/domains/domainutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindDNSDomain(this.UserContext(), &pb.FindDNSDomainRequest{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
|
||||
|
||||
// 记录日志
|
||||
defer this.CreateLogInfo(codes.DNS_LogUpdateDomain, 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.UserContext(), &pb.UpdateDNSDomainRequest{
|
||||
DnsDomainId: params.DomainId,
|
||||
Name: domain,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
17
EdgeUser/internal/web/actions/default/dns/helper.go
Normal file
17
EdgeUser/internal/web/actions/default/dns/helper.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Helper struct {
|
||||
}
|
||||
|
||||
func (this *Helper) BeforeAction(action *actions.ActionObject) {
|
||||
if action.Request.Method != http.MethodGet {
|
||||
return
|
||||
}
|
||||
|
||||
action.Data["teaMenu"] = "dns"
|
||||
}
|
||||
90
EdgeUser/internal/web/actions/default/dns/index.go
Normal file
90
EdgeUser/internal/web/actions/default/dns/index.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("dns", "dns", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Keyword string
|
||||
}) {
|
||||
//用户端没有集群列表 暂时从定向到dns服务商
|
||||
this.RedirectURL("/dns/providers")
|
||||
return
|
||||
this.Data["keyword"] = params.Keyword
|
||||
|
||||
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.UserContext(), &pb.CountAllEnabledNodeClustersRequest{
|
||||
Keyword: params.Keyword,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
page := this.NewPage(countResp.Count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.UserContext(), &pb.ListEnabledNodeClustersRequest{
|
||||
Keyword: params.Keyword,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
clusterMaps := []maps.Map{}
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
domainId := cluster.DnsDomainId
|
||||
domainName := ""
|
||||
providerId := int64(0)
|
||||
providerName := ""
|
||||
providerTypeName := ""
|
||||
|
||||
if cluster.DnsDomainId > 0 {
|
||||
domainResp, err := this.RPC().DNSDomainRPC().FindBasicDNSDomain(this.UserContext(), &pb.FindBasicDNSDomainRequest{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.UserContext(), &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()
|
||||
}
|
||||
51
EdgeUser/internal/web/actions/default/dns/init.go
Normal file
51
EdgeUser/internal/web/actions/default/dns/init.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/dns/domains"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/dns/providers"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth("")).
|
||||
Helper(new(Helper)).
|
||||
Prefix("/dns").
|
||||
Get("", new(IndexAction)).
|
||||
Post("/providerOptions", new(ProviderOptionsAction)).
|
||||
Post("/domainOptions", new(DomainOptionsAction)).
|
||||
|
||||
// 服务商
|
||||
|
||||
Prefix("/dns/providers").
|
||||
Data("teaMenu", "provider").
|
||||
//Data("teaSubMenu", "provider").
|
||||
Get("", new(providers.IndexAction)).
|
||||
GetPost("/createPopup", new(providers.CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(providers.UpdatePopupAction)).
|
||||
Post("/delete", new(providers.DeleteAction)).
|
||||
Get("/provider", new(providers.ProviderAction)).
|
||||
Post("/syncDomains", new(providers.SyncDomainsAction)).
|
||||
EndData().
|
||||
|
||||
// 域名
|
||||
Prefix("/dns/domains").
|
||||
Data("teaSubMenu", "provider").
|
||||
GetPost("/createPopup", new(domains.CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(domains.UpdatePopupAction)).
|
||||
Post("/delete", new(domains.DeleteAction)).
|
||||
Post("/recover", new(domains.RecoverAction)).
|
||||
Post("/sync", new(domains.SyncAction)).
|
||||
Get("/routesPopup", new(domains.RoutesPopupAction)).
|
||||
GetPost("/selectPopup", new(domains.SelectPopupAction)).
|
||||
Get("/clustersPopup", new(domains.ClustersPopupAction)).
|
||||
Get("/nodesPopup", new(domains.NodesPopupAction)).
|
||||
Get("/serversPopup", new(domains.ServersPopupAction)).
|
||||
EndData().
|
||||
|
||||
//
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
32
EdgeUser/internal/web/actions/default/dns/providerOptions.go
Normal file
32
EdgeUser/internal/web/actions/default/dns/providerOptions.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"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.UserContext(), &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()
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package providers
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 所有厂商
|
||||
typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.UserContext(), &pb.FindAllDNSProviderTypesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
typeMaps := []maps.Map{}
|
||||
for _, t := range typesResp.ProviderTypes {
|
||||
typeMaps = append(typeMaps, maps.Map{
|
||||
"name": t.Name,
|
||||
"code": t.Code,
|
||||
"description": t.Description,
|
||||
})
|
||||
}
|
||||
this.Data["types"] = typeMaps
|
||||
|
||||
// 自动生成CustomHTTP私钥
|
||||
this.Data["paramCustomHTTPSecret"] = rands.HexString(32)
|
||||
|
||||
// EdgeDNS集群列表
|
||||
nsClustersResp, err := this.RPC().NSClusterRPC().FindAllNSClusters(this.UserContext(), &pb.FindAllNSClustersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var nsClusterMaps = []maps.Map{}
|
||||
for _, nsCluster := range nsClustersResp.NsClusters {
|
||||
nsClusterMaps = append(nsClusterMaps, maps.Map{
|
||||
"id": nsCluster.Id,
|
||||
"name": nsCluster.Name,
|
||||
})
|
||||
}
|
||||
this.Data["nsClusters"] = nsClusterMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Type string
|
||||
|
||||
// DNSPod
|
||||
ParamDNSPodId string
|
||||
ParamDNSPodToken string
|
||||
ParamDNSPodRegion string
|
||||
|
||||
ParamDNSPodAPIType string
|
||||
ParamDNSPodAccessKeyId string
|
||||
ParamDNSPodAccessKeySecret string
|
||||
|
||||
// AliDNS
|
||||
ParamAliDNSAccessKeyId string
|
||||
ParamAliDNSAccessKeySecret string
|
||||
ParamAliDNSRegionId string
|
||||
|
||||
// HuaweiDNS
|
||||
ParamHuaweiAccessKeyId string
|
||||
ParamHuaweiAccessKeySecret string
|
||||
ParamHuaweiEndpoint string
|
||||
|
||||
// CloudFlare
|
||||
ParamCloudFlareAPIKey string
|
||||
ParamCloudFlareEmail string
|
||||
|
||||
// GoDaddy
|
||||
ParamGoDaddyKey string
|
||||
ParamGoDaddySecret string
|
||||
|
||||
// ClouDNS
|
||||
ParamClouDNSAuthId string
|
||||
ParamClouDNSSubAuthId string
|
||||
ParamClouDNSAuthPassword string
|
||||
|
||||
// DNS.COM
|
||||
ParamDNSComKey string
|
||||
ParamDNSComSecret string
|
||||
|
||||
// DNS.LA
|
||||
ParamDNSLaAPIId string
|
||||
ParamDNSLaSecret string
|
||||
|
||||
// VolcEngine
|
||||
ParamVolcEngineAccessKeyId string
|
||||
ParamVolcEngineAccessKeySecret string
|
||||
|
||||
// Amazon Route 53
|
||||
ParamAmazonRoute53AccessKeyId string
|
||||
ParamAmazonRoute53AccessKeySecret string
|
||||
ParamAmazonRoute53Region string
|
||||
|
||||
// Microsoft Azure DNS
|
||||
ParamAzureDNSSubscriptionId string
|
||||
ParamAzureDNSTenantId string
|
||||
ParamAzureDNSClientId string
|
||||
ParamAzureDNSClientSecret string
|
||||
ParamAzureDNSResourceGroupName string
|
||||
|
||||
// bunny.net
|
||||
ParamBunnyNetAPIKey string
|
||||
|
||||
// Gname
|
||||
ParamGnameAppid string
|
||||
ParamGnameSecret string
|
||||
|
||||
// Local EdgeDNS
|
||||
ParamLocalEdgeDNSClusterId int64
|
||||
|
||||
// EdgeDNS API
|
||||
ParamEdgeDNSAPIHost string
|
||||
ParamEdgeDNSAPIRole string
|
||||
ParamEdgeDNSAPIAccessKeyId string
|
||||
ParamEdgeDNSAPIAccessKeySecret string
|
||||
|
||||
// CustomHTTP
|
||||
ParamCustomHTTPURL string
|
||||
ParamCustomHTTPSecret string
|
||||
|
||||
MinTTL int32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入账号说明").
|
||||
Field("type", params.Type).
|
||||
Require("请选择服务商厂家")
|
||||
|
||||
var apiParams = maps.Map{}
|
||||
switch params.Type {
|
||||
case "dnspod":
|
||||
apiParams["apiType"] = params.ParamDNSPodAPIType
|
||||
switch params.ParamDNSPodAPIType {
|
||||
case "tencentDNS":
|
||||
params.Must.
|
||||
Field("paramDNSPodAccessKeyId", params.ParamDNSPodAccessKeyId).
|
||||
Require("请输入SecretId").
|
||||
Field("paramDNSPodAccessKeySecret", params.ParamDNSPodAccessKeySecret).
|
||||
Require("请输入SecretKey")
|
||||
apiParams["accessKeyId"] = params.ParamDNSPodAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamDNSPodAccessKeySecret
|
||||
apiParams["region"] = params.ParamDNSPodRegion
|
||||
default:
|
||||
params.Must.
|
||||
Field("paramId", params.ParamDNSPodId).
|
||||
Require("请输入密钥ID").
|
||||
Field("paramToken", params.ParamDNSPodToken).
|
||||
Require("请输入密钥Token")
|
||||
|
||||
apiParams["id"] = params.ParamDNSPodId
|
||||
apiParams["token"] = params.ParamDNSPodToken
|
||||
apiParams["region"] = params.ParamDNSPodRegion
|
||||
}
|
||||
case "alidns":
|
||||
params.Must.
|
||||
Field("paramAliDNSAccessKeyId", params.ParamAliDNSAccessKeyId).
|
||||
Require("请输入AccessKeyId").
|
||||
Field("paramAliDNSAccessKeySecret", params.ParamAliDNSAccessKeySecret).
|
||||
Require("请输入AccessKeySecret")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamAliDNSAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamAliDNSAccessKeySecret
|
||||
apiParams["regionId"] = params.ParamAliDNSRegionId
|
||||
case "huaweiDNS":
|
||||
params.Must.
|
||||
Field("paramHuaweiAccessKeyId", params.ParamHuaweiAccessKeyId).
|
||||
Require("请输入AccessKeyId").
|
||||
Field("paramHuaweiAccessKeySecret", params.ParamHuaweiAccessKeySecret).
|
||||
Require("请输入AccessKeySecret")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamHuaweiAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamHuaweiAccessKeySecret
|
||||
apiParams["endpoint"] = params.ParamHuaweiEndpoint
|
||||
case "cloudFlare":
|
||||
params.Must.
|
||||
Field("paramCloudFlareAPIKey", params.ParamCloudFlareAPIKey).
|
||||
Require("请输入API密钥").
|
||||
Field("paramCloudFlareEmail", params.ParamCloudFlareEmail).
|
||||
Email("请输入正确格式的邮箱地址")
|
||||
apiParams["apiKey"] = params.ParamCloudFlareAPIKey
|
||||
apiParams["email"] = params.ParamCloudFlareEmail
|
||||
case "godaddy":
|
||||
params.Must.
|
||||
Field("paramGodaddyKey", params.ParamGoDaddyKey).
|
||||
Require("请输入Key").
|
||||
Field("paramGodaddySecret", params.ParamGoDaddySecret).
|
||||
Require("请输入Secret")
|
||||
apiParams["key"] = params.ParamGoDaddyKey
|
||||
apiParams["secret"] = params.ParamGoDaddySecret
|
||||
case "cloudns":
|
||||
var authIdString = params.ParamClouDNSAuthId
|
||||
var subAuthIdString = params.ParamClouDNSSubAuthId
|
||||
var authPassword = params.ParamClouDNSAuthPassword
|
||||
if len(authIdString) == 0 && len(subAuthIdString) == 0 {
|
||||
this.FailField("paramClouDNSAuthId", "请输入用户或者子用户的认证ID(auth-id)")
|
||||
}
|
||||
if len(authIdString) > 0 {
|
||||
if !regexp.MustCompile(`^\d+$`).MatchString(authIdString) {
|
||||
this.FailField("paramClouDNSAuthId", "用户认证ID需要是一个整数")
|
||||
}
|
||||
}
|
||||
if len(subAuthIdString) > 0 {
|
||||
if !regexp.MustCompile(`^\d+$`).MatchString(subAuthIdString) {
|
||||
this.FailField("paramClouDNSSubAuthId", "子用户认证ID需要是一个整数")
|
||||
}
|
||||
}
|
||||
if len(authPassword) == 0 {
|
||||
this.FailField("paramClouDNSPassword", "请输入用户或者子用户的认证密码")
|
||||
}
|
||||
|
||||
apiParams["authId"] = types.Int64(authIdString)
|
||||
apiParams["subAuthId"] = types.Int64(subAuthIdString)
|
||||
apiParams["authPassword"] = authPassword
|
||||
case "dnscom":
|
||||
params.Must.
|
||||
Field("paramDNSComKey", params.ParamDNSComKey).
|
||||
Require("请输入ApiKey").
|
||||
Field("paramDNSComSecret", params.ParamDNSComSecret).
|
||||
Require("请输入ApiSecret")
|
||||
|
||||
apiParams["key"] = params.ParamDNSComKey
|
||||
apiParams["secret"] = params.ParamDNSComSecret
|
||||
case "dnsla":
|
||||
params.Must.
|
||||
Field("paramDNSLaAPIId", params.ParamDNSLaAPIId).
|
||||
Require("请输入API ID").
|
||||
Field("paramDNSLaSecret", params.ParamDNSLaSecret).
|
||||
Require("请输入API密钥")
|
||||
|
||||
apiParams["apiId"] = params.ParamDNSLaAPIId
|
||||
apiParams["secret"] = params.ParamDNSLaSecret
|
||||
case "volcEngine":
|
||||
params.Must.
|
||||
Field("paramVolcEngineAccessKeyId", params.ParamVolcEngineAccessKeyId).
|
||||
Require("请输入Access Key ID").
|
||||
Field("paramVolcEngineAccessKeySecret", params.ParamVolcEngineAccessKeySecret).
|
||||
Require("请输入Secret Access Key")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamVolcEngineAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamVolcEngineAccessKeySecret
|
||||
case "amazonRoute53":
|
||||
params.Must.
|
||||
Field("paramAmazonRoute53AccessKeyId", params.ParamAmazonRoute53AccessKeyId).
|
||||
Require("请输入Access Key ID").
|
||||
Field("paramAmazonRoute53AccessKeySecret", params.ParamAmazonRoute53AccessKeySecret).
|
||||
Require("请输入Secret Access Key")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamAmazonRoute53AccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamAmazonRoute53AccessKeySecret
|
||||
apiParams["region"] = params.ParamAmazonRoute53Region
|
||||
case "azureDNS":
|
||||
params.Must.
|
||||
Field("paramAzureDNSSubscriptionId", params.ParamAzureDNSSubscriptionId).
|
||||
Require("请输入Subscription ID").
|
||||
Field("paramAzureDNSTenantId", params.ParamAzureDNSTenantId).
|
||||
Require("请输入Tenant ID").
|
||||
Field("paramAzureDNSClientId", params.ParamAzureDNSClientId).
|
||||
Require("请输入Client ID").
|
||||
Field("paramAzureDNSClientSecret", params.ParamAzureDNSClientSecret).
|
||||
Require("请输入Client Secret").
|
||||
Field("paramAzureDNSResourceGroupName", params.ParamAzureDNSResourceGroupName).
|
||||
Require("请输入Resource Group Name")
|
||||
|
||||
apiParams["subscriptionId"] = params.ParamAzureDNSSubscriptionId
|
||||
apiParams["tenantId"] = params.ParamAzureDNSTenantId
|
||||
apiParams["clientId"] = params.ParamAzureDNSClientId
|
||||
apiParams["clientSecret"] = params.ParamAzureDNSClientSecret
|
||||
apiParams["resourceGroupName"] = params.ParamAzureDNSResourceGroupName
|
||||
case "bunnyNet":
|
||||
params.Must.
|
||||
Field("paramBunnyNetAPIKey", params.ParamBunnyNetAPIKey).
|
||||
Require("请输入API密钥")
|
||||
apiParams["apiKey"] = params.ParamBunnyNetAPIKey
|
||||
case "gname":
|
||||
params.Must.
|
||||
Field("paramGnameAppid", params.ParamGnameAppid).
|
||||
Require("请输入APPID").
|
||||
Field("paramGnameSecret", params.ParamGnameSecret).
|
||||
Require("请输入API Secret")
|
||||
apiParams["appid"] = params.ParamGnameAppid
|
||||
apiParams["secret"] = params.ParamGnameSecret
|
||||
case "localEdgeDNS":
|
||||
params.Must.
|
||||
Field("paramLocalEdgeDNSClusterId", params.ParamLocalEdgeDNSClusterId).
|
||||
Gt(0, "请选择域名服务集群")
|
||||
apiParams["clusterId"] = params.ParamLocalEdgeDNSClusterId
|
||||
case "edgeDNSAPI":
|
||||
params.Must.
|
||||
Field("paramEdgeDNSAPIHost", params.ParamEdgeDNSAPIHost).
|
||||
Require("请输入API地址").
|
||||
Field("paramEdgeDNSAPIRole", params.ParamEdgeDNSAPIRole).
|
||||
Require("请选择AccessKey类型").
|
||||
Field("paramEdgeDNSAPIAccessKeyId", params.ParamEdgeDNSAPIAccessKeyId).
|
||||
Require("请输入AccessKey ID").
|
||||
Field("paramEdgeDNSAPIAccessKeySecret", params.ParamEdgeDNSAPIAccessKeySecret).
|
||||
Require("请输入AccessKey密钥")
|
||||
apiParams["host"] = params.ParamEdgeDNSAPIHost
|
||||
apiParams["role"] = params.ParamEdgeDNSAPIRole
|
||||
apiParams["accessKeyId"] = params.ParamEdgeDNSAPIAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamEdgeDNSAPIAccessKeySecret
|
||||
case "customHTTP":
|
||||
params.Must.
|
||||
Field("paramCustomHTTPURL", params.ParamCustomHTTPURL).
|
||||
Require("请输入HTTP URL").
|
||||
Match("^(?i)(http|https):", "URL必须以http://或者https://开头").
|
||||
Field("paramCustomHTTPSecret", params.ParamCustomHTTPSecret).
|
||||
Require("请输入私钥")
|
||||
apiParams["url"] = params.ParamCustomHTTPURL
|
||||
apiParams["secret"] = params.ParamCustomHTTPSecret
|
||||
default:
|
||||
this.Fail("暂时不支持此服务商'" + params.Type + "'")
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().DNSProviderRPC().CreateDNSProvider(this.UserContext(), &pb.CreateDNSProviderRequest{
|
||||
Name: params.Name,
|
||||
Type: params.Type,
|
||||
ApiParamsJSON: apiParams.AsJSON(),
|
||||
MinTTL: params.MinTTL,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer this.CreateLogInfo(codes.DNSProvider_LogCreateDNSProvider, createResp.DnsProviderId)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
// TODO 检查权限
|
||||
|
||||
// 记录日志
|
||||
defer this.CreateLogInfo(codes.DNSProvider_LogDeleteDNSProvider, params.ProviderId)
|
||||
|
||||
// 检查是否被集群使用
|
||||
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithDNSProviderId(this.UserContext(), &pb.CountAllEnabledNodeClustersWithDNSProviderIdRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if countClustersResp.Count > 0 {
|
||||
this.Fail("当前DNS服务商账号正在被" + numberutils.FormatInt64(countClustersResp.Count) + "个集群所使用,所以不能删除。请修改集群设置后再操作。")
|
||||
}
|
||||
|
||||
// 判断是否被ACME任务使用
|
||||
countACMETasksResp, err := this.RPC().ACMETaskRPC().CountEnabledACMETasksWithDNSProviderId(this.UserContext(), &pb.CountEnabledACMETasksWithDNSProviderIdRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if countACMETasksResp.Count > 0 {
|
||||
this.Fail("当前DNS服务商账号正在被" + numberutils.FormatInt64(countACMETasksResp.Count) + "个ACME证书申请任务使用,所以不能删除。请修改ACME证书申请任务后再操作。")
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
_, err = this.RPC().DNSProviderRPC().DeleteDNSProvider(this.UserContext(), &pb.DeleteDNSProviderRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
113
EdgeUser/internal/web/actions/default/dns/providers/index.go
Normal file
113
EdgeUser/internal/web/actions/default/dns/providers/index.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "provider")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Keyword string
|
||||
Domain string
|
||||
ProviderType string
|
||||
}) {
|
||||
this.Data["keyword"] = params.Keyword
|
||||
this.Data["domain"] = params.Domain
|
||||
this.Data["providerType"] = params.ProviderType
|
||||
|
||||
// 格式化域名
|
||||
var domain = regexp.MustCompile(`^(www\.)`).ReplaceAllString(params.Domain, "")
|
||||
domain = strings.ToLower(domain)
|
||||
|
||||
countResp, err := this.RPC().DNSProviderRPC().CountAllEnabledDNSProviders(this.UserContext(), &pb.CountAllEnabledDNSProvidersRequest{
|
||||
UserId: this.UserId(),
|
||||
Keyword: params.Keyword,
|
||||
Domain: domain,
|
||||
Type: params.ProviderType,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
count := countResp.Count
|
||||
page := this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
providersResp, err := this.RPC().DNSProviderRPC().ListEnabledDNSProviders(this.UserContext(), &pb.ListEnabledDNSProvidersRequest{
|
||||
UserId: this.UserId(),
|
||||
Keyword: params.Keyword,
|
||||
Domain: domain,
|
||||
Type: params.ProviderType,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var providerMaps = []maps.Map{}
|
||||
for _, provider := range providersResp.DnsProviders {
|
||||
dataUpdatedTime := ""
|
||||
if provider.DataUpdatedAt > 0 {
|
||||
dataUpdatedTime = timeutil.FormatTime("Y-m-d H:i:s", provider.DataUpdatedAt)
|
||||
}
|
||||
|
||||
// 域名
|
||||
countDomainsResp, err := this.RPC().DNSDomainRPC().CountAllDNSDomainsWithDNSProviderId(this.UserContext(), &pb.CountAllDNSDomainsWithDNSProviderIdRequest{
|
||||
DnsProviderId: provider.Id,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
countDomains := countDomainsResp.Count
|
||||
|
||||
providerMaps = append(providerMaps, maps.Map{
|
||||
"id": provider.Id,
|
||||
"name": provider.Name,
|
||||
"type": provider.Type,
|
||||
"typeName": provider.TypeName,
|
||||
"dataUpdatedTime": dataUpdatedTime,
|
||||
"countDomains": countDomains,
|
||||
})
|
||||
}
|
||||
this.Data["providers"] = providerMaps
|
||||
|
||||
// 类型
|
||||
typesResponse, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.UserContext(), &pb.FindAllDNSProviderTypesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var providerTypeMaps = []maps.Map{}
|
||||
for _, providerType := range typesResponse.ProviderTypes {
|
||||
countProvidersWithTypeResp, err := this.RPC().DNSProviderRPC().CountAllEnabledDNSProviders(this.UserContext(), &pb.CountAllEnabledDNSProvidersRequest{
|
||||
Type: providerType.Code,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if countProvidersWithTypeResp.Count > 0 {
|
||||
providerTypeMaps = append(providerTypeMaps, maps.Map{
|
||||
"name": providerType.Name,
|
||||
"code": providerType.Code,
|
||||
"count": countProvidersWithTypeResp.Count,
|
||||
})
|
||||
}
|
||||
}
|
||||
this.Data["providerTypes"] = providerTypeMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
116
EdgeUser/internal/web/actions/default/dns/providers/provider.go
Normal file
116
EdgeUser/internal/web/actions/default/dns/providers/provider.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type ProviderAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ProviderAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ProviderAction) RunGet(params struct {
|
||||
ProviderId int64
|
||||
Page int
|
||||
Filter string
|
||||
}) {
|
||||
this.Data["pageNo"] = params.Page
|
||||
this.Data["filter"] = params.Filter
|
||||
|
||||
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.UserContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
provider := providerResp.DnsProvider
|
||||
if provider == nil {
|
||||
this.NotFound("dnsProvider", params.ProviderId)
|
||||
return
|
||||
}
|
||||
|
||||
apiParams := maps.Map{}
|
||||
if len(provider.ApiParamsJSON) > 0 {
|
||||
err = json.Unmarshal(provider.ApiParamsJSON, &apiParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 本地EdgeDNS相关
|
||||
localEdgeDNSMap, err := this.readEdgeDNS(provider, apiParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["provider"] = maps.Map{
|
||||
"id": provider.Id,
|
||||
"name": provider.Name,
|
||||
"type": provider.Type,
|
||||
"typeName": provider.TypeName,
|
||||
"apiParams": apiParams,
|
||||
"localEdgeDNS": localEdgeDNSMap,
|
||||
"minTTL": provider.MinTTL,
|
||||
}
|
||||
|
||||
// 域名数量
|
||||
countDomainsResp, err := this.RPC().DNSDomainRPC().CountAllDNSDomainsWithDNSProviderId(this.UserContext(), &pb.CountAllDNSDomainsWithDNSProviderIdRequest{
|
||||
DnsProviderId: params.ProviderId,
|
||||
IsDeleted: params.Filter == "deleted",
|
||||
IsDown: params.Filter == "down",
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countDomains = countDomainsResp.Count
|
||||
var page = this.NewPage(countDomains)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 域名
|
||||
domainsResp, err := this.RPC().DNSDomainRPC().ListBasicDNSDomainsWithDNSProviderId(this.UserContext(), &pb.ListBasicDNSDomainsWithDNSProviderIdRequest{
|
||||
DnsProviderId: provider.Id,
|
||||
IsDeleted: params.Filter == "deleted",
|
||||
IsDown: params.Filter == "down",
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
domainMaps := []maps.Map{}
|
||||
for _, domain := range domainsResp.DnsDomains {
|
||||
dataUpdatedTime := ""
|
||||
if domain.DataUpdatedAt > 0 {
|
||||
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,
|
||||
"isUp": domain.IsUp,
|
||||
"isDeleted": domain.IsDeleted,
|
||||
"dataUpdatedTime": dataUpdatedTime,
|
||||
"countRoutes": len(domain.Routes),
|
||||
"countServerRecords": domain.CountServerRecords,
|
||||
"serversChanged": domain.ServersChanged,
|
||||
"countNodeRecords": domain.CountNodeRecords,
|
||||
"nodesChanged": domain.NodesChanged,
|
||||
"countClusters": domain.CountNodeClusters,
|
||||
"countAllNodes": domain.CountAllNodes,
|
||||
"countAllServers": domain.CountAllServers,
|
||||
})
|
||||
}
|
||||
this.Data["domains"] = domainMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package providers
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
func (this *ProviderAction) readEdgeDNS(provider *pb.DNSProvider, apiParams maps.Map) (maps.Map, error) {
|
||||
var localEdgeDNSMap = maps.Map{}
|
||||
|
||||
if provider.Type == "localEdgeDNS" {
|
||||
nsClusterId := apiParams.GetInt64("clusterId")
|
||||
nsClusterResp, err := this.RPC().NSClusterRPC().FindNSCluster(this.UserContext(), &pb.FindNSClusterRequest{NsClusterId: nsClusterId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nsCluster := nsClusterResp.NsCluster
|
||||
if nsCluster != nil {
|
||||
localEdgeDNSMap = maps.Map{
|
||||
"id": nsCluster.Id,
|
||||
"name": nsCluster.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return localEdgeDNSMap, nil
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package providers
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
)
|
||||
|
||||
type SyncDomainsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SyncDomainsAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
resp, err := this.RPC().DNSDomainRPC().SyncDNSDomainsFromProvider(this.UserContext(), &pb.SyncDNSDomainsFromProviderRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.Fail("更新域名失败:" + err.Error())
|
||||
}
|
||||
|
||||
this.Data["hasChanges"] = resp.HasChanges
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
ProviderId int64
|
||||
}) {
|
||||
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.UserContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var provider = providerResp.DnsProvider
|
||||
if provider == nil {
|
||||
this.NotFound("dnsProvider", params.ProviderId)
|
||||
return
|
||||
}
|
||||
|
||||
var apiParams = maps.Map{}
|
||||
if len(provider.ApiParamsJSON) > 0 {
|
||||
err = json.Unmarshal(provider.ApiParamsJSON, &apiParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["provider"] = maps.Map{
|
||||
"id": provider.Id,
|
||||
"name": provider.Name,
|
||||
"type": provider.Type,
|
||||
"typeName": provider.TypeName,
|
||||
"minTTL": provider.MinTTL,
|
||||
"params": apiParams,
|
||||
}
|
||||
|
||||
// 所有厂商
|
||||
typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.UserContext(), &pb.FindAllDNSProviderTypesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var typeMaps = []maps.Map{}
|
||||
for _, t := range typesResp.ProviderTypes {
|
||||
typeMaps = append(typeMaps, maps.Map{
|
||||
"name": t.Name,
|
||||
"code": t.Code,
|
||||
"description": t.Description,
|
||||
})
|
||||
}
|
||||
this.Data["types"] = typeMaps
|
||||
|
||||
// EdgeDNS集群列表
|
||||
nsClustersResp, err := this.RPC().NSClusterRPC().FindAllNSClusters(this.UserContext(), &pb.FindAllNSClustersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var nsClusterMaps = []maps.Map{}
|
||||
for _, nsCluster := range nsClustersResp.NsClusters {
|
||||
nsClusterMaps = append(nsClusterMaps, maps.Map{
|
||||
"id": nsCluster.Id,
|
||||
"name": nsCluster.Name,
|
||||
})
|
||||
}
|
||||
this.Data["nsClusters"] = nsClusterMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
|
||||
Name string
|
||||
Type string
|
||||
|
||||
// DNSPod
|
||||
ParamDNSPodId string
|
||||
ParamDNSPodToken string
|
||||
ParamDNSPodRegion string
|
||||
|
||||
ParamDNSPodAPIType string
|
||||
ParamDNSPodAccessKeyId string
|
||||
ParamDNSPodAccessKeySecret string
|
||||
|
||||
// AliDNS
|
||||
ParamAliDNSAccessKeyId string
|
||||
ParamAliDNSAccessKeySecret string
|
||||
ParamAliDNSRegionId string
|
||||
|
||||
// HuaweiDNS
|
||||
ParamHuaweiAccessKeyId string
|
||||
ParamHuaweiAccessKeySecret string
|
||||
ParamHuaweiEndpoint string
|
||||
|
||||
// DNS.COM
|
||||
ParamApiKey string
|
||||
ParamApiSecret string
|
||||
|
||||
// CloudFlare
|
||||
ParamCloudFlareAPIKey string
|
||||
ParamCloudFlareEmail string
|
||||
|
||||
// GoDaddy
|
||||
ParamGoDaddyKey string
|
||||
ParamGoDaddySecret string
|
||||
|
||||
// ClouDNS
|
||||
ParamClouDNSAuthId string
|
||||
ParamClouDNSSubAuthId string
|
||||
ParamClouDNSAuthPassword string
|
||||
|
||||
// DNS.COM
|
||||
ParamDNSComKey string
|
||||
ParamDNSComSecret string
|
||||
|
||||
// DNS.LA
|
||||
ParamDNSLaAPIId string
|
||||
ParamDNSLaSecret string
|
||||
|
||||
// VolcEngine
|
||||
ParamVolcEngineAccessKeyId string
|
||||
ParamVolcEngineAccessKeySecret string
|
||||
|
||||
// Amazon Route 53
|
||||
ParamAmazonRoute53AccessKeyId string
|
||||
ParamAmazonRoute53AccessKeySecret string
|
||||
ParamAmazonRoute53Region string
|
||||
|
||||
// Microsoft Azure DNS
|
||||
ParamAzureDNSSubscriptionId string
|
||||
ParamAzureDNSTenantId string
|
||||
ParamAzureDNSClientId string
|
||||
ParamAzureDNSClientSecret string
|
||||
ParamAzureDNSResourceGroupName string
|
||||
|
||||
// bunny.net
|
||||
ParamBunnyNetAPIKey string
|
||||
|
||||
// Gname
|
||||
ParamGnameAppid string
|
||||
ParamGnameSecret string
|
||||
|
||||
// Local EdgeDNS
|
||||
ParamLocalEdgeDNSClusterId int64
|
||||
|
||||
// EdgeDNS API
|
||||
ParamEdgeDNSAPIHost string
|
||||
ParamEdgeDNSAPIRole string
|
||||
ParamEdgeDNSAPIAccessKeyId string
|
||||
ParamEdgeDNSAPIAccessKeySecret string
|
||||
|
||||
// CustomHTTP
|
||||
ParamCustomHTTPURL string
|
||||
ParamCustomHTTPSecret string
|
||||
|
||||
MinTTL int32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.DNSProvider_LogUpdateDNSProvider, params.ProviderId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入账号说明").
|
||||
Field("type", params.Type).
|
||||
Require("请选择服务商厂家")
|
||||
|
||||
var apiParams = maps.Map{}
|
||||
switch params.Type {
|
||||
case "dnspod":
|
||||
apiParams["apiType"] = params.ParamDNSPodAPIType
|
||||
switch params.ParamDNSPodAPIType {
|
||||
case "tencentDNS":
|
||||
params.Must.
|
||||
Field("paramDNSPodAccessKeyId", params.ParamDNSPodAccessKeyId).
|
||||
Require("请输入SecretId").
|
||||
Field("paramDNSPodAccessKeySecret", params.ParamDNSPodAccessKeySecret).
|
||||
Require("请输入SecretKey")
|
||||
apiParams["accessKeyId"] = params.ParamDNSPodAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamDNSPodAccessKeySecret
|
||||
apiParams["region"] = params.ParamDNSPodRegion
|
||||
default:
|
||||
params.Must.
|
||||
Field("paramId", params.ParamDNSPodId).
|
||||
Require("请输入密钥ID").
|
||||
Field("paramToken", params.ParamDNSPodToken).
|
||||
Require("请输入密钥Token")
|
||||
|
||||
apiParams["id"] = params.ParamDNSPodId
|
||||
apiParams["token"] = params.ParamDNSPodToken
|
||||
apiParams["region"] = params.ParamDNSPodRegion
|
||||
}
|
||||
case "alidns":
|
||||
params.Must.
|
||||
Field("paramAliDNSAccessKeyId", params.ParamAliDNSAccessKeyId).
|
||||
Require("请输入AccessKeyId").
|
||||
Field("paramAliDNSAccessKeySecret", params.ParamAliDNSAccessKeySecret).
|
||||
Require("请输入AccessKeySecret")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamAliDNSAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamAliDNSAccessKeySecret
|
||||
apiParams["regionId"] = params.ParamAliDNSRegionId
|
||||
case "huaweiDNS":
|
||||
params.Must.
|
||||
Field("paramHuaweiAccessKeyId", params.ParamHuaweiAccessKeyId).
|
||||
Require("请输入AccessKeyId").
|
||||
Field("paramHuaweiAccessKeySecret", params.ParamHuaweiAccessKeySecret).
|
||||
Require("请输入AccessKeySecret")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamHuaweiAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamHuaweiAccessKeySecret
|
||||
apiParams["endpoint"] = params.ParamHuaweiEndpoint
|
||||
case "cloudFlare":
|
||||
params.Must.
|
||||
Field("paramCloudFlareAPIKey", params.ParamCloudFlareAPIKey).
|
||||
Require("请输入API密钥").
|
||||
Field("paramCloudFlareEmail", params.ParamCloudFlareEmail).
|
||||
Email("请输入正确格式的邮箱地址")
|
||||
apiParams["apiKey"] = params.ParamCloudFlareAPIKey
|
||||
apiParams["email"] = params.ParamCloudFlareEmail
|
||||
case "godaddy":
|
||||
params.Must.
|
||||
Field("paramGodaddyKey", params.ParamGoDaddyKey).
|
||||
Require("请输入Key").
|
||||
Field("paramGodaddySecret", params.ParamGoDaddySecret).
|
||||
Require("请输入Secret")
|
||||
apiParams["key"] = params.ParamGoDaddyKey
|
||||
apiParams["secret"] = params.ParamGoDaddySecret
|
||||
case "cloudns":
|
||||
var authIdString = params.ParamClouDNSAuthId
|
||||
var subAuthIdString = params.ParamClouDNSSubAuthId
|
||||
var authPassword = params.ParamClouDNSAuthPassword
|
||||
if len(authIdString) == 0 && len(subAuthIdString) == 0 {
|
||||
this.FailField("paramClouDNSAuthId", "请输入用户或者子用户的认证ID(auth-id)")
|
||||
}
|
||||
if len(authIdString) > 0 {
|
||||
if !regexp.MustCompile(`^\d+$`).MatchString(authIdString) {
|
||||
this.FailField("paramClouDNSAuthId", "用户认证ID需要是一个整数")
|
||||
}
|
||||
}
|
||||
if len(subAuthIdString) > 0 {
|
||||
if !regexp.MustCompile(`^\d+$`).MatchString(subAuthIdString) {
|
||||
this.FailField("paramClouDNSSubAuthId", "子用户认证ID需要是一个整数")
|
||||
}
|
||||
}
|
||||
if len(authPassword) == 0 {
|
||||
this.FailField("paramClouDNSPassword", "请输入用户或者子用户的认证密码")
|
||||
}
|
||||
|
||||
apiParams["authId"] = types.Int64(authIdString)
|
||||
apiParams["subAuthId"] = types.Int64(subAuthIdString)
|
||||
apiParams["authPassword"] = authPassword
|
||||
case "dnscom":
|
||||
params.Must.
|
||||
Field("paramDNSComKey", params.ParamDNSComKey).
|
||||
Require("请输入ApiKey").
|
||||
Field("paramDNSComSecret", params.ParamDNSComSecret).
|
||||
Require("请输入ApiSecret")
|
||||
|
||||
apiParams["key"] = params.ParamDNSComKey
|
||||
apiParams["secret"] = params.ParamDNSComSecret
|
||||
case "dnsla":
|
||||
params.Must.
|
||||
Field("paramDNSLaAPIId", params.ParamDNSLaAPIId).
|
||||
Require("请输入API ID").
|
||||
Field("paramDNSLaSecret", params.ParamDNSLaSecret).
|
||||
Require("请输入API密钥")
|
||||
|
||||
apiParams["apiId"] = params.ParamDNSLaAPIId
|
||||
apiParams["secret"] = params.ParamDNSLaSecret
|
||||
case "volcEngine":
|
||||
params.Must.
|
||||
Field("paramVolcEngineAccessKeyId", params.ParamVolcEngineAccessKeyId).
|
||||
Require("请输入Access Key ID").
|
||||
Field("paramVolcEngineAccessKeySecret", params.ParamVolcEngineAccessKeySecret).
|
||||
Require("请输入Secret Access Key")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamVolcEngineAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamVolcEngineAccessKeySecret
|
||||
case "amazonRoute53":
|
||||
params.Must.
|
||||
Field("paramAmazonRoute53AccessKeyId", params.ParamAmazonRoute53AccessKeyId).
|
||||
Require("请输入Access Key ID").
|
||||
Field("paramAmazonRoute53AccessKeySecret", params.ParamAmazonRoute53AccessKeySecret).
|
||||
Require("请输入Secret Access Key")
|
||||
|
||||
apiParams["accessKeyId"] = params.ParamAmazonRoute53AccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamAmazonRoute53AccessKeySecret
|
||||
apiParams["region"] = params.ParamAmazonRoute53Region
|
||||
case "azureDNS":
|
||||
params.Must.
|
||||
Field("paramAzureDNSSubscriptionId", params.ParamAzureDNSSubscriptionId).
|
||||
Require("请输入Subscription ID").
|
||||
Field("paramAzureDNSTenantId", params.ParamAzureDNSTenantId).
|
||||
Require("请输入Tenant ID").
|
||||
Field("paramAzureDNSClientId", params.ParamAzureDNSClientId).
|
||||
Require("请输入Client ID").
|
||||
Field("paramAzureDNSClientSecret", params.ParamAzureDNSClientSecret).
|
||||
Require("请输入Client Secret").
|
||||
Field("paramAzureDNSResourceGroupName", params.ParamAzureDNSResourceGroupName).
|
||||
Require("请输入Resource Group Name")
|
||||
|
||||
apiParams["subscriptionId"] = params.ParamAzureDNSSubscriptionId
|
||||
apiParams["tenantId"] = params.ParamAzureDNSTenantId
|
||||
apiParams["clientId"] = params.ParamAzureDNSClientId
|
||||
apiParams["clientSecret"] = params.ParamAzureDNSClientSecret
|
||||
apiParams["resourceGroupName"] = params.ParamAzureDNSResourceGroupName
|
||||
case "bunnyNet":
|
||||
params.Must.
|
||||
Field("paramBunnyNetAPIKey", params.ParamBunnyNetAPIKey).
|
||||
Require("请输入API密钥")
|
||||
apiParams["apiKey"] = params.ParamBunnyNetAPIKey
|
||||
case "gname":
|
||||
params.Must.
|
||||
Field("paramGnameAppid", params.ParamGnameAppid).
|
||||
Require("请输入APPID").
|
||||
Field("paramGnameSecret", params.ParamGnameSecret).
|
||||
Require("请输入API Secret")
|
||||
apiParams["appid"] = params.ParamGnameAppid
|
||||
apiParams["secret"] = params.ParamGnameSecret
|
||||
case "localEdgeDNS":
|
||||
params.Must.
|
||||
Field("paramLocalEdgeDNSClusterId", params.ParamLocalEdgeDNSClusterId).
|
||||
Gt(0, "请选择域名服务集群")
|
||||
apiParams["clusterId"] = params.ParamLocalEdgeDNSClusterId
|
||||
case "edgeDNSAPI":
|
||||
params.Must.
|
||||
Field("paramEdgeDNSAPIHost", params.ParamEdgeDNSAPIHost).
|
||||
Require("请输入API地址").
|
||||
Field("paramEdgeDNSAPIRole", params.ParamEdgeDNSAPIRole).
|
||||
Require("请选择AccessKey类型").
|
||||
Field("paramEdgeDNSAPIAccessKeyId", params.ParamEdgeDNSAPIAccessKeyId).
|
||||
Require("请输入AccessKey ID").
|
||||
Field("paramEdgeDNSAPIAccessKeySecret", params.ParamEdgeDNSAPIAccessKeySecret).
|
||||
Require("请输入AccessKey密钥")
|
||||
apiParams["host"] = params.ParamEdgeDNSAPIHost
|
||||
apiParams["role"] = params.ParamEdgeDNSAPIRole
|
||||
apiParams["accessKeyId"] = params.ParamEdgeDNSAPIAccessKeyId
|
||||
apiParams["accessKeySecret"] = params.ParamEdgeDNSAPIAccessKeySecret
|
||||
case "customHTTP":
|
||||
params.Must.
|
||||
Field("paramCustomHTTPURL", params.ParamCustomHTTPURL).
|
||||
Require("请输入HTTP URL").
|
||||
Match("^(?i)(http|https):", "URL必须以http://或者https://开头").
|
||||
Field("paramCustomHTTPSecret", params.ParamCustomHTTPSecret).
|
||||
Require("请输入私钥")
|
||||
apiParams["url"] = params.ParamCustomHTTPURL
|
||||
apiParams["secret"] = params.ParamCustomHTTPSecret
|
||||
default:
|
||||
this.Fail("暂时不支持此服务商'" + params.Type + "'")
|
||||
}
|
||||
|
||||
_, err := this.RPC().DNSProviderRPC().UpdateDNSProvider(this.UserContext(), &pb.UpdateDNSProviderRequest{
|
||||
DnsProviderId: params.ProviderId,
|
||||
Name: params.Name,
|
||||
MinTTL: params.MinTTL,
|
||||
ApiParamsJSON: apiParams.AsJSON(),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user