diff --git a/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go b/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go index 9e3e0de5..b8d96a57 100644 --- a/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go +++ b/internal/web/actions/default/ns/clusters/cluster/settings/accessLog/index.go @@ -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()) diff --git a/internal/web/actions/default/ns/clusters/create.go b/internal/web/actions/default/ns/clusters/create.go index ce7e55c3..7880305e 100644 --- a/internal/web/actions/default/ns/clusters/create.go +++ b/internal/web/actions/default/ns/clusters/create.go @@ -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()) diff --git a/internal/web/actions/default/ns/init.go b/internal/web/actions/default/ns/init.go index d5839099..bb8c74e3 100644 --- a/internal/web/actions/default/ns/init.go +++ b/internal/web/actions/default/ns/init.go @@ -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() }) } diff --git a/internal/web/actions/default/ns/settings/accesslogs/index.go b/internal/web/actions/default/ns/settings/accesslogs/index.go new file mode 100644 index 00000000..b6a25cf1 --- /dev/null +++ b/internal/web/actions/default/ns/settings/accesslogs/index.go @@ -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() +} diff --git a/internal/web/actions/default/ns/settings/accesslogs/init.go b/internal/web/actions/default/ns/settings/accesslogs/init.go new file mode 100644 index 00000000..67d2122c --- /dev/null +++ b/internal/web/actions/default/ns/settings/accesslogs/init.go @@ -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() + }) +} diff --git a/internal/web/actions/default/ns/settings/index.go b/internal/web/actions/default/ns/settings/index.go new file mode 100644 index 00000000..c231be1c --- /dev/null +++ b/internal/web/actions/default/ns/settings/index.go @@ -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") +} diff --git a/internal/web/actions/default/ns/settings/settingutils/helper.go b/internal/web/actions/default/ns/settings/settingutils/helper.go new file mode 100644 index 00000000..fce9930c --- /dev/null +++ b/internal/web/actions/default/ns/settings/settingutils/helper.go @@ -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", + }, + } +} diff --git a/internal/web/helpers/user_must_auth.go b/internal/web/helpers/user_must_auth.go index 203ca48c..c76cb328 100644 --- a/internal/web/helpers/user_must_auth.go +++ b/internal/web/helpers/user_must_auth.go @@ -288,6 +288,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map { "url": "/ns/clusters/logs", "code": "log", }, + { + "name": "全局配置", + "url": "/ns/settings", + "code": "setting", + }, }, }, { diff --git a/internal/web/import.go b/internal/web/import.go index 479554e0..16786ff6 100644 --- a/internal/web/import.go +++ b/internal/web/import.go @@ -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" // 服务相关 diff --git a/web/public/js/components/ns/ns-access-log-ref-box.js b/web/public/js/components/ns/ns-access-log-ref-box.js index bb69db82..625730f0 100644 --- a/web/public/js/components/ns/ns-access-log-ref-box.js +++ b/web/public/js/components/ns/ns-access-log-ref-box.js @@ -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: `
- - - - + + + + + + + + + + +
是否启用 - -
是否启用 + +
记录所有访问 + +

包括对没有在系统里创建的域名访问。

+
` diff --git a/web/views/@default/ns/clusters/cluster/settings/accessLog/index.html b/web/views/@default/ns/clusters/cluster/settings/accessLog/index.html index d692dbae..e02d2219 100644 --- a/web/views/@default/ns/clusters/cluster/settings/accessLog/index.html +++ b/web/views/@default/ns/clusters/cluster/settings/accessLog/index.html @@ -5,7 +5,7 @@
- +
\ No newline at end of file diff --git a/web/views/@default/ns/settings/accesslogs/index.html b/web/views/@default/ns/settings/accesslogs/index.html new file mode 100644 index 00000000..88356629 --- /dev/null +++ b/web/views/@default/ns/settings/accesslogs/index.html @@ -0,0 +1,10 @@ +{$layout} +{$template "/left_menu_top"} + +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/ns/settings/accesslogs/index.js b/web/views/@default/ns/settings/accesslogs/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/ns/settings/accesslogs/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file