mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-25 19:20:30 +08:00
DNS支持TSIG
This commit is contained in:
80
internal/web/actions/default/ns/domains/tsig.go
Normal file
80
internal/web/actions/default/ns/domains/tsig.go
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package domains
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/domainutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
)
|
||||
|
||||
type TsigAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TsigAction) Init() {
|
||||
this.Nav("", "", "tsig")
|
||||
}
|
||||
|
||||
func (this *TsigAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
}) {
|
||||
// 初始化域名信息
|
||||
err := domainutils.InitDomain(this.Parent(), params.DomainId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// TSIG信息
|
||||
tsigResp, err := this.RPC().NSDomainRPC().FindEnabledNSDomainTSIG(this.AdminContext(), &pb.FindEnabledNSDomainTSIGRequest{NsDomainId: params.DomainId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var tsigJSON = tsigResp.TsigJSON
|
||||
|
||||
var tsigConfig = &dnsconfigs.TSIGConfig{}
|
||||
if len(tsigJSON) > 0 {
|
||||
err = json.Unmarshal(tsigJSON, tsigConfig)
|
||||
if err != nil {
|
||||
// 只是提示错误,仍然允许用户修改
|
||||
logs.Error(err)
|
||||
}
|
||||
}
|
||||
this.Data["tsig"] = tsigConfig
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *TsigAction) RunPost(params struct {
|
||||
DomainId int64
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改DNS域名 %d 的TSIG配置", params.DomainId)
|
||||
|
||||
var tsigConfig = &dnsconfigs.TSIGConfig{
|
||||
IsOn: params.IsOn,
|
||||
}
|
||||
tsigJSON, err := json.Marshal(tsigConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().NSDomainRPC().UpdateNSDomainTSIG(this.AdminContext(), &pb.UpdateNSDomainTSIGRequest{
|
||||
NsDomainId: params.DomainId,
|
||||
TsigJSON: tsigJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -23,6 +23,7 @@ func init() {
|
||||
Post("/delete", new(domains.DeleteAction)).
|
||||
Get("/domain", new(domains.DomainAction)).
|
||||
GetPost("/update", new(domains.UpdateAction)).
|
||||
GetPost("/tsig", new(domains.TsigAction)).
|
||||
|
||||
// 域名密钥
|
||||
Prefix("/ns/domains/keys").
|
||||
|
||||
@@ -34,5 +34,8 @@ Vue.component("ns-access-log-box", {
|
||||
},
|
||||
template: `<div class="access-log-row" :style="{'color': (accessLog.nsRecordId == null || accessLog.nsRecordId == 0) ? '#dc143c' : ''}" ref="box">
|
||||
<span v-if="accessLog.region != null && accessLog.region.length > 0" class="grey">[{{accessLog.region}}]</span> <keyword :v-word="vKeyword">{{accessLog.remoteAddr}}</keyword> [{{accessLog.timeLocal}}] [{{accessLog.networking}}] <em>{{accessLog.questionType}} <keyword :v-word="vKeyword">{{accessLog.questionName}}</keyword></em> -> <em>{{accessLog.recordType}} <keyword :v-word="vKeyword">{{accessLog.recordValue}}</keyword></em><!-- <a href="" @click.prevent="showLog" title="查看详情"><i class="icon expand"></i></a>-->
|
||||
<div v-if="accessLog.error != null && accessLog.error.length > 0">
|
||||
<i class="icon warning circle"></i>错误:[{{accessLog.error}}]
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
@@ -30,7 +30,6 @@
|
||||
<th>概要</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<!-- 这里之所以需要添加 :key,是因为要不然不会刷新显示 -->
|
||||
<tr v-for="accessLog in accessLogs" :key="accessLog.requestId">
|
||||
<td>
|
||||
<div v-if="accessLog.node.cluster != null">
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
<menu-item :href="'/ns/domains/domain?domainId=' + domain.id" code="index">详情<span class="grey small">({{domain.name}})</span></menu-item>
|
||||
<menu-item :href="'/ns/domains/records?domainId=' + domain.id" code="record">记录({{domain.countRecords}})</menu-item>
|
||||
<menu-item :href="'/ns/domains/keys?domainId=' + domain.id" code="key">密钥({{domain.countKeys}})</menu-item>
|
||||
<menu-item :href="'/ns/domains/tsig?domainId=' + domain.id" code="tsig">TSIG</menu-item>
|
||||
<menu-item :href="'/ns/domains/update?domainId=' + domain.id" code="update">修改</menu-item>
|
||||
</first-menu>
|
||||
@@ -12,8 +12,8 @@
|
||||
<table class="ui table celled selectable" v-if="keys.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="two wide">密钥名称</th>
|
||||
<th class="two wide">算法</th>
|
||||
<th class="three wide">密钥名称</th>
|
||||
<th class="three wide">算法</th>
|
||||
<th>密码</th>
|
||||
<th class="two wide">密码类型</th>
|
||||
<th class="two wide">状态</th>
|
||||
|
||||
@@ -10,7 +10,7 @@ Tea.context(function () {
|
||||
|
||||
this.updateKey = function (keyId) {
|
||||
teaweb.popup(Tea.url(".updatePopup?keyId=" + keyId), {
|
||||
height: "26em",
|
||||
height: "27em",
|
||||
callback: function () {
|
||||
teaweb.successRefresh("保存成功")
|
||||
}
|
||||
|
||||
16
web/views/@default/ns/domains/tsig.html
Normal file
16
web/views/@default/ns/domains/tsig.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{$layout}
|
||||
{$template "domain_menu"}
|
||||
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="domainId" :value="domain.id"/>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">是否启用TSIG *</td>
|
||||
<td>
|
||||
<checkbox name="isOn" v-model="tsig.isOn"></checkbox>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
3
web/views/@default/ns/domains/tsig.js
Normal file
3
web/views/@default/ns/domains/tsig.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifyReloadSuccess("保存成功")
|
||||
})
|
||||
Reference in New Issue
Block a user