自建DNS增加全局配置

This commit is contained in:
刘祥超
2021-08-05 16:08:18 +08:00
parent e766372a81
commit 4a46aaa880
13 changed files with 195 additions and 13 deletions

View File

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

View File

@@ -20,7 +20,7 @@ func (this *CreateAction) Init() {
func (this *CreateAction) RunGet(params struct{}) {
// 默认的访问日志设置
this.Data["accessLogRef"] = &dnsconfigs.AccessLogRef{
this.Data["accessLogRef"] = &dnsconfigs.NSAccessLogRef{
IsOn: true,
}
@@ -44,7 +44,7 @@ func (this *CreateAction) RunPost(params struct {
Require("请输入集群名称")
// 校验访问日志设置
ref := &dnsconfigs.AccessLogRef{}
ref := &dnsconfigs.NSAccessLogRef{}
err := json.Unmarshal(params.AccessLogJSON, ref)
if err != nil {
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/keys"
"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/iwind/TeaGo"
)
@@ -40,6 +41,9 @@ func init() {
GetPost("/updatePopup", new(records.UpdatePopupAction)).
Post("/delete", new(records.DeleteAction)).
// 设置
Prefix("/ns/settings").
Get("", new(settings.IndexAction)).
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",
},
}
}