Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,300 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ClusterAction struct {
actionutils.ParentAction
}
func (this *ClusterAction) Init() {
this.Nav("", "", "")
}
func (this *ClusterAction) RunGet(params struct {
ClusterId int64
}) {
// 集群信息
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
var cluster = clusterResp.NodeCluster
if cluster == nil {
this.NotFound("nodeCluster", params.ClusterId)
return
}
this.Data["cluster"] = maps.Map{
"id": cluster.Id,
"name": cluster.Name,
}
// DNS信息
dnsResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
var defaultRoute = dnsResp.DefaultRoute
var domainName = ""
var dnsMap = maps.Map{
"dnsName": dnsResp.Name,
"domainId": 0,
"domainName": "",
"providerId": 0,
"providerName": "",
"providerTypeName": "",
}
if dnsResp.Domain != nil {
domainName = dnsResp.Domain.Name
dnsMap["domainId"] = dnsResp.Domain.Id
dnsMap["domainName"] = dnsResp.Domain.Name
}
if dnsResp.Provider != nil {
dnsMap["providerId"] = dnsResp.Provider.Id
dnsMap["providerName"] = dnsResp.Provider.Name
dnsMap["providerTypeName"] = dnsResp.Provider.TypeName
}
if len(dnsResp.CnameRecords) > 0 {
dnsMap["cnameRecords"] = dnsResp.CnameRecords
} else {
dnsMap["cnameRecords"] = []string{}
}
this.Data["dnsInfo"] = dnsMap
// 未安装的节点
notInstalledNodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesDNSWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledNodesDNSWithNodeClusterIdRequest{
NodeClusterId: params.ClusterId,
IsInstalled: false,
})
if err != nil {
this.ErrorPage(err)
return
}
var allNodes = notInstalledNodesResp.Nodes
// 节点DNS解析记录
nodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesDNSWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledNodesDNSWithNodeClusterIdRequest{
NodeClusterId: params.ClusterId,
IsInstalled: true,
})
if err != nil {
this.ErrorPage(err)
return
}
var installedNodeIdsMap = map[int64]bool{}
for _, node := range nodesResp.Nodes {
installedNodeIdsMap[node.Id] = true
}
allNodes = append(allNodes, nodesResp.Nodes...)
var nodeMaps = []maps.Map{}
for _, node := range allNodes {
var isInstalled = installedNodeIdsMap[node.Id]
if len(node.Routes) > 0 {
for _, route := range node.Routes {
// 检查是否已解析
var isResolved = false
if isInstalled && cluster.DnsDomainId > 0 && len(cluster.DnsName) > 0 && len(node.IpAddr) > 0 {
var recordType = "A"
if iputils.IsIPv6(node.IpAddr) {
recordType = "AAAA"
}
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.AdminContext(), &pb.ExistDNSDomainRecordRequest{
DnsDomainId: cluster.DnsDomainId,
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,
"ipAddrId": node.NodeIPAddressId,
"route": maps.Map{
"name": route.Name,
"code": route.Code,
},
"clusterId": node.NodeClusterId,
"isResolved": isResolved,
"isInstalled": isInstalled,
"isBackup": node.IsBackupForCluster || node.IsBackupForGroup,
"isOffline": node.IsOffline,
})
}
} else {
// 默认线路
var isResolved = false
if isInstalled && len(defaultRoute) > 0 {
var recordType = "A"
if iputils.IsIPv6(node.IpAddr) {
recordType = "AAAA"
}
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.AdminContext(), &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,
"ipAddrId": node.NodeIPAddressId,
"route": maps.Map{
"name": "",
"code": "",
},
"clusterId": node.NodeClusterId,
"isResolved": isResolved,
"isInstalled": isInstalled,
"isBackup": node.IsBackupForCluster || node.IsBackupForGroup,
"isOffline": node.IsOffline,
})
}
}
this.Data["nodes"] = nodeMaps
// 代理服务解析记录
serversResp, err := this.RPC().ServerRPC().FindAllEnabledServersDNSWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledServersDNSWithNodeClusterIdRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
var serverMaps = []maps.Map{}
for _, server := range serversResp.Servers {
// 检查是否已解析
isResolved := false
if cluster.DnsDomainId > 0 && len(cluster.DnsName) > 0 && len(server.DnsName) > 0 && len(domainName) > 0 {
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.AdminContext(), &pb.ExistDNSDomainRecordRequest{
DnsDomainId: cluster.DnsDomainId,
Name: server.DnsName,
Type: "CNAME",
Value: cluster.DnsName + "." + domainName,
})
if err != nil {
this.ErrorPage(err)
return
}
isResolved = checkResp.IsOk
}
serverMaps = append(serverMaps, maps.Map{
"id": server.Id,
"name": server.Name,
"dnsName": server.DnsName,
"isResolved": isResolved,
})
}
this.Data["servers"] = serverMaps
// 检查解析记录是否有变化
checkChangesResp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSChanges(this.AdminContext(), &pb.CheckNodeClusterDNSChangesRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["dnsHasChanges"] = checkChangesResp.IsChanged
// 需要解决的问题
issuesResp, err := this.RPC().DNSRPC().FindAllDNSIssues(this.AdminContext(), &pb.FindAllDNSIssuesRequest{
NodeClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
var issueMaps = []maps.Map{}
for _, issue := range issuesResp.Issues {
issueMaps = append(issueMaps, maps.Map{
"target": issue.Target,
"targetId": issue.TargetId,
"type": issue.Type,
"description": issue.Description,
"params": issue.Params,
})
}
this.Data["issues"] = issueMaps
// 当前正在执行的任务
resp, err := this.RPC().DNSTaskRPC().FindAllDoingDNSTasks(this.AdminContext(), &pb.FindAllDoingDNSTasksRequest{
NodeClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
var taskMaps = []maps.Map{}
for _, task := range resp.DnsTasks {
var clusterMap maps.Map = nil
var nodeMap maps.Map = nil
var serverMap maps.Map = nil
var domainMap maps.Map = nil
if task.NodeCluster != nil {
clusterMap = maps.Map{
"id": task.NodeCluster.Id,
"name": task.NodeCluster.Name,
}
}
if task.Node != nil {
nodeMap = maps.Map{
"id": task.Node.Id,
"name": task.Node.Name,
}
}
if task.Server != nil {
serverMap = maps.Map{
"id": task.Server.Id,
"name": task.Server.Name,
}
}
if task.DnsDomain != nil {
domainMap = maps.Map{
"id": task.DnsDomain.Id,
"name": task.DnsDomain.Name,
}
}
taskMaps = append(taskMaps, maps.Map{
"id": task.Id,
"type": task.Type,
"isDone": task.IsDone,
"isOk": task.IsOk,
"error": task.Error,
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", task.UpdatedAt),
"cluster": clusterMap,
"node": nodeMap,
"server": serverMap,
"domain": domainMap,
})
}
this.Data["tasks"] = taskMaps
this.Show()
}

View File

@@ -0,0 +1,46 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type SyncAction struct {
actionutils.ParentAction
}
func (this *SyncAction) RunPost(params struct {
ClusterId int64
}) {
// 记录日志
defer this.CreateLogInfo(codes.DNS_LogSyncCluster, params.ClusterId)
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
domain := dnsInfoResp.Domain
if domain == nil || domain.Id <= 0 {
this.Fail("此集群尚未设置域名")
}
syncResp, err := this.RPC().DNSDomainRPC().SyncDNSDomainData(this.AdminContext(), &pb.SyncDNSDomainDataRequest{
DnsDomainId: domain.Id,
NodeClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
if syncResp.ShouldFix {
this.Fail("请先修改当前页面中红色标记的问题")
}
if !syncResp.IsOk {
this.Fail(syncResp.Error)
}
this.Success()
}

View File

@@ -0,0 +1,48 @@
package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"sort"
)
// DomainOptionsAction 域名列表选项
type DomainOptionsAction struct {
actionutils.ParentAction
}
func (this *DomainOptionsAction) RunPost(params struct {
ProviderId int64
}) {
domainsResp, err := this.RPC().DNSDomainRPC().FindAllBasicDNSDomainsWithDNSProviderId(this.AdminContext(), &pb.FindAllBasicDNSDomainsWithDNSProviderIdRequest{
DnsProviderId: params.ProviderId,
})
if err != nil {
this.ErrorPage(err)
return
}
// 排序
if len(domainsResp.DnsDomains) > 0 {
sort.Slice(domainsResp.DnsDomains, func(i, j int) bool {
return domainsResp.DnsDomains[i].Name < domainsResp.DnsDomains[j].Name
})
}
var domainMaps = []maps.Map{}
for _, domain := range domainsResp.DnsDomains {
// 未开启或者已删除的先跳过
if !domain.IsOn || domain.IsDeleted || !domain.IsUp {
continue
}
domainMaps = append(domainMaps, maps.Map{
"id": domain.Id,
"name": domain.Name,
})
}
this.Data["domains"] = domainMaps
this.Success()
}

View File

@@ -0,0 +1,73 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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()
}

View File

@@ -0,0 +1,60 @@
package domains
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/langs/codes"
"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
}
defer this.CreateLogInfo(codes.DNS_LogCreateDomain, createResp.DnsDomainId)
this.Success()
}

View File

@@ -0,0 +1,38 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
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.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()
}

View File

@@ -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
}

View File

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

View File

@@ -0,0 +1,146 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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()
}

View File

@@ -0,0 +1,27 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
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.AdminContext(), &pb.RecoverDNSDomainRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,35 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &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()
}

View File

@@ -0,0 +1,105 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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()
}

View File

@@ -0,0 +1,85 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &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.AdminContext(), &pb.FindAllEnabledNodeClustersWithDNSDomainIdRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
for _, cluster := range clustersResp.NodeClusters {
serversResp, err := this.RPC().ServerRPC().FindAllEnabledServersDNSWithNodeClusterId(this.AdminContext(), &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.AdminContext(), &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()
}

View File

@@ -0,0 +1,33 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
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.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

@@ -0,0 +1,79 @@
package domains
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/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &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.AdminContext(), &pb.UpdateDNSDomainRequest{
DnsDomainId: params.DomainId,
Name: domain,
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View 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"
}

View File

@@ -0,0 +1,87 @@
package dns
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
}
func (this *IndexAction) Init() {
this.Nav("dns", "dns", "")
}
func (this *IndexAction) RunGet(params struct {
Keyword string
}) {
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &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.AdminContext(), &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.AdminContext(), &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.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

@@ -0,0 +1,65 @@
package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/clusters"
"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"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeDNS)).
Helper(new(Helper)).
Prefix("/dns").
Data("teaSubMenu", "cluster").
Get("", new(IndexAction)).
GetPost("/updateClusterPopup", new(UpdateClusterPopupAction)).
Post("/providerOptions", new(ProviderOptionsAction)).
Post("/domainOptions", new(DomainOptionsAction)).
// 集群
Prefix("/dns/clusters").
Get("/cluster", new(clusters.ClusterAction)).
Post("/sync", new(clusters.SyncAction)).
// 服务商
Prefix("/dns/providers").
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().
// 问题修复
Prefix("/dns/issues").
Data("teaSubMenu", "issue").
GetPost("", new(issues.IndexAction)).
GetPost("/updateNodePopup", new(issues.UpdateNodePopupAction)).
Post("/syncDomain", new(issues.SyncDomainAction)).
EndData().
EndAll()
})
}

View File

@@ -0,0 +1,41 @@
package issues
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
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
this.Data["issues"] = []interface{}{}
this.Show()
}
func (this *IndexAction) RunPost(params struct{}) {
issuesResp, err := this.RPC().DNSRPC().FindAllDNSIssues(this.AdminContext(), &pb.FindAllDNSIssuesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
issueMaps := []maps.Map{}
for _, issue := range issuesResp.Issues {
issueMaps = append(issueMaps, maps.Map{
"target": issue.Target,
"targetId": issue.TargetId,
"type": issue.Type,
"description": issue.Description,
"params": issue.Params,
})
}
this.Data["issues"] = issueMaps
this.Success()
}

View File

@@ -0,0 +1,33 @@
package issues
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type SyncDomainAction struct {
actionutils.ParentAction
}
func (this *SyncDomainAction) RunPost(params struct {
DomainId int64
}) {
// 记录日志
defer this.CreateLogInfo(codes.DNS_LogSyncDomain, 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

@@ -0,0 +1,122 @@
package issues
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net"
)
type UpdateNodePopupAction struct {
actionutils.ParentAction
}
func (this *UpdateNodePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdateNodePopupAction) RunGet(params struct {
ClusterId int64
NodeId int64
IpAddrId int64
}) {
this.Data["nodeId"] = params.NodeId
dnsInfoResp, err := this.RPC().NodeRPC().FindEnabledNodeDNS(this.AdminContext(), &pb.FindEnabledNodeDNSRequest{
NodeId: params.NodeId,
NodeClusterId: params.ClusterId,
NodeIPAddrId: params.IpAddrId,
})
if err != nil {
this.ErrorPage(err)
return
}
dnsInfo := dnsInfoResp.Node
if dnsInfo == nil {
this.NotFound("node", params.NodeId)
return
}
this.Data["ipAddr"] = dnsInfo.IpAddr
this.Data["ipAddrId"] = dnsInfo.NodeIPAddressId
this.Data["routes"] = domainutils.ConvertRoutesToMaps(dnsInfo)
this.Data["domainId"] = dnsInfo.DnsDomainId
this.Data["domainName"] = dnsInfo.DnsDomainName
// 读取所有线路
var allRouteMaps = []maps.Map{}
if dnsInfo.DnsDomainId > 0 {
routesResp, err := this.RPC().DNSDomainRPC().FindAllDNSDomainRoutes(this.AdminContext(), &pb.FindAllDNSDomainRoutesRequest{DnsDomainId: dnsInfo.DnsDomainId})
if err != nil {
this.ErrorPage(err)
return
}
if len(routesResp.Routes) > 0 {
for _, route := range routesResp.Routes {
allRouteMaps = append(allRouteMaps, maps.Map{
"name": route.Name,
"code": route.Code,
"domainName": dnsInfo.DnsDomainName,
"domainId": dnsInfo.DnsDomainId,
})
}
// 筛选
var routes = domainutils.FilterRoutes(dnsInfo.Routes, routesResp.Routes)
dnsInfo.Routes = routes
this.Data["routes"] = domainutils.ConvertRoutesToMaps(dnsInfo)
}
}
this.Data["allRoutes"] = allRouteMaps
this.Show()
}
func (this *UpdateNodePopupAction) RunPost(params struct {
NodeId int64
IpAddr string
IpAddrId int64
DomainId int64
DnsRoutesJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 操作日志
defer this.CreateLogInfo(codes.DNS_LogUpdateNodeDNS, params.NodeId)
var routes = []string{}
if len(params.DnsRoutesJSON) > 0 {
err := json.Unmarshal(params.DnsRoutesJSON, &routes)
if err != nil {
this.ErrorPage(err)
return
}
}
params.Must.
Field("ipAddr", params.IpAddr).
Require("请输入IP地址")
if net.ParseIP(params.IpAddr) == nil {
this.FailField("ipAddr", "请输入正确的IP地址")
}
// 执行修改
_, err := this.RPC().NodeRPC().UpdateNodeDNS(this.AdminContext(), &pb.UpdateNodeDNSRequest{
NodeId: params.NodeId,
IpAddr: params.IpAddr,
NodeIPAddressId: params.IpAddrId,
DnsDomainId: params.DomainId,
Routes: routes,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

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

@@ -0,0 +1,192 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build !plus
package providers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
// 所有厂商
typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &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集群列表
this.Data["nsClusters"] = []maps.Map{}
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
// CustomHTTP
ParamCustomHTTPURL string
ParamCustomHTTPSecret string
// EdgeDNS API
ParamEdgeDNSAPIRole string
ParamEdgeDNSAPIHost string
ParamEdgeDNSAPIAccessKeyId string
ParamEdgeDNSAPIAccessKeySecret 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 "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.AdminContext(), &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()
}

View File

@@ -0,0 +1,354 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package providers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"regexp"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
// 所有厂商
typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &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.AdminContext(), &pb.FindAllNSClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
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", "请输入用户或者子用户的认证IDauth-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.AdminContext(), &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()
}

View File

@@ -0,0 +1,50 @@
package providers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
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.AdminContext(), &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.AdminContext(), &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.AdminContext(), &pb.DeleteDNSProviderRequest{DnsProviderId: params.ProviderId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,114 @@
package providers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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("", "", "")
}
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 = params.Domain
domain = regexp.MustCompile(`^(www\.)`).ReplaceAllString(domain, "")
domain = strings.ToLower(domain)
countResp, err := this.RPC().DNSProviderRPC().CountAllEnabledDNSProviders(this.AdminContext(), &pb.CountAllEnabledDNSProvidersRequest{
AdminId: this.AdminId(),
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.AdminContext(), &pb.ListEnabledDNSProvidersRequest{
AdminId: this.AdminId(),
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 {
var dataUpdatedTime = ""
if provider.DataUpdatedAt > 0 {
dataUpdatedTime = timeutil.FormatTime("Y-m-d H:i:s", provider.DataUpdatedAt)
}
// 域名
countDomainsResp, err := this.RPC().DNSDomainRPC().CountAllDNSDomainsWithDNSProviderId(this.AdminContext(), &pb.CountAllDNSDomainsWithDNSProviderIdRequest{
DnsProviderId: provider.Id,
})
if err != nil {
this.ErrorPage(err)
return
}
var 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.AdminContext(), &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.AdminContext(), &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()
}

View File

@@ -0,0 +1,119 @@
package providers
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &pb.FindEnabledDNSProviderRequest{
DnsProviderId: params.ProviderId,
MaskParams: true,
})
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
}
}
// 本地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,
"minTTL": provider.MinTTL,
"apiParams": apiParams,
"localEdgeDNS": localEdgeDNSMap,
}
// 域名数量
countDomainsResp, err := this.RPC().DNSDomainRPC().CountAllDNSDomainsWithDNSProviderId(this.AdminContext(), &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.AdminContext(), &pb.ListBasicDNSDomainsWithDNSProviderIdRequest{
DnsProviderId: params.ProviderId,
IsDeleted: params.Filter == "deleted",
IsDown: params.Filter == "down",
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var 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()
}

View File

@@ -0,0 +1,13 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build !plus
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) {
return maps.Map{}, nil
}

View File

@@ -0,0 +1,30 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
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.AdminContext(), &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
}

View File

@@ -0,0 +1,25 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package providers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type SyncDomainsAction struct {
actionutils.ParentAction
}
func (this *SyncDomainsAction) RunPost(params struct {
ProviderId int64
}) {
resp, err := this.RPC().DNSDomainRPC().SyncDNSDomainsFromProvider(this.AdminContext(), &pb.SyncDNSDomainsFromProviderRequest{DnsProviderId: params.ProviderId})
if err != nil {
this.Fail("更新域名失败:" + err.Error())
}
this.Data["hasChanges"] = resp.HasChanges
this.Success()
}

View File

@@ -0,0 +1,223 @@
//go:build !plus
package providers
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
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.AdminContext(), &pb.FindEnabledDNSProviderRequest{
DnsProviderId: params.ProviderId,
MaskParams: true,
})
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
}
}
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.AdminContext(), &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
// EdgeDNS集群列表
this.Data["nsClusters"] = []maps.Map{}
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
// CloudFlare
ParamCloudFlareAPIKey string
ParamCloudFlareEmail string
// CustomHTTP
ParamCustomHTTPURL string
ParamCustomHTTPSecret string
// EdgeDNS API
ParamEdgeDNSAPIHost string
ParamEdgeDNSAPIRole string
ParamEdgeDNSAPIAccessKeyId string
ParamEdgeDNSAPIAccessKeySecret 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 "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.AdminContext(), &pb.UpdateDNSProviderRequest{
DnsProviderId: params.ProviderId,
Name: params.Name,
MinTTL: params.MinTTL,
ApiParamsJSON: apiParams.AsJSON(),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,389 @@
//go:build plus
package providers
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"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.AdminContext(), &pb.FindEnabledDNSProviderRequest{
DnsProviderId: params.ProviderId,
MaskParams: true,
})
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.AdminContext(), &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.AdminContext(), &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", "请输入用户或者子用户的认证IDauth-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.AdminContext(), &pb.UpdateDNSProviderRequest{
DnsProviderId: params.ProviderId,
Name: params.Name,
MinTTL: params.MinTTL,
ApiParamsJSON: apiParams.AsJSON(),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,41 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"time"
)
type CheckAction struct {
actionutils.ParentAction
}
func (this *CheckAction) RunPost(params struct {
IsDoing bool
HasError bool
IsUpdated bool
}) {
var isStream = this.Request.ProtoMajor >= 2
this.Data["isStream"] = isStream
var maxTries = 10
for i := 0; i < maxTries; i++ {
resp, err := this.RPC().DNSTaskRPC().ExistsDNSTasks(this.AdminContext(), &pb.ExistsDNSTasksRequest{})
if err != nil {
this.ErrorPage(err)
return
}
// 如果没有数据变化,继续查询
if i < maxTries-1 && params.IsUpdated && resp.ExistTasks == params.IsDoing && resp.ExistError == params.HasError && isStream {
time.Sleep(3 * time.Second)
continue
}
this.Data["isDoing"] = resp.ExistTasks
this.Data["hasError"] = resp.ExistError
break
}
this.Success()
}

View File

@@ -0,0 +1,25 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
TaskId int64
}) {
defer this.CreateLogInfo(codes.DNSTask_LogDeleteDNSTask, params.TaskId)
_, err := this.RPC().DNSTaskRPC().DeleteDNSTask(this.AdminContext(), &pb.DeleteDNSTaskRequest{DnsTaskId: params.TaskId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,25 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAllAction struct {
actionutils.ParentAction
}
func (this *DeleteAllAction) RunPost(params struct{}) {
defer this.CreateLogInfo(codes.DNSTask_LogDeleteAllDNSTasks)
_, err := this.RPC().DNSTaskRPC().DeleteAllDNSTasks(this.AdminContext(), &pb.DeleteAllDNSTasksRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,22 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeDNS)).
Helper(clusterutils.NewClustersHelper()).
Prefix("/dns/tasks").
GetPost("/listPopup", new(ListPopupAction)).
Post("/check", new(CheckAction)).
Post("/delete", new(DeleteAction)).
Post("/deleteAll", new(DeleteAllAction)).
EndAll()
})
}

View File

@@ -0,0 +1,84 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ListPopupAction struct {
actionutils.ParentAction
}
func (this *ListPopupAction) Init() {
this.Nav("", "", "")
}
func (this *ListPopupAction) RunGet(params struct{}) {
this.retrieveTasks()
this.Show()
}
func (this *ListPopupAction) RunPost(params struct {
Must *actions.Must
}) {
this.retrieveTasks()
this.Success()
}
func (this *ListPopupAction) retrieveTasks() {
resp, err := this.RPC().DNSTaskRPC().FindAllDoingDNSTasks(this.AdminContext(), &pb.FindAllDoingDNSTasksRequest{})
if err != nil {
this.ErrorPage(err)
return
}
taskMaps := []maps.Map{}
for _, task := range resp.DnsTasks {
var clusterMap maps.Map = nil
var nodeMap maps.Map = nil
var serverMap maps.Map = nil
var domainMap maps.Map = nil
if task.NodeCluster != nil {
clusterMap = maps.Map{
"id": task.NodeCluster.Id,
"name": task.NodeCluster.Name,
}
}
if task.Node != nil {
nodeMap = maps.Map{
"id": task.Node.Id,
"name": task.Node.Name,
}
}
if task.Server != nil {
serverMap = maps.Map{
"id": task.Server.Id,
"name": task.Server.Name,
}
}
if task.DnsDomain != nil {
domainMap = maps.Map{
"id": task.DnsDomain.Id,
"name": task.DnsDomain.Name,
}
}
taskMaps = append(taskMaps, maps.Map{
"id": task.Id,
"type": task.Type,
"isDone": task.IsDone,
"isOk": task.IsOk,
"error": task.Error,
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", task.UpdatedAt),
"cluster": clusterMap,
"node": nodeMap,
"server": serverMap,
"domain": domainMap,
})
}
this.Data["tasks"] = taskMaps
}

View File

@@ -0,0 +1,131 @@
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/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
// UpdateClusterPopupAction 修改集群的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
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["dnsName"] = dnsInfoResp.Name
this.Data["nodesAutoSync"] = dnsInfoResp.NodesAutoSync
this.Data["serversAutoSync"] = dnsInfoResp.ServersAutoSync
if dnsInfoResp.Domain != nil {
this.Data["domainId"] = dnsInfoResp.Domain.Id
this.Data["domain"] = dnsInfoResp.Domain.Name
} else {
this.Data["domainId"] = 0
this.Data["domain"] = ""
}
if dnsInfoResp.Provider != nil {
this.Data["providerType"] = dnsInfoResp.Provider.Type
this.Data["providerId"] = dnsInfoResp.Provider.Id
} else {
this.Data["providerType"] = ""
this.Data["providerId"] = 0
}
if len(dnsInfoResp.CnameRecords) == 0 {
this.Data["cnameRecords"] = []string{}
} else {
this.Data["cnameRecords"] = dnsInfoResp.CnameRecords
}
this.Data["ttl"] = dnsInfoResp.Ttl
this.Data["cnameAsDomain"] = dnsInfoResp.CnameAsDomain
this.Data["includingLnNodes"] = dnsInfoResp.IncludingLnNodes
// 所有服务商
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
NodesAutoSync bool
ServersAutoSync bool
CnameRecords []string
Ttl int32
CnameAsDomain bool
IncludingLnNodes bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 日志
defer this.CreateLogInfo(codes.DNS_LogUpdateClusterDNS, params.ClusterId)
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,
NodesAutoSync: params.NodesAutoSync,
ServersAutoSync: params.ServersAutoSync,
CnameRecords: params.CnameRecords,
Ttl: params.Ttl,
CnameAsDomain: params.CnameAsDomain,
IncludingLnNodes: params.IncludingLnNodes,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}