diff --git a/internal/web/actions/default/dns/clusters/cluster.go b/internal/web/actions/default/dns/clusters/cluster.go new file mode 100644 index 00000000..9b6f9409 --- /dev/null +++ b/internal/web/actions/default/dns/clusters/cluster.go @@ -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() +} diff --git a/internal/web/actions/default/dns/init.go b/internal/web/actions/default/dns/init.go index bcbfe7ef..7f2f87df 100644 --- a/internal/web/actions/default/dns/init.go +++ b/internal/web/actions/default/dns/init.go @@ -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() diff --git a/internal/web/actions/default/dns/issues/updateNodePopup.go b/internal/web/actions/default/dns/issues/updateNodePopup.go new file mode 100644 index 00000000..fe0bce6e --- /dev/null +++ b/internal/web/actions/default/dns/issues/updateNodePopup.go @@ -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() +} diff --git a/internal/web/actions/default/dns/issues/updateServerPopup.go b/internal/web/actions/default/dns/issues/updateServerPopup.go new file mode 100644 index 00000000..cf0f9856 --- /dev/null +++ b/internal/web/actions/default/dns/issues/updateServerPopup.go @@ -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() +} diff --git a/internal/web/actions/default/dns/updateClusterPopup.go b/internal/web/actions/default/dns/updateClusterPopup.go index 70a74f42..e2313b67 100644 --- a/internal/web/actions/default/dns/updateClusterPopup.go +++ b/internal/web/actions/default/dns/updateClusterPopup.go @@ -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("请输入子域名") diff --git a/web/views/@default/dns/clusters/cluster.html b/web/views/@default/dns/clusters/cluster.html new file mode 100644 index 00000000..d253c738 --- /dev/null +++ b/web/views/@default/dns/clusters/cluster.html @@ -0,0 +1,70 @@ +{$layout} + + + 所有集群 + | + {{cluster.name}} + + + + + + + + + + + + + + + +
集群{{cluster.name}}
子域名 + {{dnsInfo.dnsName}}.{{dnsInfo.domainName}} + 没有设置 + +   [修改] +
DNS服务商 +
+ {{dnsInfo.providerTypeName}} - {{dnsInfo.providerName}} +
+ 请先设置域名 + 没有设置 +
+ +

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

+ +

节点DNS解析记录

+

暂时没有需要设置的DNS记录。

+ + + + + + + + + + + + + + + + + +
节点记录类型记录值线路操作
{{node.name}}A + {{node.ipAddr}} + 没有设置 + + {{node.route}} + 没有设置 + + 修改 +
+ +

代理服务解析记录

+

暂时没有需要设置的DNS记录。

+ + +
\ No newline at end of file diff --git a/web/views/@default/dns/clusters/cluster.js b/web/views/@default/dns/clusters/cluster.js new file mode 100644 index 00000000..39dd88f0 --- /dev/null +++ b/web/views/@default/dns/clusters/cluster.js @@ -0,0 +1,22 @@ +Tea.context(function () { + this.updateClusterDNS = function (clusterId) { + teaweb.popup("/dns/updateClusterPopup?clusterId=" + clusterId, { + height: "22em", + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } + + this.updateNode = function (nodeId) { + teaweb.popup("/dns/issues/updateNodePopup?nodeId=" + nodeId, { + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/dns/index.html b/web/views/@default/dns/index.html index bda4920e..43f81c66 100644 --- a/web/views/@default/dns/index.html +++ b/web/views/@default/dns/index.html @@ -7,7 +7,7 @@ 集群 - 域名解析 + 子域名 DNS服务商 DNS服务商账号 操作 @@ -30,7 +30,7 @@ - - 修改 + 详情   修改 diff --git a/web/views/@default/dns/issues/updateNodePopup.html b/web/views/@default/dns/issues/updateNodePopup.html new file mode 100644 index 00000000..062c5531 --- /dev/null +++ b/web/views/@default/dns/issues/updateNodePopup.html @@ -0,0 +1,31 @@ +{$layout "layout_popup"} + +

修改节点DNS设置

+ +
+ + + + + + + + + + + + + +
IP地址 * + +

用于域名解析的节点IP地址。

+
线路 +

没有可选的线路。

+ +

当前节点IP对应的线路。

+
+ + +
\ No newline at end of file diff --git a/web/views/@default/dns/issues/updateNodePopup.js b/web/views/@default/dns/issues/updateNodePopup.js new file mode 100644 index 00000000..c8fe9515 --- /dev/null +++ b/web/views/@default/dns/issues/updateNodePopup.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyPopup +}) \ No newline at end of file