mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-12 19:30:26 +08:00
实现访问日志配置
This commit is contained in:
@@ -32,6 +32,7 @@ type RPCClient struct {
|
|||||||
httpHeaderPolicyClients []pb.HTTPHeaderPolicyServiceClient
|
httpHeaderPolicyClients []pb.HTTPHeaderPolicyServiceClient
|
||||||
httpHeaderClients []pb.HTTPHeaderServiceClient
|
httpHeaderClients []pb.HTTPHeaderServiceClient
|
||||||
httpPageClients []pb.HTTPPageServiceClient
|
httpPageClients []pb.HTTPPageServiceClient
|
||||||
|
httpAccessLogPolicyClients []pb.HTTPAccessLogPolicyServiceClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
||||||
@@ -53,6 +54,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
httpHeaderPolicyClients := []pb.HTTPHeaderPolicyServiceClient{}
|
httpHeaderPolicyClients := []pb.HTTPHeaderPolicyServiceClient{}
|
||||||
httpHeaderClients := []pb.HTTPHeaderServiceClient{}
|
httpHeaderClients := []pb.HTTPHeaderServiceClient{}
|
||||||
httpPageClients := []pb.HTTPPageServiceClient{}
|
httpPageClients := []pb.HTTPPageServiceClient{}
|
||||||
|
httpAccessLogPolicyClients := []pb.HTTPAccessLogPolicyServiceClient{}
|
||||||
|
|
||||||
conns := []*grpc.ClientConn{}
|
conns := []*grpc.ClientConn{}
|
||||||
for _, endpoint := range apiConfig.RPC.Endpoints {
|
for _, endpoint := range apiConfig.RPC.Endpoints {
|
||||||
@@ -82,6 +84,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
httpHeaderPolicyClients = append(httpHeaderPolicyClients, pb.NewHTTPHeaderPolicyServiceClient(conn))
|
httpHeaderPolicyClients = append(httpHeaderPolicyClients, pb.NewHTTPHeaderPolicyServiceClient(conn))
|
||||||
httpHeaderClients = append(httpHeaderClients, pb.NewHTTPHeaderServiceClient(conn))
|
httpHeaderClients = append(httpHeaderClients, pb.NewHTTPHeaderServiceClient(conn))
|
||||||
httpPageClients = append(httpPageClients, pb.NewHTTPPageServiceClient(conn))
|
httpPageClients = append(httpPageClients, pb.NewHTTPPageServiceClient(conn))
|
||||||
|
httpAccessLogPolicyClients = append(httpAccessLogPolicyClients, pb.NewHTTPAccessLogPolicyServiceClient(conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &RPCClient{
|
return &RPCClient{
|
||||||
@@ -100,6 +103,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
httpHeaderPolicyClients: httpHeaderPolicyClients,
|
httpHeaderPolicyClients: httpHeaderPolicyClients,
|
||||||
httpHeaderClients: httpHeaderClients,
|
httpHeaderClients: httpHeaderClients,
|
||||||
httpPageClients: httpPageClients,
|
httpPageClients: httpPageClients,
|
||||||
|
httpAccessLogPolicyClients: httpAccessLogPolicyClients,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +205,13 @@ func (this *RPCClient) HTTPPageRPC() pb.HTTPPageServiceClient {
|
|||||||
return nil
|
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 {
|
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
m := maps.Map{
|
m := maps.Map{
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package accessLog
|
package accessLog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"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 {
|
type IndexAction struct {
|
||||||
@@ -16,7 +21,60 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
ServerId int64
|
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()
|
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()
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func init() {
|
|||||||
Helper(helpers.NewUserMustAuth()).
|
Helper(helpers.NewUserMustAuth()).
|
||||||
Helper(serverutils.NewServerHelper()).
|
Helper(serverutils.NewServerHelper()).
|
||||||
Prefix("/servers/server/settings/accessLog").
|
Prefix("/servers/server/settings/accessLog").
|
||||||
Get("", new(IndexAction)).
|
GetPost("", new(IndexAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
135
web/public/js/components/server/http-access-log-config-box.js
Normal file
135
web/public/js/components/server/http-access-log-config-box.js
Normal file
@@ -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: `<div>
|
||||||
|
<input type="hidden" name="accessLogJSON" :value="JSON.stringify(accessLog)"/>
|
||||||
|
<table class="ui table definition selectable">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="title">是否开启访问日志存储</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui checkbox">
|
||||||
|
<input type="checkbox" v-model="accessLog.isOn"/>
|
||||||
|
<label></label>
|
||||||
|
</div>
|
||||||
|
<p class="comment">关闭访问日志,并不影响统计的运行。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tbody v-show="accessLog.isOn">
|
||||||
|
<tr>
|
||||||
|
<td>要存储的访问日志字段</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui checkbox" v-for="field in vFields" style="width:10em;margin-bottom:0.8em">
|
||||||
|
<input type="checkbox" v-model="field.isChecked" @change="changeFields"/>
|
||||||
|
<label>{{field.name}}</label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>要存储的访问日志状态码</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui checkbox" style="width:3.5em">
|
||||||
|
<input type="checkbox" v-model="accessLog.status1"/>
|
||||||
|
<label>1xx</label>
|
||||||
|
</div>
|
||||||
|
<div class="ui checkbox" style="width:3.5em">
|
||||||
|
<input type="checkbox" v-model="accessLog.status2"/>
|
||||||
|
<label>2xx</label>
|
||||||
|
</div>
|
||||||
|
<div class="ui checkbox" style="width:3.5em">
|
||||||
|
<input type="checkbox" v-model="accessLog.status3"/>
|
||||||
|
<label>3xx</label>
|
||||||
|
</div>
|
||||||
|
<div class="ui checkbox" style="width:3.5em">
|
||||||
|
<input type="checkbox" v-model="accessLog.status4"/>
|
||||||
|
<label>4xx</label>
|
||||||
|
</div>
|
||||||
|
<div class="ui checkbox" style="width:3.5em">
|
||||||
|
<input type="checkbox" v-model="accessLog.status5"/>
|
||||||
|
<label>5xx</label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>选择输出的日志策略</td>
|
||||||
|
<td>
|
||||||
|
<span class="disabled" v-if="vAccessLogPolicies.length == 0">暂时还没有缓存策略。</span>
|
||||||
|
<div v-if="vAccessLogPolicies.length > 0">
|
||||||
|
<div class="ui checkbox" v-for="policy in vAccessLogPolicies" style="width:10em;margin-bottom:0.8em">
|
||||||
|
<input type="checkbox" v-model="policy.isChecked" @change="changePolicy" />
|
||||||
|
<label>{{policy.name}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>是否只输出到日志策略</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui checkbox">
|
||||||
|
<input type="checkbox" v-model="accessLog.storageOnly"/>
|
||||||
|
<label></label>
|
||||||
|
</div>
|
||||||
|
<p class="comment">选中表示只输出日志到日志策略,而停止默认的日志存储。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="margin"></div>
|
||||||
|
</div>`
|
||||||
|
})
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Vue.component("charsets-box", {
|
Vue.component("http-charsets-box", {
|
||||||
props: ["v-usual-charsets", "v-all-charsets", "v-charset"],
|
props: ["v-usual-charsets", "v-all-charsets", "v-charset"],
|
||||||
data: function () {
|
data: function () {
|
||||||
let charset = this.vCharset
|
let charset = this.vCharset
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Vue.component("gzip-box", {
|
Vue.component("http-gzip-box", {
|
||||||
props: ["v-gzip-config"],
|
props: ["v-gzip-config"],
|
||||||
data: function () {
|
data: function () {
|
||||||
let gzip = this.vGzipConfig
|
let gzip = this.vGzipConfig
|
||||||
@@ -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"],
|
props: ["v-request-header-policy", "v-response-header-policy", "v-params"],
|
||||||
data: function () {
|
data: function () {
|
||||||
let type = "request"
|
let type = "request"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Vue.component("pages-and-shutdown-box", {
|
Vue.component("http-pages-and-shutdown-box", {
|
||||||
props: ["v-pages", "v-shutdown-config"],
|
props: ["v-pages", "v-shutdown-config"],
|
||||||
data: function () {
|
data: function () {
|
||||||
let pages = []
|
let pages = []
|
||||||
@@ -3,5 +3,13 @@
|
|||||||
{$template "/left_menu"}
|
{$template "/left_menu"}
|
||||||
|
|
||||||
<div class="right-box">
|
<div class="right-box">
|
||||||
<p class="ui message">此功能暂未开放,敬请期待。</p>
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
|
<http-access-log-config-box
|
||||||
|
:v-access-log-config="accessLogConfig"
|
||||||
|
:v-fields="fields"
|
||||||
|
:v-default-field-codes="defaultFieldCodes"
|
||||||
|
:v-access-log-policies="accessLogPolicies"></http-access-log-config-box>
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifyReloadSuccess("保存成功")
|
||||||
|
})
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="right-box">
|
<div class="right-box">
|
||||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
<input type="hidden" name="webId" :value="webId"/>
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
<charsets-box :v-usual-charsets="usualCharsets" :v-all-charsets="allCharsets" :v-charset="charset"></charsets-box>
|
<http-charsets-box :v-usual-charsets="usualCharsets" :v-all-charsets="allCharsets" :v-charset="charset"></http-charsets-box>
|
||||||
<submit-btn></submit-btn>
|
<submit-btn></submit-btn>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<input type="hidden" name="webId" :value="webId"/>
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
<input type="hidden" name="gzipId" :value="gzipConfig.id"/>
|
<input type="hidden" name="gzipId" :value="gzipConfig.id"/>
|
||||||
|
|
||||||
<gzip-box :v-gzip-config="gzipConfig"></gzip-box>
|
<http-gzip-box :v-gzip-config="gzipConfig"></http-gzip-box>
|
||||||
|
|
||||||
<div class="margin"></div>
|
<div class="margin"></div>
|
||||||
<submit-btn></submit-btn>
|
<submit-btn></submit-btn>
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
{$template "/left_menu"}
|
{$template "/left_menu"}
|
||||||
|
|
||||||
<div class="right-box">
|
<div class="right-box">
|
||||||
<header-policy-box :v-request-header-policy="requestHeaderPolicy" :v-response-header-policy="responseHeaderPolicy" :v-params="'serverId=' + serverId"></header-policy-box>
|
<http-header-policy-box :v-request-header-policy="requestHeaderPolicy" :v-response-header-policy="responseHeaderPolicy" :v-params="'serverId=' + serverId"></http-header-policy-box>
|
||||||
</div>
|
</div>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="right-box">
|
<div class="right-box">
|
||||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
<input type="hidden" name="webId" :value="webId"/>
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
<pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></pages-and-shutdown-box>
|
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></http-pages-and-shutdown-box>
|
||||||
<submit-btn></submit-btn>
|
<submit-btn></submit-btn>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user