diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index f7cfec41..bb5cfa40 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -212,6 +212,10 @@ func (this *RPCClient) DNSDomainRPC() pb.DNSDomainServiceClient { return pb.NewDNSDomainServiceClient(this.pickConn()) } +func (this *RPCClient) DNSRPC() pb.DNSServiceClient { + return pb.NewDNSServiceClient(this.pickConn()) +} + // 构造Admin上下文 func (this *RPCClient) Context(adminId int64) context.Context { ctx := context.Background() diff --git a/internal/web/actions/default/dns/clusters/cluster.go b/internal/web/actions/default/dns/clusters/cluster.go index 14c710ef..00ec14d6 100644 --- a/internal/web/actions/default/dns/clusters/cluster.go +++ b/internal/web/actions/default/dns/clusters/cluster.go @@ -68,10 +68,11 @@ func (this *ClusterAction) RunGet(params struct { 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, + "id": node.Id, + "name": node.Name, + "ipAddr": node.IpAddr, + "route": node.Route, + "clusterId": node.ClusterId, }) } this.Data["nodes"] = nodeMaps @@ -92,5 +93,13 @@ func (this *ClusterAction) RunGet(params struct { } 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 + this.Show() } diff --git a/internal/web/actions/default/dns/clusters/sync.go b/internal/web/actions/default/dns/clusters/sync.go new file mode 100644 index 00000000..be890f20 --- /dev/null +++ b/internal/web/actions/default/dns/clusters/sync.go @@ -0,0 +1,46 @@ +package clusters + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +type SyncAction struct { + actionutils.ParentAction +} + +func (this *SyncAction) RunPost(params struct { + ClusterId int64 +}) { + // 记录日志 + this.CreateLog(oplogs.LevelInfo, "同步集群 %d 的DNS设置", 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() +} diff --git a/internal/web/actions/default/dns/init.go b/internal/web/actions/default/dns/init.go index 7f2f87df..23f6410f 100644 --- a/internal/web/actions/default/dns/init.go +++ b/internal/web/actions/default/dns/init.go @@ -23,6 +23,7 @@ func init() { // 集群 Prefix("/dns/clusters"). Get("/cluster", new(clusters.ClusterAction)). + Post("/sync", new(clusters.SyncAction)). // 服务商 Prefix("/dns/providers"). @@ -47,9 +48,8 @@ func init() { // 问题修复 Prefix("/dns/issues"). Data("teaSubMenu", "issue"). - Get("", new(issues.IndexAction)). + GetPost("", new(issues.IndexAction)). GetPost("/updateNodePopup", new(issues.UpdateNodePopupAction)). - GetPost("/updateServerPopup", new(issues.UpdateServerPopupAction)). EndData(). EndAll() diff --git a/internal/web/actions/default/dns/issues/index.go b/internal/web/actions/default/dns/issues/index.go index 78359cdb..230aad40 100644 --- a/internal/web/actions/default/dns/issues/index.go +++ b/internal/web/actions/default/dns/issues/index.go @@ -1,6 +1,10 @@ package issues -import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" +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 @@ -11,5 +15,27 @@ func (this *IndexAction) Init() { } 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() +} diff --git a/internal/web/actions/default/dns/issues/updateNodePopup.go b/internal/web/actions/default/dns/issues/updateNodePopup.go index fe0bce6e..d936cbcd 100644 --- a/internal/web/actions/default/dns/issues/updateNodePopup.go +++ b/internal/web/actions/default/dns/issues/updateNodePopup.go @@ -35,6 +35,7 @@ func (this *UpdateNodePopupAction) RunGet(params struct { this.Data["ipAddr"] = dnsInfo.IpAddr this.Data["route"] = dnsInfo.Route this.Data["domainId"] = dnsInfo.DnsDomainId + this.Data["domainName"] = dnsInfo.DnsDomainName // 读取所有线路 routes := []string{} diff --git a/internal/web/actions/default/dns/issues/updateServerPopup.go b/internal/web/actions/default/dns/issues/updateServerPopup.go deleted file mode 100644 index cf0f9856..00000000 --- a/internal/web/actions/default/dns/issues/updateServerPopup.go +++ /dev/null @@ -1,15 +0,0 @@ -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() -} diff --git a/internal/web/actions/default/dns/providers/provider.go b/internal/web/actions/default/dns/providers/provider.go index bbd0d26c..9d318fb2 100644 --- a/internal/web/actions/default/dns/providers/provider.go +++ b/internal/web/actions/default/dns/providers/provider.go @@ -60,15 +60,15 @@ func (this *ProviderAction) RunGet(params struct { 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, - "dataUpdatedTime": dataUpdatedTime, - "countRoutes": len(domain.Routes), - "countServerRecords": domain.ServerRecords, - "allServersResolved": domain.AllServersResolved, - "countClusterRecords": domain.ClusterRecords, - "allClustersResolved": domain.AllClustersResolved, + "id": domain.Id, + "name": domain.Name, + "isOn": domain.IsOn, + "dataUpdatedTime": dataUpdatedTime, + "countRoutes": len(domain.Routes), + "countServerRecords": domain.CountServerRecords, + "serversChanged": domain.ServersChanged, + "countNodeRecords": domain.CountNodeRecords, + "nodesChanged": domain.NodesChanged, }) } this.Data["domains"] = domainMaps diff --git a/web/public/js/components/common/links.js b/web/public/js/components/common/links.js index 0e38465d..0824ae9e 100644 --- a/web/public/js/components/common/links.js +++ b/web/public/js/components/common/links.js @@ -35,6 +35,17 @@ Vue.component("link-popup", { template: `` }) +// 小提示 +Vue.component("tip-icon", { + props: ["content"], + methods: { + showTip: function () { + teaweb.popupTip(this.content) + } + }, + template: `` +}) + // 提交点击事件 function emitClick(obj, arguments) { let event = "click" diff --git a/web/public/js/utils.js b/web/public/js/utils.js index ba0f2830..8a948440 100644 --- a/web/public/js/utils.js +++ b/web/public/js/utils.js @@ -131,6 +131,16 @@ window.teaweb = { window.POPUP_CALLBACK.apply(window, arguments); } }, + popupTip: function (html) { + Swal.fire({ + html: '' + html + "", + width: "30em", + padding: "5em", + showConfirmButton: false, + showCloseButton: true, + focusConfirm: false + }); + }, isPopup: function () { var hash = window.location.hash; return hash != null && hash.startsWith("#popup"); diff --git a/web/views/@default/dns/clusters/cluster.html b/web/views/@default/dns/clusters/cluster.html index f74ead85..ea93dcd9 100644 --- a/web/views/@default/dns/clusters/cluster.html +++ b/web/views/@default/dns/clusters/cluster.html @@ -17,7 +17,7 @@ {{dnsInfo.dnsName}}.{{dnsInfo.domainName}} 没有设置 -   [修改] +   [修改] @@ -30,6 +30,16 @@ 没有设置 + + 操作 + +
+ 检测到解析记录有变化,需要同步 + DNS服务商同步 +
+ DNS服务商同步中... + +

下面的DNS解析记录也可以手工在DNS服务商提供的管理平台添加。

@@ -48,10 +58,10 @@ - {{node.name}} + {{node.name}} {{dnsInfo.dnsName}} - 没有设置 + 没有设置 A @@ -85,7 +95,7 @@ CNAME {{dnsInfo.dnsName}}.{{dnsInfo.domainName}}. - 没有设置 + 没有设置 \ No newline at end of file diff --git a/web/views/@default/dns/clusters/cluster.js b/web/views/@default/dns/clusters/cluster.js index 39dd88f0..b6e05ba6 100644 --- a/web/views/@default/dns/clusters/cluster.js +++ b/web/views/@default/dns/clusters/cluster.js @@ -1,5 +1,5 @@ Tea.context(function () { - this.updateClusterDNS = function (clusterId) { + this.updateCluster = function (clusterId) { teaweb.popup("/dns/updateClusterPopup?clusterId=" + clusterId, { height: "22em", callback: function () { @@ -19,4 +19,22 @@ Tea.context(function () { } }) } + + this.isSyncing = false + this.syncCluster = function (clusterId) { + let that = this + teaweb.confirm("确定要执行数据同步吗?", function () { + that.isSyncing = true + that.$post(".sync") + .params({clusterId: clusterId}) + .done(function () { + that.isSyncing = false + }) + .success(function () { + teaweb.success("同步成功", function () { + teaweb.reload() + }) + }) + }) + } }) \ No newline at end of file diff --git a/web/views/@default/dns/issues/index.html b/web/views/@default/dns/issues/index.html index a98dc909..706738d1 100644 --- a/web/views/@default/dns/issues/index.html +++ b/web/views/@default/dns/issues/index.html @@ -1,3 +1,50 @@ {$layout} -

此功能暂未开放,敬请期待。

\ No newline at end of file + + {{issues.length}}个问题 + | + 刷新 + | + + + +
+
+ 正在检查系统问题,请耐心等待... +
+ +
+
+

暂时没有发现问题。

+
+ + + + + + + + + + + + + + +
问题对象问题描述操作
+
+ 集群 "{{issue.target}}" +
+
+ 集群 "{{issue.params.clusterName}}" 节点 "{{issue.target}}" +
+
+ {{issue.description}} + +
+ 修复 +
+
+ 修复 +
+
\ No newline at end of file diff --git a/web/views/@default/dns/issues/index.js b/web/views/@default/dns/issues/index.js new file mode 100644 index 00000000..fb9d38d1 --- /dev/null +++ b/web/views/@default/dns/issues/index.js @@ -0,0 +1,41 @@ +Tea.context(function () { + this.isRequesting = true + + this.$delay(function () { + this.reload() + }) + + this.updateCluster = function (clusterId) { + let that = this + teaweb.popup("/dns/updateClusterPopup?clusterId=" + clusterId, { + height: "22em", + callback: function () { + teaweb.success("保存成功", function () { + that.reload() + }) + } + }) + } + + this.updateNode = function (nodeId) { + let that = this + teaweb.popup("/dns/issues/updateNodePopup?nodeId=" + nodeId, { + callback: function () { + teaweb.success("保存成功", function () { + that.reload() + }) + } + }) + } + + this.reload = function () { + this.isRequesting = true + this.$post("$") + .success(function (resp) { + this.issues = resp.data.issues; + }) + .done(function () { + this.isRequesting = false + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/dns/issues/updateNodePopup.html b/web/views/@default/dns/issues/updateNodePopup.html index 062c5531..b51c78c4 100644 --- a/web/views/@default/dns/issues/updateNodePopup.html +++ b/web/views/@default/dns/issues/updateNodePopup.html @@ -8,6 +8,12 @@ + + + + - + @@ -54,11 +54,11 @@ 0个
主域名{{domainName}} +

由当前节点所属集群设置。

+
IP地址 * diff --git a/web/views/@default/dns/providers/provider.html b/web/views/@default/dns/providers/provider.html index 6d8ef7d9..b07aba3c 100644 --- a/web/views/@default/dns/providers/provider.html +++ b/web/views/@default/dns/providers/provider.html @@ -40,7 +40,7 @@
域名 线路集群域名节点域名 服务域名 数据更新时间 状态 - {{domain.countClusterRecords}}个 + {{domain.countNodeRecords}}个 0个 - {{domain.countServerRecords}}个 + {{domain.countServerRecords}}个 0个 @@ -66,7 +66,7 @@ 尚未更新 -
+
需要同步 正在同步...
diff --git a/web/views/@default/dns/providers/provider.js b/web/views/@default/dns/providers/provider.js index 17f5a71c..8204637d 100644 --- a/web/views/@default/dns/providers/provider.js +++ b/web/views/@default/dns/providers/provider.js @@ -43,29 +43,33 @@ Tea.context(function () { } this.syncDomain = function (index, domain) { - domain.isSyncing = true - Vue.set(this.domains, index, domain) + let that = this + teaweb.confirm("确定要同步此域名下的所有解析记录吗?", function () { + domain.isSyncing = true + Vue.set(that.domains, index, domain) - this.$post("/dns/domains/sync") - .params({ - domainId: domain.id - }) - .success(function () { - teaweb.success("同步成功", function () { - teaweb.reload() + this.$post("/dns/domains/sync") + .params({ + domainId: domain.id }) - }) - .fail(function (resp) { - teaweb.warn(resp.message, function () { - if (resp.data.shouldFix) { - window.location = "/dns/issues" - } + .success(function () { + teaweb.success("同步成功", function () { + teaweb.reload() + }) }) - }) - .done(function () { - domain.isSyncing = false - Vue.set(this.domains, index, domain) - }) + .fail(function (resp) { + teaweb.warn(resp.message, function () { + if (resp.data.shouldFix) { + window.location = "/dns/issues" + } + }) + }) + .done(function () { + domain.isSyncing = false + that.dnsHasChanges = false + Vue.set(that.domains, index, domain) + }) + }) } this.showRoutes = function (domainId) {