diff --git a/internal/web/actions/default/clusters/cluster/init.go b/internal/web/actions/default/clusters/cluster/init.go index 28e5d99d..86d6407f 100644 --- a/internal/web/actions/default/clusters/cluster/init.go +++ b/internal/web/actions/default/clusters/cluster/init.go @@ -47,6 +47,7 @@ func init() { Get("/thresholds", new(thresholds.IndexAction)). Get("/detail", new(node.DetailAction)). GetPost("/boards", new(nodeboards.IndexAction)). + GetPost("/updateDNSPopup", new(node.UpdateDNSPopupAction)). // 分组相关 Prefix("/clusters/cluster/groups"). diff --git a/internal/web/actions/default/clusters/cluster/node/updateDNSPopup.go b/internal/web/actions/default/clusters/cluster/node/updateDNSPopup.go new file mode 100644 index 00000000..0ff7e41a --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/node/updateDNSPopup.go @@ -0,0 +1,115 @@ +package node + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" + "net" +) + +type UpdateDNSPopupAction struct { + actionutils.ParentAction +} + +func (this *UpdateDNSPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *UpdateDNSPopupAction) RunGet(params struct { + ClusterId int64 + NodeId int64 +}) { + this.Data["nodeId"] = params.NodeId + + dnsInfoResp, err := this.RPC().NodeRPC().FindEnabledNodeDNS(this.AdminContext(), &pb.FindEnabledNodeDNSRequest{ + NodeId: params.NodeId, + NodeClusterId: params.ClusterId, + }) + 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["routes"] = domainutils.ConvertRoutesToMaps(dnsInfo) + this.Data["domainId"] = dnsInfo.DnsDomainId + this.Data["domainName"] = dnsInfo.DnsDomainName + + // 读取所有线路 + 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 *UpdateDNSPopupAction) RunPost(params struct { + NodeId int64 + IpAddr string + DomainId int64 + DnsRoutesJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + // 操作日志 + defer this.CreateLog(oplogs.LevelInfo, "修改节点 %d 的DNS设置", params.NodeId) + + routes := []string{} + 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, + DnsDomainId: params.DomainId, + Routes: routes, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/nodes.go b/internal/web/actions/default/clusters/cluster/nodes.go index 4aa77425..39e37b3f 100644 --- a/internal/web/actions/default/clusters/cluster/nodes.go +++ b/internal/web/actions/default/clusters/cluster/nodes.go @@ -41,6 +41,15 @@ func (this *NodesAction) RunGet(params struct { this.Data["activeState"] = params.ActiveState this.Data["keyword"] = params.Keyword + // 集群是否已经设置了线路 + clusterDNSResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId}) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasClusterDNS"] = clusterDNSResp.Domain != nil + + // 数量 countAllResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ NodeClusterId: params.ClusterId, }) diff --git a/web/public/js/components/dns/dns-route-selector.js b/web/public/js/components/dns/dns-route-selector.js index d864b6fe..2b2376d7 100644 --- a/web/public/js/components/dns/dns-route-selector.js +++ b/web/public/js/components/dns/dns-route-selector.js @@ -94,7 +94,7 @@ Vue.component("dns-route-selector", {