mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-09-01 04:47:58 +08:00
feat:规则增加查询处理
This commit is contained in:
+1
-1
@@ -84,7 +84,7 @@ func (w *WafRuleAPi) GetDetailApi(c *gin.Context) {
|
||||
}
|
||||
func (w *WafRuleAPi) GetListApi(c *gin.Context) {
|
||||
var req request.WafRuleSearchReq
|
||||
err := c.ShouldBind(&req)
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err == nil {
|
||||
wafRules, total, _ := wafRuleService.GetListApi(req)
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
|
||||
@@ -3,8 +3,8 @@ import request from '@/utils/request'
|
||||
export function wafRuleListApi(params) {
|
||||
return request({
|
||||
url: '/wafhost/rule/list',
|
||||
method: 'get',
|
||||
params: params
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
//删除规则
|
||||
|
||||
@@ -7,12 +7,25 @@
|
||||
<t-button variant="base" theme="default" :disabled="!selectedRowKeys.length"> 导出日志 </t-button>
|
||||
<p v-if="!!selectedRowKeys.length" class="selected-count">已选{{ selectedRowKeys.length }}项</p>
|
||||
</div>
|
||||
<t-input v-model="searchValue" class="search-input" placeholder="请输入你需要搜索的规则" clearable>
|
||||
<template #suffix-icon>
|
||||
<search-icon size="20px" />
|
||||
</template>
|
||||
</t-input>
|
||||
<div class="right-operation-container">
|
||||
<t-form ref="form" :data="searchformData" :label-width="80" colon :style="{ marginBottom: '8px' }">
|
||||
|
||||
<t-row>
|
||||
<span>网站:</span><t-select v-model="searchformData.host_code" clearable :style="{ width: '150px' }">
|
||||
<t-option v-for="(item, index) in host_dic" :value="index" :label="item" :key="index">
|
||||
{{ item }}
|
||||
</t-option>
|
||||
</t-select>
|
||||
<span>规则名:</span>
|
||||
<t-input v-model="searchformData.rule_name" class="search-input" placeholder="请输入你需要搜索的规则" clearable>
|
||||
</t-input>
|
||||
<t-button theme="primary" :style="{ marginLeft: '8px' }" @click="getList('all')"> 查询 </t-button>
|
||||
</t-row>
|
||||
</t-form>
|
||||
</div>
|
||||
|
||||
</t-row>
|
||||
|
||||
<t-alert theme="info" message="SamWaf防御规则,可进行脚本(首选),界面编辑" close>
|
||||
<template #operation>
|
||||
<span @click="handleJumpOnlineUrl">规则编辑在线文档</span>
|
||||
@@ -176,7 +189,11 @@ export default Vue.extend({
|
||||
current: 1,
|
||||
pageSize:10
|
||||
},
|
||||
searchValue: '',
|
||||
//顶部搜索
|
||||
searchformData: {
|
||||
rule_name:"",
|
||||
host_code:""
|
||||
},
|
||||
confirmVisible: false,
|
||||
deleteIdx: -1,
|
||||
//主机字典
|
||||
@@ -222,7 +239,8 @@ export default Vue.extend({
|
||||
wafRuleListApi(
|
||||
{
|
||||
pageSize: that.pagination.pageSize,
|
||||
pageIndex: that.pagination.current
|
||||
pageIndex: that.pagination.current,
|
||||
...that.searchformData
|
||||
}
|
||||
)
|
||||
.then((res) => {
|
||||
|
||||
@@ -4,5 +4,6 @@ import "SamWaf/model/common/request"
|
||||
|
||||
type WafRuleSearchReq struct {
|
||||
HostCode string `json:"host_code" form:"host_code"` //主机码
|
||||
RuleName string `json:"rule_name" form:"rule_name"` //规则名
|
||||
request.PageInfo
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ type RuleRouter struct {
|
||||
func (receiver *RuleRouter) InitRuleRouter(group *gin.RouterGroup) {
|
||||
ruleApi := api.APIGroupAPP.WafRuleAPi
|
||||
wafRuleRouter := group.Group("")
|
||||
wafRuleRouter.GET("/samwaf/wafhost/rule/list", ruleApi.GetListApi)
|
||||
wafRuleRouter.POST("/samwaf/wafhost/rule/list", ruleApi.GetListApi)
|
||||
wafRuleRouter.GET("/samwaf/wafhost/rule/detail", ruleApi.GetDetailApi)
|
||||
wafRuleRouter.POST("/samwaf/wafhost/rule/add", ruleApi.AddApi)
|
||||
wafRuleRouter.GET("/samwaf/wafhost/rule/del", ruleApi.DelRuleApi)
|
||||
|
||||
@@ -98,8 +98,34 @@ func (receiver *WafRuleService) GetDetailByCodeApi(ruleCode string) model.Rules
|
||||
func (receiver *WafRuleService) GetListApi(wafRuleSearchReq request.WafRuleSearchReq) ([]model.Rules, int64, error) {
|
||||
var total int64 = 0
|
||||
var rules []model.Rules
|
||||
global.GWAF_LOCAL_DB.Where("rule_status= 1").Limit(wafRuleSearchReq.PageSize).Offset(wafRuleSearchReq.PageSize * (wafRuleSearchReq.PageIndex - 1)).Find(&rules)
|
||||
global.GWAF_LOCAL_DB.Where("rule_status= 1 ").Model(&model.Rules{}).Count(&total)
|
||||
/*where条件*/
|
||||
var whereField = ""
|
||||
var whereValues []interface{}
|
||||
//where字段
|
||||
whereField = "rule_status=? "
|
||||
if len(wafRuleSearchReq.HostCode) > 0 {
|
||||
if len(whereField) > 0 {
|
||||
whereField = whereField + " and "
|
||||
}
|
||||
whereField = whereField + " host_code=? "
|
||||
}
|
||||
if len(wafRuleSearchReq.RuleName) > 0 {
|
||||
if len(whereField) > 0 {
|
||||
whereField = whereField + " and "
|
||||
}
|
||||
whereField = whereField + " rule_name=? "
|
||||
}
|
||||
//where字段赋值
|
||||
whereValues = append(whereValues, 1)
|
||||
if len(wafRuleSearchReq.HostCode) > 0 {
|
||||
whereValues = append(whereValues, wafRuleSearchReq.HostCode)
|
||||
}
|
||||
if len(wafRuleSearchReq.RuleName) > 0 {
|
||||
whereValues = append(whereValues, wafRuleSearchReq.RuleName)
|
||||
}
|
||||
|
||||
global.GWAF_LOCAL_DB.Debug().Model(&model.Rules{}).Where(whereField, whereValues...).Limit(wafRuleSearchReq.PageSize).Offset(wafRuleSearchReq.PageSize * (wafRuleSearchReq.PageIndex - 1)).Find(&rules)
|
||||
global.GWAF_LOCAL_DB.Debug().Model(&model.Rules{}).Where(whereField, whereValues...).Count(&total)
|
||||
|
||||
return rules, total, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user