mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-18 06:40:25 +08:00
自建DNS增加全局配置
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
77
internal/web/actions/default/ns/settings/accesslogs/index.go
Normal file
77
internal/web/actions/default/ns/settings/accesslogs/index.go
Normal 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()
|
||||
}
|
||||
23
internal/web/actions/default/ns/settings/accesslogs/init.go
Normal file
23
internal/web/actions/default/ns/settings/accesslogs/init.go
Normal 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()
|
||||
})
|
||||
}
|
||||
17
internal/web/actions/default/ns/settings/index.go
Normal file
17
internal/web/actions/default/ns/settings/index.go
Normal 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")
|
||||
}
|
||||
@@ -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",
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -288,6 +288,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
|
||||
"url": "/ns/clusters/logs",
|
||||
"code": "log",
|
||||
},
|
||||
{
|
||||
"name": "全局配置",
|
||||
"url": "/ns/settings",
|
||||
"code": "setting",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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/logs"
|
||||
_ "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"
|
||||
|
||||
// 服务相关
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
Vue.component("ns-access-log-ref-box", {
|
||||
props:["v-access-log-ref"],
|
||||
props: ["v-access-log-ref", "v-is-parent"],
|
||||
data: function () {
|
||||
let config = this.vAccessLogRef
|
||||
if (config == null) {
|
||||
config = {
|
||||
isOn: false,
|
||||
isPrior: false
|
||||
isPrior: false,
|
||||
logMissingDomains: false
|
||||
}
|
||||
}
|
||||
if (typeof (config.logMissingDomains) == "undefined") {
|
||||
config.logMissingDomains = false
|
||||
}
|
||||
return {
|
||||
config: config
|
||||
}
|
||||
@@ -15,12 +19,22 @@ Vue.component("ns-access-log-ref-box", {
|
||||
template: `<div>
|
||||
<input type="hidden" name="accessLogJSON" :value="JSON.stringify(config)"/>
|
||||
<table class="ui table definition selectable">
|
||||
<prior-checkbox :v-config="config" v-if="!vIsParent"></prior-checkbox>
|
||||
<tbody v-show="vIsParent || config.isPrior">
|
||||
<tr>
|
||||
<td class="title">是否启用</td>
|
||||
<td>
|
||||
<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>
|
||||
<div class="margin"></div>
|
||||
</div>`
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<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>
|
||||
</form>
|
||||
</div>
|
||||
10
web/views/@default/ns/settings/accesslogs/index.html
Normal file
10
web/views/@default/ns/settings/accesslogs/index.html
Normal 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>
|
||||
3
web/views/@default/ns/settings/accesslogs/index.js
Normal file
3
web/views/@default/ns/settings/accesslogs/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifyReloadSuccess("保存成功")
|
||||
})
|
||||
Reference in New Issue
Block a user