diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index 88cac56f..bc013fc0 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -17,21 +17,22 @@ import ( ) type RPCClient struct { - apiConfig *configs.APIConfig - adminClients []pb.AdminServiceClient - nodeClients []pb.NodeServiceClient - nodeGrantClients []pb.NodeGrantServiceClient - nodeClusterClients []pb.NodeClusterServiceClient - nodeIPAddressClients []pb.NodeIPAddressServiceClient - serverClients []pb.ServerServiceClient - apiNodeClients []pb.APINodeServiceClient - originNodeClients []pb.OriginServerServiceClient - httpWebClients []pb.HTTPWebServiceClient - reverseProxyClients []pb.ReverseProxyServiceClient - httpGzipClients []pb.HTTPGzipServiceClient - httpHeaderPolicyClients []pb.HTTPHeaderPolicyServiceClient - httpHeaderClients []pb.HTTPHeaderServiceClient - httpPageClients []pb.HTTPPageServiceClient + apiConfig *configs.APIConfig + adminClients []pb.AdminServiceClient + nodeClients []pb.NodeServiceClient + nodeGrantClients []pb.NodeGrantServiceClient + nodeClusterClients []pb.NodeClusterServiceClient + nodeIPAddressClients []pb.NodeIPAddressServiceClient + serverClients []pb.ServerServiceClient + apiNodeClients []pb.APINodeServiceClient + originNodeClients []pb.OriginServerServiceClient + httpWebClients []pb.HTTPWebServiceClient + reverseProxyClients []pb.ReverseProxyServiceClient + httpGzipClients []pb.HTTPGzipServiceClient + httpHeaderPolicyClients []pb.HTTPHeaderPolicyServiceClient + httpHeaderClients []pb.HTTPHeaderServiceClient + httpPageClients []pb.HTTPPageServiceClient + httpAccessLogPolicyClients []pb.HTTPAccessLogPolicyServiceClient } func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) { @@ -53,6 +54,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) { httpHeaderPolicyClients := []pb.HTTPHeaderPolicyServiceClient{} httpHeaderClients := []pb.HTTPHeaderServiceClient{} httpPageClients := []pb.HTTPPageServiceClient{} + httpAccessLogPolicyClients := []pb.HTTPAccessLogPolicyServiceClient{} conns := []*grpc.ClientConn{} for _, endpoint := range apiConfig.RPC.Endpoints { @@ -82,24 +84,26 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) { httpHeaderPolicyClients = append(httpHeaderPolicyClients, pb.NewHTTPHeaderPolicyServiceClient(conn)) httpHeaderClients = append(httpHeaderClients, pb.NewHTTPHeaderServiceClient(conn)) httpPageClients = append(httpPageClients, pb.NewHTTPPageServiceClient(conn)) + httpAccessLogPolicyClients = append(httpAccessLogPolicyClients, pb.NewHTTPAccessLogPolicyServiceClient(conn)) } return &RPCClient{ - apiConfig: apiConfig, - adminClients: adminClients, - nodeClients: nodeClients, - nodeGrantClients: nodeGrantClients, - nodeClusterClients: nodeClusterClients, - nodeIPAddressClients: nodeIPAddressClients, - serverClients: serverClients, - apiNodeClients: apiNodeClients, - originNodeClients: originNodeClients, - httpWebClients: httpWebClients, - reverseProxyClients: reverseProxyClients, - httpGzipClients: httpGzipClients, - httpHeaderPolicyClients: httpHeaderPolicyClients, - httpHeaderClients: httpHeaderClients, - httpPageClients: httpPageClients, + apiConfig: apiConfig, + adminClients: adminClients, + nodeClients: nodeClients, + nodeGrantClients: nodeGrantClients, + nodeClusterClients: nodeClusterClients, + nodeIPAddressClients: nodeIPAddressClients, + serverClients: serverClients, + apiNodeClients: apiNodeClients, + originNodeClients: originNodeClients, + httpWebClients: httpWebClients, + reverseProxyClients: reverseProxyClients, + httpGzipClients: httpGzipClients, + httpHeaderPolicyClients: httpHeaderPolicyClients, + httpHeaderClients: httpHeaderClients, + httpPageClients: httpPageClients, + httpAccessLogPolicyClients: httpAccessLogPolicyClients, }, nil } @@ -201,6 +205,13 @@ func (this *RPCClient) HTTPPageRPC() pb.HTTPPageServiceClient { return nil } +func (this *RPCClient) HTTPAccessLogPolicyRPC() pb.HTTPAccessLogPolicyServiceClient { + if len(this.httpAccessLogPolicyClients) > 0 { + return this.httpAccessLogPolicyClients[rands.Int(0, len(this.httpAccessLogPolicyClients)-1)] + } + return nil +} + func (this *RPCClient) Context(adminId int64) context.Context { ctx := context.Background() m := maps.Map{ diff --git a/internal/web/actions/default/servers/server/settings/accessLog/index.go b/internal/web/actions/default/servers/server/settings/accessLog/index.go index 147050db..008d3b99 100644 --- a/internal/web/actions/default/servers/server/settings/accessLog/index.go +++ b/internal/web/actions/default/servers/server/settings/accessLog/index.go @@ -1,7 +1,12 @@ package accessLog import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" ) type IndexAction struct { @@ -16,7 +21,60 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { - // TODO + // 获取配置 + webResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId}) + if err != nil { + this.ErrorPage(err) + return + } + webConfig := &serverconfigs.HTTPWebConfig{} + err = json.Unmarshal(webResp.Config, webConfig) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["webId"] = webConfig.Id + this.Data["accessLogConfig"] = webConfig.AccessLog + + // 可选的缓存策略 + policiesResp, err := this.RPC().HTTPAccessLogPolicyRPC().FindAllEnabledHTTPAccessLogPolicies(this.AdminContext(), &pb.FindAllEnabledHTTPAccessLogPoliciesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + policyMaps := []maps.Map{} + for _, policy := range policiesResp.AccessLogPolicies { + policyMaps = append(policyMaps, maps.Map{ + "id": policy.Id, + "name": policy.Name, + "isOn": policy.IsOn, // TODO 这里界面上显示是否开启状态 + }) + } + this.Data["accessLogPolicies"] = policyMaps + + // 通用变量 + this.Data["fields"] = serverconfigs.HTTPAccessLogFields + this.Data["defaultFieldCodes"] = serverconfigs.HTTPAccessLogDefaultFieldsCodes this.Show() } + +func (this *IndexAction) RunPost(params struct { + WebId int64 + AccessLogJSON []byte + + Must *actions.Must +}) { + // TODO 检查参数 + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPAccessLog(this.AdminContext(), &pb.UpdateHTTPAccessLogRequest{ + WebId: params.WebId, + AccessLogJSON: params.AccessLogJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/server/settings/accessLog/init.go b/internal/web/actions/default/servers/server/settings/accessLog/init.go index ac432d79..d7a6931f 100644 --- a/internal/web/actions/default/servers/server/settings/accessLog/init.go +++ b/internal/web/actions/default/servers/server/settings/accessLog/init.go @@ -12,7 +12,7 @@ func init() { Helper(helpers.NewUserMustAuth()). Helper(serverutils.NewServerHelper()). Prefix("/servers/server/settings/accessLog"). - Get("", new(IndexAction)). + GetPost("", new(IndexAction)). EndAll() }) } diff --git a/web/public/js/components/server/http-access-log-config-box.js b/web/public/js/components/server/http-access-log-config-box.js new file mode 100644 index 00000000..cd7ca11e --- /dev/null +++ b/web/public/js/components/server/http-access-log-config-box.js @@ -0,0 +1,135 @@ +Vue.component("http-access-log-config-box", { + props: ["v-access-log-config", "v-fields", "v-default-field-codes", "v-access-log-policies"], + data: function () { + let that = this + + // 初始化 + setTimeout(function () { + that.changeFields() + that.changePolicy() + }, 100) + + let accessLog = { + isOn: true, + fields: [], + status1: true, + status2: true, + status3: true, + status4: true, + status5: true, + + storageOnly: false, + storagePolicies: [] + } + if (this.vAccessLogConfig != null) { + accessLog = this.vAccessLogConfig + } + + this.vFields.forEach(function (v) { + if (that.vAccessLogConfig == null) { // 初始化默认值 + v.isChecked = that.vDefaultFieldCodes.$contains(v.code) + } else { + v.isChecked = accessLog.fields.$contains(v.code) + } + }) + this.vAccessLogPolicies.forEach(function (v) { + v.isChecked = accessLog.storagePolicies.$contains(v.id) + }) + + return { + accessLog: accessLog + } + }, + methods: { + changeFields: function () { + this.accessLog.fields = this.vFields.filter(function (v) { + return v.isChecked + }).map(function (v) { + return v.code + }) + }, + changePolicy: function () { + this.accessLog.storagePolicies = this.vAccessLogPolicies.filter(function (v) { + return v.isChecked + }).map(function (v) { + return v.id + }) + } + }, + template: `
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
是否开启访问日志存储 +
+ + +
+

关闭访问日志,并不影响统计的运行。

+
要存储的访问日志字段 +
+ + +
+
要存储的访问日志状态码 +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
选择输出的日志策略 + 暂时还没有缓存策略。 +
+
+ + +
+
+
是否只输出到日志策略 +
+ + +
+

选中表示只输出日志到日志策略,而停止默认的日志存储。

+
+
+
` +}) \ No newline at end of file diff --git a/web/public/js/components/server/charsets-box.js b/web/public/js/components/server/http-charsets-box.js similarity index 95% rename from web/public/js/components/server/charsets-box.js rename to web/public/js/components/server/http-charsets-box.js index 9fb20ea1..6adb731c 100644 --- a/web/public/js/components/server/charsets-box.js +++ b/web/public/js/components/server/http-charsets-box.js @@ -1,4 +1,4 @@ -Vue.component("charsets-box", { +Vue.component("http-charsets-box", { props: ["v-usual-charsets", "v-all-charsets", "v-charset"], data: function () { let charset = this.vCharset diff --git a/web/public/js/components/server/gzip-box.js b/web/public/js/components/server/http-gzip-box.js similarity index 97% rename from web/public/js/components/server/gzip-box.js rename to web/public/js/components/server/http-gzip-box.js index b8ce12c7..6b92164b 100644 --- a/web/public/js/components/server/gzip-box.js +++ b/web/public/js/components/server/http-gzip-box.js @@ -1,4 +1,4 @@ -Vue.component("gzip-box", { +Vue.component("http-gzip-box", { props: ["v-gzip-config"], data: function () { let gzip = this.vGzipConfig diff --git a/web/public/js/components/server/header-policy-box.js b/web/public/js/components/server/http-header-policy-box.js similarity index 99% rename from web/public/js/components/server/header-policy-box.js rename to web/public/js/components/server/http-header-policy-box.js index 0ff5b9df..31d60bd1 100644 --- a/web/public/js/components/server/header-policy-box.js +++ b/web/public/js/components/server/http-header-policy-box.js @@ -1,4 +1,4 @@ -Vue.component("header-policy-box", { +Vue.component("http-header-policy-box", { props: ["v-request-header-policy", "v-response-header-policy", "v-params"], data: function () { let type = "request" diff --git a/web/public/js/components/server/pages-and-shutdown-box.js b/web/public/js/components/server/http-pages-and-shutdown-box.js similarity index 98% rename from web/public/js/components/server/pages-and-shutdown-box.js rename to web/public/js/components/server/http-pages-and-shutdown-box.js index 312be198..39f58e0e 100644 --- a/web/public/js/components/server/pages-and-shutdown-box.js +++ b/web/public/js/components/server/http-pages-and-shutdown-box.js @@ -1,4 +1,4 @@ -Vue.component("pages-and-shutdown-box", { +Vue.component("http-pages-and-shutdown-box", { props: ["v-pages", "v-shutdown-config"], data: function () { let pages = [] diff --git a/web/views/@default/servers/server/settings/accessLog/index.html b/web/views/@default/servers/server/settings/accessLog/index.html index eae519e9..fe1f9dbb 100644 --- a/web/views/@default/servers/server/settings/accessLog/index.html +++ b/web/views/@default/servers/server/settings/accessLog/index.html @@ -3,5 +3,13 @@ {$template "/left_menu"}
-

此功能暂未开放,敬请期待。

+
+ + + +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/accessLog/index.js b/web/views/@default/servers/server/settings/accessLog/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/server/settings/accessLog/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/charset/index.html b/web/views/@default/servers/server/settings/charset/index.html index f867a040..249b16cd 100644 --- a/web/views/@default/servers/server/settings/charset/index.html +++ b/web/views/@default/servers/server/settings/charset/index.html @@ -5,7 +5,7 @@
- +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/gzip/index.html b/web/views/@default/servers/server/settings/gzip/index.html index 286aee83..533a5c8f 100644 --- a/web/views/@default/servers/server/settings/gzip/index.html +++ b/web/views/@default/servers/server/settings/gzip/index.html @@ -7,7 +7,7 @@ - +
diff --git a/web/views/@default/servers/server/settings/headers/index.html b/web/views/@default/servers/server/settings/headers/index.html index a7d0aa52..ba7b1f5c 100644 --- a/web/views/@default/servers/server/settings/headers/index.html +++ b/web/views/@default/servers/server/settings/headers/index.html @@ -3,5 +3,5 @@ {$template "/left_menu"}
- +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/pages/index.html b/web/views/@default/servers/server/settings/pages/index.html index 986ad022..8010a01f 100644 --- a/web/views/@default/servers/server/settings/pages/index.html +++ b/web/views/@default/servers/server/settings/pages/index.html @@ -5,7 +5,7 @@
- +
\ No newline at end of file