mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-21 00:30:26 +08:00
可以修改节点的DNS设置
This commit is contained in:
85
internal/web/actions/default/dns/clusters/cluster.go
Normal file
85
internal/web/actions/default/dns/clusters/cluster.go
Normal 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()
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
93
internal/web/actions/default/dns/issues/updateNodePopup.go
Normal file
93
internal/web/actions/default/dns/issues/updateNodePopup.go
Normal 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()
|
||||
}
|
||||
15
internal/web/actions/default/dns/issues/updateServerPopup.go
Normal file
15
internal/web/actions/default/dns/issues/updateServerPopup.go
Normal 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()
|
||||
}
|
||||
@@ -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("请输入子域名")
|
||||
|
||||
70
web/views/@default/dns/clusters/cluster.html
Normal file
70
web/views/@default/dns/clusters/cluster.html
Normal file
@@ -0,0 +1,70 @@
|
||||
{$layout}
|
||||
|
||||
<first-menu>
|
||||
<menu-item :href="'/dns'">所有集群</menu-item>
|
||||
<span class="item">|</span>
|
||||
<menu-item :href="'/dns/clusters/cluster?clusterId=' + cluster.id" active="true">{{cluster.name}}</menu-item>
|
||||
</first-menu>
|
||||
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">集群</td>
|
||||
<td>{{cluster.name}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>子域名</td>
|
||||
<td>
|
||||
<span v-if="dnsInfo.domainName.length > 0"><var>{{dnsInfo.dnsName}}</var>.{{dnsInfo.domainName}}</span>
|
||||
<span v-else class="disabled">没有设置</span>
|
||||
|
||||
<a href="" @click.prevent="updateClusterDNS(cluster.id)">[修改]</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>DNS服务商</td>
|
||||
<td>
|
||||
<div v-if="dnsInfo.providerName.length > 0">
|
||||
<a :href="'/dns/providers/provider?providerId=' + dnsInfo.providerId">{{dnsInfo.providerTypeName}} - {{dnsInfo.providerName}}</a>
|
||||
</div>
|
||||
<span v-else-if="dnsInfo.domainName.length == 0" class="disabled">请先设置域名</span>
|
||||
<span v-else class="disabled">没有设置</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="comment">下面的DNS解析记录可以手工在DNS服务商提供的管理平台添加。</p>
|
||||
|
||||
<h3>节点DNS解析记录</h3>
|
||||
<p class="comment" v-if="nodes.length == 0">暂时没有需要设置的DNS记录。</p>
|
||||
<table class="ui table selectable" v-if="nodes.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>节点</th>
|
||||
<th>记录类型</th>
|
||||
<th>记录值</th>
|
||||
<th>线路</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="node in nodes">
|
||||
<td><a :href="'/clusters/cluster/node?nodeId=' + node.id">{{node.name}}</a></td>
|
||||
<td>A</td>
|
||||
<td>
|
||||
<span v-if="node.ipAddr.length > 0">{{node.ipAddr}}</span>
|
||||
<a href="" v-else style="border-bottom: 1px #db2828 dashed" @click.prevent="updateNode(node.id)"><span class="red">没有设置</span></a>
|
||||
</td>
|
||||
<td>
|
||||
<span v-if="node.route.length > 0">{{node.route}}</span>
|
||||
<a href="" v-else style="border-bottom: 1px #db2828 dashed" @click.prevent="updateNode(node.id)"><span class="red">没有设置</span></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="" @click.prevent="updateNode(node.id)">修改</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>代理服务解析记录</h3>
|
||||
<p class="comment" v-if="servers.length == 0">暂时没有需要设置的DNS记录。</p>
|
||||
<table class="ui table selectable" v-if="servers.length > 0">
|
||||
|
||||
</table>
|
||||
22
web/views/@default/dns/clusters/cluster.js
Normal file
22
web/views/@default/dns/clusters/cluster.js
Normal file
@@ -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()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -7,7 +7,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>集群</th>
|
||||
<th>域名解析</th>
|
||||
<th>子域名</th>
|
||||
<th>DNS服务商</th>
|
||||
<th>DNS服务商账号</th>
|
||||
<th class="two op">操作</th>
|
||||
@@ -30,7 +30,7 @@
|
||||
<span v-else="" class="disabled">-</span>
|
||||
</td>
|
||||
<td>
|
||||
<a href="" @click.prevent="updateCluster(cluster.id)">修改</a>
|
||||
<a :href="'/dns/clusters/cluster?clusterId=' + cluster.id">详情</a> <a href="" @click.prevent="updateCluster(cluster.id)">修改</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
31
web/views/@default/dns/issues/updateNodePopup.html
Normal file
31
web/views/@default/dns/issues/updateNodePopup.html
Normal file
@@ -0,0 +1,31 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>修改节点DNS设置</h3>
|
||||
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<input type="hidden" name="nodeId" :value="nodeId"/>
|
||||
<input type="hidden" name="domainId" :value="domainId"/>
|
||||
<csrf-token></csrf-token>
|
||||
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">IP地址 *</td>
|
||||
<td>
|
||||
<input type="text" name="ipAddr" maxlength="64" ref="focus" v-model="ipAddr"/>
|
||||
<p class="comment">用于域名解析的节点IP地址。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="domainId > 0">
|
||||
<td>线路</td>
|
||||
<td>
|
||||
<p class="comment" v-if="routes.length == 0">没有可选的线路。</p>
|
||||
<select class="ui dropdown auto-width" name="route" v-if="routes.length > 0" v-model="route">
|
||||
<option v-for="route in routes" :value="route">{{route}}</option>
|
||||
</select>
|
||||
<p class="comment" v-if="routes.length > 0">当前节点IP对应的线路。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
3
web/views/@default/dns/issues/updateNodePopup.js
Normal file
3
web/views/@default/dns/issues/updateNodePopup.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifyPopup
|
||||
})
|
||||
Reference in New Issue
Block a user