可以修改节点的DNS设置

This commit is contained in:
刘祥超
2020-11-14 09:42:21 +08:00
parent 8b749fbc60
commit cc6123884d
10 changed files with 332 additions and 2 deletions

View File

@@ -0,0 +1,85 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
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{ClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
cluster := clusterResp.Cluster
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
}
dnsMap := maps.Map{
"dnsName": dnsResp.Name,
"domainId": 0,
"domainName": "",
"providerId": 0,
"providerName": "",
"providerTypeName": "",
}
if dnsResp.Domain != nil {
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
}
this.Data["dnsInfo"] = dnsMap
// 节点DNS解析记录
nodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesDNSWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodesDNSWithClusterIdRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
nodeMaps := []maps.Map{}
for _, node := range nodesResp.Nodes {
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"ipAddr": node.IpAddr,
"route": node.Route,
})
}
this.Data["nodes"] = nodeMaps
// 代理服务解析记录
// TODO
this.Data["servers"] = []interface{}{}
this.Show()
}

View File

@@ -1,6 +1,7 @@
package dns
import (
"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"
@@ -19,6 +20,10 @@ func init() {
Post("/providerOptions", new(ProviderOptionsAction)).
Post("/domainOptions", new(DomainOptionsAction)).
// 集群
Prefix("/dns/clusters").
Get("/cluster", new(clusters.ClusterAction)).
// 服务商
Prefix("/dns/providers").
Data("teaSubMenu", "provider").
@@ -43,6 +48,8 @@ func init() {
Prefix("/dns/issues").
Data("teaSubMenu", "issue").
Get("", new(issues.IndexAction)).
GetPost("/updateNodePopup", new(issues.UpdateNodePopupAction)).
GetPost("/updateServerPopup", new(issues.UpdateServerPopupAction)).
EndData().
EndAll()

View File

@@ -0,0 +1,93 @@
package issues
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists"
"net"
)
type UpdateNodePopupAction struct {
actionutils.ParentAction
}
func (this *UpdateNodePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdateNodePopupAction) RunGet(params struct {
NodeId int64
}) {
this.Data["nodeId"] = params.NodeId
dnsInfoResp, err := this.RPC().NodeRPC().FindEnabledNodeDNS(this.AdminContext(), &pb.FindEnabledNodeDNSRequest{NodeId: params.NodeId})
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["route"] = dnsInfo.Route
this.Data["domainId"] = dnsInfo.DnsDomainId
// 读取所有线路
routes := []string{}
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 {
routes = routesResp.Routes
}
}
this.Data["routes"] = routes
if len(routes) > 0 && !lists.ContainsString(routes, dnsInfo.Route) {
this.Data["route"] = routes[0]
}
this.Show()
}
func (this *UpdateNodePopupAction) RunPost(params struct {
NodeId int64
IpAddr string
DomainId int64
Route string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 操作日志
this.CreateLog(oplogs.LevelInfo, "修改节点 %d 的DNS设置", params.NodeId)
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,
DnsDomainId: params.DomainId,
Route: params.Route,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

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

View File

@@ -1,6 +1,7 @@
package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
@@ -69,6 +70,9 @@ func (this *UpdateClusterPopupAction) RunPost(params struct {
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 日志
this.CreateLog(oplogs.LevelInfo, "修改集群 %d DNS设置", params.ClusterId)
params.Must.
Field("dnsName", params.DnsName).
Require("请输入子域名")