自建DNS增加全局配置

This commit is contained in:
GoEdgeLab
2021-08-05 16:08:18 +08:00
parent 48b8d94404
commit efcec26013
13 changed files with 195 additions and 13 deletions

View File

@@ -28,7 +28,7 @@ func (this *IndexAction) RunGet(params struct {
return return
} }
accessLogRef := &dnsconfigs.AccessLogRef{} accessLogRef := &dnsconfigs.NSAccessLogRef{}
if len(accessLogResp.AccessLogJSON) > 0 { if len(accessLogResp.AccessLogJSON) > 0 {
err = json.Unmarshal(accessLogResp.AccessLogJSON, accessLogRef) err = json.Unmarshal(accessLogResp.AccessLogJSON, accessLogRef)
if err != nil { if err != nil {
@@ -50,7 +50,7 @@ func (this *IndexAction) RunPost(params struct {
}) { }) {
defer this.CreateLogInfo("修改域名服务集群 %d 访问日志配置", params.ClusterId) defer this.CreateLogInfo("修改域名服务集群 %d 访问日志配置", params.ClusterId)
ref := &dnsconfigs.AccessLogRef{} ref := &dnsconfigs.NSAccessLogRef{}
err := json.Unmarshal(params.AccessLogJSON, ref) err := json.Unmarshal(params.AccessLogJSON, ref)
if err != nil { if err != nil {
this.Fail("数据格式错误:" + err.Error()) this.Fail("数据格式错误:" + err.Error())

View File

@@ -20,7 +20,7 @@ func (this *CreateAction) Init() {
func (this *CreateAction) RunGet(params struct{}) { func (this *CreateAction) RunGet(params struct{}) {
// 默认的访问日志设置 // 默认的访问日志设置
this.Data["accessLogRef"] = &dnsconfigs.AccessLogRef{ this.Data["accessLogRef"] = &dnsconfigs.NSAccessLogRef{
IsOn: true, IsOn: true,
} }
@@ -44,7 +44,7 @@ func (this *CreateAction) RunPost(params struct {
Require("请输入集群名称") Require("请输入集群名称")
// 校验访问日志设置 // 校验访问日志设置
ref := &dnsconfigs.AccessLogRef{} ref := &dnsconfigs.NSAccessLogRef{}
err := json.Unmarshal(params.AccessLogJSON, ref) err := json.Unmarshal(params.AccessLogJSON, ref)
if err != nil { if err != nil {
this.Fail("数据格式错误:" + err.Error()) this.Fail("数据格式错误:" + err.Error())

View File

@@ -5,6 +5,7 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/keys" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/keys"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/records" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/domains/records"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo" "github.com/iwind/TeaGo"
) )
@@ -40,6 +41,9 @@ func init() {
GetPost("/updatePopup", new(records.UpdatePopupAction)). GetPost("/updatePopup", new(records.UpdatePopupAction)).
Post("/delete", new(records.DeleteAction)). Post("/delete", new(records.DeleteAction)).
// 设置
Prefix("/ns/settings").
Get("", new(settings.IndexAction)).
EndAll() EndAll()
}) })
} }

View File

@@ -0,0 +1,77 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accesslogs
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
this.SecondMenu("accessLog")
}
func (this *IndexAction) RunGet(params struct{}) {
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
Code: systemconfigs.SettingCodeNSAccessLogSetting,
})
if err != nil {
this.ErrorPage(err)
return
}
var config = &dnsconfigs.NSAccessLogRef{}
if len(resp.ValueJSON) > 0 {
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
} else {
config.IsOn = true
config.LogMissingDomains = true
}
this.Data["config"] = config
this.Show()
}
func (this *IndexAction) RunPost(params struct {
AccessLogJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 校验配置
var config = &dnsconfigs.NSAccessLogRef{}
err := json.Unmarshal(params.AccessLogJSON, config)
if err != nil {
this.Fail("配置解析失败:" + err.Error())
}
err = config.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeNSAccessLogSetting,
ValueJSON: params.AccessLogJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,23 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accesslogs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings/settingutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
Helper(new(settingutils.Helper)).
Data("teaMenu", "ns").
Data("teaSubMenu", "setting").
Prefix("/ns/settings/accesslogs").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,17 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package settings
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
this.RedirectURL("/ns/settings/accesslogs")
}

View File

@@ -0,0 +1,28 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package settingutils
import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type Helper struct {
}
func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) {
var action = actionPtr.Object()
secondMenuItem := action.Data.GetString("secondMenuItem")
action.Data["leftMenuItems"] = this.createSettingMenu(secondMenuItem)
return true
}
func (this *Helper) createSettingMenu(selectedItem string) (items []maps.Map) {
return []maps.Map{
{
"name": "访问日志",
"url": "/ns/settings/accesslogs",
"isActive": selectedItem == "accessLog",
},
}
}

View File

@@ -288,6 +288,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
"url": "/ns/clusters/logs", "url": "/ns/clusters/logs",
"code": "log", "code": "log",
}, },
{
"name": "全局配置",
"url": "/ns/settings",
"code": "setting",
},
}, },
}, },
{ {

View File

@@ -50,6 +50,7 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/cluster/settings/accessLog" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/cluster/settings/accessLog"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/logs" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/logs"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/routes" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/routes"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings/accesslogs"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/users" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/users"
// 服务相关 // 服务相关

View File

@@ -1,13 +1,17 @@
Vue.component("ns-access-log-ref-box", { Vue.component("ns-access-log-ref-box", {
props:["v-access-log-ref"], props: ["v-access-log-ref", "v-is-parent"],
data: function () { data: function () {
let config = this.vAccessLogRef let config = this.vAccessLogRef
if (config == null) { if (config == null) {
config = { config = {
isOn: false, isOn: false,
isPrior: false isPrior: false,
logMissingDomains: false
} }
} }
if (typeof (config.logMissingDomains) == "undefined") {
config.logMissingDomains = false
}
return { return {
config: config config: config
} }
@@ -15,12 +19,22 @@ Vue.component("ns-access-log-ref-box", {
template: `<div> template: `<div>
<input type="hidden" name="accessLogJSON" :value="JSON.stringify(config)"/> <input type="hidden" name="accessLogJSON" :value="JSON.stringify(config)"/>
<table class="ui table definition selectable"> <table class="ui table definition selectable">
<tr> <prior-checkbox :v-config="config" v-if="!vIsParent"></prior-checkbox>
<td class="title">是否启用</td> <tbody v-show="vIsParent || config.isPrior">
<td> <tr>
<checkbox name="isOn" value="1" v-model="config.isOn"></checkbox> <td class="title">是否启用</td>
</td> <td>
</tr> <checkbox name="isOn" value="1" v-model="config.isOn"></checkbox>
</td>
</tr>
<tr>
<td>记录所有访问</td>
<td>
<checkbox name="logMissingDomains" value="1" v-model="config.logMissingDomains"></checkbox>
<p class="comment">包括对没有在系统里创建的域名访问。</p>
</td>
</tr>
</tbody>
</table> </table>
<div class="margin"></div> <div class="margin"></div>
</div>` </div>`

View File

@@ -5,7 +5,7 @@
<form class="ui form" data-tea-action="$" data-tea-success="success"> <form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token> <csrf-token></csrf-token>
<input type="hidden" name="clusterId" :value="clusterId"/> <input type="hidden" name="clusterId" :value="clusterId"/>
<ns-access-log-ref-box :v-access-log-ref="accessLogRef"></ns-access-log-ref-box> <ns-access-log-ref-box :v-access-log-ref="accessLogRef" :v-is-parent="false"></ns-access-log-ref-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>

View File

@@ -0,0 +1,10 @@
{$layout}
{$template "/left_menu_top"}
<div class="right-box without-tabbar">
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<ns-access-log-ref-box :v-access-log-ref="config" :v-is-parent="true"></ns-access-log-ref-box>
<submit-btn></submit-btn>
</form>
</div>

View File

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