创建集群的时候可以填写DNS信息/集群设置页增加DNS设置功能

This commit is contained in:
GoEdgeLab
2020-11-15 16:28:25 +08:00
parent 6f1c8e286f
commit dae2c9b18f
16 changed files with 497 additions and 19 deletions

View File

@@ -0,0 +1,92 @@
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"
"github.com/iwind/TeaGo/actions"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "")
this.SecondMenu("dns")
}
func (this *IndexAction) RunGet(params struct {
ClusterId int64
}) {
// 是否有域名可选
hasDomainsResp, err := this.RPC().DNSDomainRPC().ExistAvailableDomains(this.AdminContext(), &pb.ExistAvailableDomainsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasDomains"] = hasDomainsResp.Exist
// 当前集群的DNS信息
this.Data["domainId"] = 0
this.Data["domainName"] = ""
this.Data["dnsName"] = ""
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["dnsName"] = dnsInfoResp.Name
if dnsInfoResp.Domain != nil {
this.Data["domainId"] = dnsInfoResp.Domain.Id
this.Data["domainName"] = dnsInfoResp.Domain.Name
}
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ClusterId int64
DnsDomainId int64
DnsName string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 创建日志
this.CreateLog(oplogs.LevelInfo, "修改集群 %d DNS设置", params.ClusterId)
// 检查DNS名称
if len(params.DnsName) > 0 {
if !domainutils.ValidateDomainFormat(params.DnsName) {
this.FailField("dnsName", "请输入正确的DNS子域名")
}
// 检查是否已经被使用
resp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSName(this.AdminContext(), &pb.CheckNodeClusterDNSNameRequest{
NodeClusterId: params.ClusterId,
DnsName: params.DnsName,
})
if err != nil {
this.ErrorPage(err)
return
}
if resp.IsUsed {
this.FailField("dnsName", "此DNS子域名已经被使用请换一个再试")
}
}
_, err := this.RPC().NodeClusterRPC().UpdateNodeClusterDNS(this.AdminContext(), &pb.UpdateNodeClusterDNSRequest{
NodeClusterId: params.ClusterId,
DnsName: params.DnsName,
DnsDomainId: params.DnsDomainId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,6 +1,7 @@
package settings
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns"
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
@@ -15,6 +16,10 @@ func init() {
GetPost("", new(IndexAction)).
GetPost("/health", new(HealthAction)).
GetPost("/healthRunPopup", new(HealthRunPopupAction)).
// DNS
GetPost("/dns", new(dns.IndexAction)).
EndAll()
})
}

View File

@@ -11,6 +11,7 @@ import (
"strconv"
)
// 单个集群的帮助
type ClusterHelper struct {
}
@@ -81,5 +82,10 @@ func (this *ClusterHelper) createSettingMenu(clusterId string, selectedItem stri
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
"isActive": selectedItem == "health",
})
items = append(items, maps.Map{
"name": "DNS设置",
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
"isActive": selectedItem == "dns",
})
return
}

View File

@@ -3,6 +3,7 @@ package clusters
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"
"github.com/iwind/TeaGo/actions"
)
@@ -16,24 +17,61 @@ func (this *CreateAction) Init() {
}
func (this *CreateAction) RunGet(params struct{}) {
hasDomainsResp, err := this.RPC().DNSDomainRPC().ExistAvailableDomains(this.AdminContext(), &pb.ExistAvailableDomainsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasDomains"] = hasDomainsResp.Exist
this.Show()
}
func (this *CreateAction) RunPost(params struct {
Name string
Name string
// SSH相关
GrantId int64
InstallDir string
// DNS相关
DnsDomainId int64
DnsName string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入集群名称")
// 检查DNS名称
if len(params.DnsName) > 0 {
if !domainutils.ValidateDomainFormat(params.DnsName) {
this.FailField("dnsName", "请输入正确的DNS子域名")
}
// 检查是否已经被使用
resp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSName(this.AdminContext(), &pb.CheckNodeClusterDNSNameRequest{
NodeClusterId: 0,
DnsName: params.DnsName,
})
if err != nil {
this.ErrorPage(err)
return
}
if resp.IsUsed {
this.FailField("dnsName", "此DNS子域名已经被使用请换一个再试")
}
}
// TODO 检查DnsDomainId的有效性
createResp, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{
Name: params.Name,
GrantId: params.GrantId,
InstallDir: params.InstallDir,
Name: params.Name,
GrantId: params.GrantId,
InstallDir: params.InstallDir,
DnsDomainId: params.DnsDomainId,
DnsName: params.DnsName,
})
if err != nil {
this.ErrorPage(err)
@@ -41,7 +79,7 @@ func (this *CreateAction) RunPost(params struct {
}
// 创建日志
this.CreateLog(oplogs.LevelInfo, "创建集群:%d", createResp.ClusterId)
this.CreateLog(oplogs.LevelInfo, "创建节点集群:%d", createResp.ClusterId)
this.Success()
}

View File

@@ -0,0 +1,91 @@
package domains
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type SelectPopupAction struct {
actionutils.ParentAction
}
func (this *SelectPopupAction) Init() {
this.Nav("", "", "")
}
func (this *SelectPopupAction) RunGet(params struct {
DomainId int64
}) {
this.Data["domainId"] = 0
this.Data["domainName"] = ""
this.Data["providerId"] = 0
this.Data["providerType"] = ""
// 域名信息
if params.DomainId > 0 {
domainResp, err := this.RPC().DNSDomainRPC().FindEnabledDNSDomain(this.AdminContext(), &pb.FindEnabledDNSDomainRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
domain := domainResp.DnsDomain
if domain != nil {
this.Data["domainId"] = domain.Id
this.Data["domainName"] = domain.Name
this.Data["providerId"] = domain.ProviderId
providerResp, err := this.RPC().DNSProviderRPC().FindEnabledDNSProvider(this.AdminContext(), &pb.FindEnabledDNSProviderRequest{DnsProviderId: domain.ProviderId})
if err != nil {
this.ErrorPage(err)
return
}
if providerResp.DnsProvider != nil {
this.Data["providerType"] = providerResp.DnsProvider.Type
}
}
}
// 所有服务商
providerTypesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &pb.FindAllDNSProviderTypesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
providerTypeMaps := []maps.Map{}
for _, providerType := range providerTypesResp.ProviderTypes {
providerTypeMaps = append(providerTypeMaps, maps.Map{
"name": providerType.Name,
"code": providerType.Code,
})
}
this.Data["providerTypes"] = providerTypeMaps
this.Show()
}
func (this *SelectPopupAction) RunPost(params struct {
DomainId int64
Must *actions.Must
CSRF *actionutils.CSRF
}) {
this.Data["domainId"] = params.DomainId
this.Data["domainName"] = ""
if params.DomainId > 0 {
domainResp, err := this.RPC().DNSDomainRPC().FindEnabledDNSDomain(this.AdminContext(), &pb.FindEnabledDNSDomainRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
if domainResp.DnsDomain != nil {
this.Data["domainName"] = domainResp.DnsDomain.Name
} else {
this.Data["domainId"] = 0
}
}
this.Success()
}

View File

@@ -43,6 +43,7 @@ func init() {
Post("/delete", new(domains.DeleteAction)).
Post("/sync", new(domains.SyncAction)).
Get("/routesPopup", new(domains.RoutesPopupAction)).
GetPost("/selectPopup", new(domains.SelectPopupAction)).
EndData().
// 问题修复

View File

@@ -127,6 +127,14 @@ func (this *IndexAction) RunGet(params struct {
return
}
}
countServerNames := 0
for _, serverName := range serverNames {
if len(serverName.SubNames) == 0 {
countServerNames++
} else {
countServerNames += len(serverName.SubNames)
}
}
serverMaps = append(serverMaps, maps.Map{
"id": server.Id,
@@ -136,10 +144,11 @@ func (this *IndexAction) RunGet(params struct {
"id": server.Cluster.Id,
"name": server.Cluster.Name,
},
"ports": portMaps,
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
"groups": groupMaps,
"serverNames": serverNames,
"ports": portMaps,
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
"groups": groupMaps,
"serverNames": serverNames,
"countServerNames": countServerNames,
})
}
this.Data["servers"] = serverMaps

View File

@@ -82,7 +82,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
modules := []maps.Map{
{
"code": "servers",
"name": "代理服务",
"name": "网站服务",
"icon": "clone outsize",
"subItems": []maps.Map{
{
@@ -94,7 +94,7 @@ func (this *UserMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
},
{
"code": "clusters",
"name": "节点集群",
"name": "边缘节点",
"icon": "cloud",
"subItems": []maps.Map{
{

View File

@@ -0,0 +1,54 @@
Vue.component("dns-domain-selector", {
props: ["v-domain-id", "v-domain-name"],
data: function () {
let domainId = this.vDomainId
if (domainId == null) {
domainId = 0
}
let domainName = this.vDomainName
if (domainName == null) {
domainName = ""
}
return {
domainId: domainId,
domainName: domainName
}
},
methods: {
select: function () {
let that = this
teaweb.popup("/dns/domains/selectPopup", {
callback: function (resp) {
that.domainId = resp.data.domainId
that.domainName = resp.data.domainName
}
})
},
remove: function() {
this.domainId = 0
this.domainName = ""
},
update: function () {
let that = this
teaweb.popup("/dns/domains/selectPopup?domainId=" + this.domainId, {
callback: function (resp) {
that.domainId = resp.data.domainId
that.domainName = resp.data.domainName
}
})
}
},
template: `<div>
<input type="hidden" name="dnsDomainId" :value="domainId"/>
<div v-if="domainName.length > 0">
<span class="ui label small">
{{domainName}}
<a href="" @click.prevent="update"><i class="icon pencil small"></i></a>
<a href="" @click.prevent="remove()"><i class="icon remove"></i></a>
</span>
</div>
<div v-if="domainName.length == 0">
<a href="" @click.prevent="select()">[选择域名]</a>
</div>
</div>`
})

View File

@@ -0,0 +1,32 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<p class="comment"><a :href="'/dns/clusters/cluster?clusterId=' + clusterId">查看DNS解析记录 &raquo;</a></p>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="clusterId" :value="clusterId"/>
<csrf-token></csrf-token>
<table class="ui table selectable definition">
<tr v-if="hasDomains">
<td>选择主域名</td>
<td>
<dns-domain-selector :v-domain-id="domainId" :v-domain-name="domainName"></dns-domain-selector>
<p class="comment">用于生成集群节点和网站服务的DNS解析记录。</p>
</td>
</tr>
<tr>
<td class="title">DNS子域名</td>
<td>
<div class="ui input right labeled">
<input type="text" name="dnsName" maxlength="64" style="width:10em" v-model="dnsName"/>
<span class="ui label">.主域名</span>
</div>
<p class="comment">和主域名一起组成子域名。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -18,7 +18,7 @@
</td>
</tr>
<tr>
<td>默认安装目录</td>
<td>节点安装目录</td>
<td>
<input type="text" name="installDir" maxlength="100" v-model="cluster.installDir"/>
<p class="comment">当节点没有单独设置安装目录时,默认使用此设置。如果集群和节点都没有设置安装目录,则使用<span class="ui label tiny">/$登录用户/edge-node</span> 目录。</p>

View File

@@ -9,20 +9,47 @@
<td class="title">集群名称 *</td>
<td><input type="text" name="name" maxlength="50" ref="focus"/></td>
</tr>
</table>
<h4>节点安装选项</h4>
<table class="ui table selectable definition">
<tr>
<td>默认SSH登录方式</td>
<td class="title">默认SSH登录方式</td>
<td>
<grant-selector></grant-selector>
<p class="comment">当节点没有单独设置SSH登录方式时默认使用此设置。</p>
</td>
</tr>
<tr>
<td>默认安装目录</td>
<td>节点安装目录</td>
<td>
<input type="text" name="installDir" maxlength="100"/>
<p class="comment">当节点没有单独设置安装目录时,默认使用此设置。如果集群和节点都没有设置安装目录,则使用<span class="ui label tiny">/$登录用户/edge-node</span> 目录。</p>
<p class="comment">当节点没有单独设置安装目录时,默认使用此设置。如果集群和节点都没有设置安装目录,则使用<span class="ui label tiny">/$登录用户/edge-node</span>
目录。</p>
</td>
</tr>
</table>
<h4>DNS设置选项</h4>
<table class="ui table selectable definition">
<tr v-if="hasDomains">
<td>选择主域名</td>
<td>
<dns-domain-selector></dns-domain-selector>
<p class="comment">用于生成集群节点和网站服务的DNS解析记录。</p>
</td>
</tr>
<tr>
<td class="title">DNS子域名</td>
<td>
<div class="ui input right labeled">
<input type="text" name="dnsName" maxlength="64" style="width:10em"/>
<span class="ui label">.主域名</span>
</div>
<p class="comment">和主域名一起组成子域名。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,38 @@
{$layout "layout_popup"}
<h3>修改集群DNS设置</h3>
<form method="post" class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token>
<table class="ui table definition selectable">
<tr>
<td class="title">DNS服务商</td>
<td>
<select name="providerType" class="ui dropdown auto-width" v-model="providerType" @change="changeProviderType">
<option v-for="providerType in providerTypes" :value="providerType.code">{{providerType.name}}</option>
</select>
</td>
</tr>
<tr>
<td>账号</td>
<td>
<p class="comment" v-if="providers.length == 0">没有账号可选</p>
<select name="providerId" class="ui dropdown auto-width" v-model="providerId" v-show="providers.length > 0">
<option v-for="provider in providers" :value="provider.id">{{provider.name}}</option>
</select>
</td>
</tr>
<tr v-show="providerId > 0">
<td>域名</td>
<td>
<p class="comment" v-if="domains.length == 0">没有域名可选</p>
<select name="domainId" class="ui dropdown auto-width" v-model="domainId" v-show="domains.length > 0">
<option v-for="domain in domains" :value="domain.id">{{domain.name}}</option>
</select>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,80 @@
Tea.context(function () {
this.$delay(function () {
this.changeProviderType()
this.changeProvider()
this.$watch("providerId", function () {
this.changeProvider()
})
this.$watch("domainId", function () {
this.changeDomain()
})
})
this.success = NotifyPopup
// 初始化的内容
// this.domainId = 0
// this.domain = ""
// this.providerId = 0
if (this.providerType == "") {
this.providerType = this.providerTypes[0].code
}
this.providers = []
this.domains = []
this.changeProviderType = function () {
this.$post("/dns/providerOptions")
.params({
type: this.providerType
})
.success(function (resp) {
this.providers = resp.data.providers
// 检查providerId
if (this.providers.length == 0) {
this.providerId = 0
return
}
let that = this
if (this.providers.$find(function (k, v) {
return v.id == that.providerId
}) == null) {
this.providerId = this.providers[0].id
}
this.changeProvider()
})
}
this.changeProvider = function () {
this.$post("/dns/domainOptions")
.params({
providerId: this.providerId
})
.success(function (resp) {
this.domains = resp.data.domains
this.changeDomain()
})
}
this.changeDomain = function () {
if (this.domains.length == 0) {
this.domainId = 0
this.domain = ""
return
}
let domainId = this.domainId
let domainInfo = this.domains.$find(function (k, v) {
return v.id == domainId
})
if (domainInfo == null) {
// 默认选取第一个
this.domainId = this.domains[0].id
this.domain = this.domains[0].name
} else {
this.domain = domainInfo.name
}
}
})

View File

@@ -52,10 +52,12 @@
</td>
<td>{{server.cluster.name}}</td>
<td>
<div v-for="serverName in server.serverNames">
<tiny-label v-if="serverName.subNames == null || serverName.subNames.length == 0">{{serverName.name}}</tiny-label>
<tiny-label v-else>{{serverName.subNames[0]}}等{{serverName.subNames.length}}个域名</tiny-label>
</div>
<span v-if="server.serverNames.length > 0">
<span v-if="server.serverNames[0].subNames == null || server.serverNames[0].subNames.length == 0">{{server.serverNames[0].name}}</span>
<span v-else>{{server.serverNames[0].subNames[0]}}</span>
<span v-if="server.countServerNames > 1">等{{server.countServerNames}}个域名</span>
</span>
<span v-else class="disabled">-</span>
</td>
<td>
<span v-if="server.ports.length == 0">-</span>