完善增加编辑

This commit is contained in:
samwaf
2022-10-10 17:09:21 +08:00
parent df797808b9
commit db28bf001a
12 changed files with 352 additions and 860 deletions
+3
View File
@@ -19,5 +19,8 @@ func InitDb() {
db.AutoMigrate(&innerbean.WebLog{})
db.AutoMigrate(&model.Hosts{})
db.AutoMigrate(&model.Rules{})
//重启需要删除无效规则
db.Where("user_code = ? and rule_status = 999", global.GWAF_USER_CODE).Delete(model.Rules{})
}
}
+12 -14
View File
@@ -315,7 +315,7 @@ func StartLocalServer() {
var total int64 = 0
var rules []model.Rules
global.GWAF_LOCAL_DB.Debug().Limit(waf_rule_search_req.PageSize).Offset(waf_rule_search_req.PageSize * (waf_rule_search_req.PageIndex - 1)).Find(&rules)
global.GWAF_LOCAL_DB.Debug().Where("user_code=? and rule_status= 1", global.GWAF_USER_CODE).Limit(waf_rule_search_req.PageSize).Offset(waf_rule_search_req.PageSize * (waf_rule_search_req.PageIndex - 1)).Find(&rules)
global.GWAF_LOCAL_DB.Debug().Model(&model.Rules{}).Count(&total)
c.JSON(http.StatusOK, response.Response{
@@ -404,17 +404,11 @@ func StartLocalServer() {
})
return
}
var rulename = rule_info.RuleBase.RuleName //中文名
if waf_rule_edit_req.CODE != rule_info.RuleBase.RuleDomainCode {
c.JSON(http.StatusOK, response.Response{
Code: -1,
Msg: "网站识别码不匹配",
})
return
}
var rule_name = rule_info.RuleBase.RuleName //中文名
var rule model.Rules
global.GWAF_LOCAL_DB.Debug().Where("rulename = ? and code= ?",
rulename, rule_info.RuleBase.RuleDomainCode).Find(&rule)
global.GWAF_LOCAL_DB.Debug().Where("rule_name = ? and host_code= ?",
rule_name, rule_info.RuleBase.RuleDomainCode).Find(&rule)
if rule.Id != 0 && rule.RuleCode != waf_rule_edit_req.CODE {
c.JSON(http.StatusOK, response.Response{
@@ -424,13 +418,13 @@ func StartLocalServer() {
return
}
global.GWAF_LOCAL_DB.Debug().Where("rule_code=?", waf_rule_edit_req.CODE).Find(rule)
global.GWAF_LOCAL_DB.Debug().Where("rule_code=?", waf_rule_edit_req.CODE).Find(&rule)
rule_info.RuleBase.RuleName = strings.Replace(rule.RuleCode, "-", "", -1)
ruleMap := map[string]interface{}{
"HostCode": rule_info.RuleBase.RuleDomainCode, //TODO 注意字典名称
"RuleName": rulename,
"RuleName": rule_name,
"RuleContent": rule_tool.GenRuleInfo(rule_info),
"RuleContentJSON": waf_rule_edit_req.RuleJson, //TODO 后续考虑是否应该再从结构转一次
"RuleVersionName": "初版",
@@ -490,7 +484,11 @@ func StartLocalServer() {
})
return
}
err = global.GWAF_LOCAL_DB.Where("rule_code = ?", waf_rule_del_req.CODE).Delete(model.Rules{}).Error
rule_map := map[string]interface{}{
"RuleStatus": "999",
"RuleVersion": 999999,
}
err = global.GWAF_LOCAL_DB.Model(model.Rules{}).Where("rule_code = ?", waf_rule_del_req.CODE).Updates(rule_map).Error
if err != nil {
c.JSON(http.StatusOK, response.Response{
@@ -1,106 +0,0 @@
@import '@/style/variables.less';
.detail-base {
/deep/ .t-card {
padding: 8px;
}
/deep/ .t-card__title {
font-size: 20px;
font-weight: 500;
}
&-info-steps {
padding-top: 12px;
}
}
.info-block {
column-count: 2;
.info-item {
padding: 12px 0;
display: flex;
color: var(--td-text-color-primary);
h1 {
width: 200px;
font-weight: normal;
font-size: @font-size-base;
color: var(--td-text-color-secondary);
text-align: left;
line-height: 22px;
@media (max-width: @screen-sm-max) {
width: 100px;
}
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) {
width: 120px;
}
}
span {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-left: 24px;
}
i {
display: inline-block;
width: 8px;
height: 8px;
border-radius: @border-radius-50;
background: var(--td-success-color-5);
}
.inProgress {
color: var(--td-success-color-5);
}
.pdf {
color: var(--td-brand-color);
&:hover {
cursor: pointer;
}
}
}
}
.dialog-info-block {
.info-item {
padding: 12px 0;
display: flex;
h1 {
width: 84px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: var(--td-text-color-secondary);
text-align: left;
line-height: 22px;
}
span {
margin-left: 24px;
}
i {
display: inline-block;
width: 8px;
height: 8px;
border-radius: @border-radius-50;
background: var(--td-success-color-5);
}
.green {
color: var(--td-success-color-5);
}
.blue {
color: var(--td-brand-color-8);
}
}
}
@@ -1,363 +0,0 @@
<template>
<div class="detail-base">
<t-form :data="formData" @submit="onSubmit"> <!--:rules="rules"-->
<!--基本信息 开始-->
<t-card title="基本信息">
<t-form-item label="规则名称" name="rule_name">
<t-input placeholder="请输入内容" v-model="formData.rule_base.rule_name" />
</t-form-item>
<t-form-item label="防护网站" name="rule_domain_code">
<t-input placeholder="请输入内容" v-model="formData.rule_base.rule_domain_code" />
</t-form-item>
<t-form-item label="防护级别" name="salience">
<t-input placeholder="请输入内容" v-model="formData.rule_base.salience" />
</t-form-item>
</t-card>
<!--基本信息 结束-->
<!--规则编排 开始-->
<t-card title="规则编排">
<t-form-item label="关系" name="relation_symbol">
<t-select clearable :style="{ width: '480px' }"
v-model="formData.rule_condition_detail.relation_detail.relation_symbol">
<t-option v-for="(item, index) in relation_symbol_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
<t-card title="条件" v-for="condition_item in formData.rule_condition_detail.relation_detail">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }">
<t-col :span="4">
<div>
<t-form-item label="内置实体名称">
<t-select clearable :style="{ width: '480px' }" v-model="condition_item.fact_name">
<t-option v-for="(item, index) in fact_option" :value="item.value" :label="item.label" :key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="作用域" name="attr">
<t-select clearable :style="{ width: '480px' }" v-model="condition_item.attr">
<t-option v-for="(item, index) in attr_option" :value="item.value" :label="item.label" :key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="值类型" name="attr_type">
<t-select clearable :style="{ width: '480px' }" v-model="condition_item.attr_type">
<t-option v-for="(item, index) in attr_type_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
</t-row>
<t-form-item label="值" name="att_val">
<t-input placeholder="请输入内容" v-model="condition_item.attr_val" />
</t-form-item>
</t-card>
</t-card>
<!--规则编排 结束-->
<!--符合则执行部分 开始-->
<t-card title="符合则执行如下">
<!--赋值总区块 开始-->
<t-card title="赋值">
<t-card title="赋值明细" v-for="do_assignment_item in formData.rule_do_assignment">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }">
<t-col :span="4">
<div>
<t-form-item label="内置实体名称">
<t-select clearable :style="{ width: '480px' }" v-model="do_assignment_item.fact_name">
<t-option v-for="(item, index) in fact_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="作用域" name="attr">
<t-select clearable :style="{ width: '480px' }" v-model="do_assignment_item.attr">
<t-option v-for="(item, index) in attr_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="值类型" name="attr_type">
<t-select clearable :style="{ width: '480px' }" v-model="do_assignment_item.attr_type">
<t-option v-for="(item, index) in attr_type_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
</t-row>
<t-form-item label="值" name="att_val">
<t-input placeholder="请输入内容" v-model="do_assignment_item.attr_val" />
</t-form-item>
</t-card>
</t-card>
<!--赋值总区块 结束-->
<!--方法执行总区块 开始-->
<t-card title="方法执行">
<!--方法执行明细 开始-->
<t-card title="方法明细" v-for="do_method_item in formData.rule_do_method">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }">
<t-col :span="6">
<div>
<t-form-item label="内置实体名称">
<t-select clearable :style="{ width: '480px' }" v-model="do_method_item.fact_name">
<t-option v-for="(item, index) in fact_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="6">
<div>
<t-form-item label="内置方法名称">
<t-select clearable :style="{ width: '480px' }" v-model="do_method_item.method_name">
<t-option v-for="(item, index) in method_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
</t-row>
<!--传参列表明细 开始-->
<t-card title="传参">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }"
v-for="do_method_parms_item in do_method_item.parms">
<t-col :span="6">
<div>
<t-form-item label="值类型" name="attr_type">
<t-select clearable :style="{ width: '480px' }" v-model="do_method_parms_item.attr_type">
<t-option v-for="(item, index) in attr_type_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="6">
<div>
<t-form-item label="值" name="att_val">
<t-input placeholder="请输入内容" v-model="do_method_parms_item.attr_val" />
</t-form-item>
</div>
</t-col>
</t-row>
</t-card>
<!--传参列表明细 结束-->
</t-card>
<!--方法执行明细 结束-->
</t-card>
<!--方法执行总区块 结束-->
</t-card>
<!--符合则执行部分 结束-->
<t-form-item style="margin-left: 100px">
<t-space size="10px">
<!-- type = submit,表单中的提交按钮,原生行为 -->
<t-button theme="primary" type="submit">提交</t-button>
<!-- type = reset,表单中的重置按钮,原生行为 -->
<t-button theme="default" variant="base" type="reset">重置</t-button>
</t-space>
</t-form-item>
</t-form>
</div>
</template>
<script lang="ts">
import {
prefix
} from '@/config/global';
import {
RULE
} from '@/service/service-rule';
export default {
name: 'WafRuleAdd',
data() {
return {
prefix,
detail_data: {},
rules: {
rule_name: [{ required: true, message: '请输入规则名称', type: 'error' }],
},
fact_option: [{
label: '默认',
value: 'MF'
}, ],
method_option: [{
label: '做动作',
value: 'DoSomeThing'
}, ],
attr_option: [{
label: '网址',
value: 'URL'
},
{
label: '请求端口',
value: 'PORT'
},
{
label: '访客IP',
value: 'SRC_IP'
},
],
attr_type_option: [{
label: '文本',
value: 'string'
},
{
label: '数字',
value: 'int'
},
],
relation_symbol_option: [{
label: '并且',
value: '&&'
},
{
label: '或者',
value: 'or'
},
],
formData: {
...RULE
},
};
},
beforeRouteUpdate(to, from) {
console.log('beforeRouteUpdate')
},
mounted() {
console.log('----mounted----')
console.log(RULE)
//console.log(this.$route.params.req_uuid);
//this.getDetail(this.$route.params.req_uuid);
this.getDetail(this.$route.query.req_uuid);
},
beforeCreate() {
console.log('----beforeCreate----')
},
created() {
console.log('----created----')
},
beforeMount() {
console.log('----beforeMount----')
},
beforeUpdate() {
console.log('----beforeUpdate----')
},
updated() {
console.log('----updated----')
},
watch: {
'$route.query.code'(newVal, oldVal) {
console.log('route.query.code changed', newVal, oldVal)
this.getDetail(newVal)
},
},
methods: {
getDetail(id) {
let that = this
this.$request
.get('/wafhost/host/detail', {
params: {
CODE: id,
}
})
.then((res) => {
let resdata = res.data
console.log(resdata)
if (resdata.code === 200) {
//const { list = [] } = resdata.data.list;
that.detail_data = resdata.data;
}
})
.catch((e: Error) => {
console.log(e);
})
.finally(() => {});
},
onSubmit({ result, firstError }): void {
let that = this
if (!firstError) {
let postdata = {...that.formData}
this.$request
.post('/wafhost/rule/add', {
RuleJson: JSON.stringify(postdata)
})
.then((res) => {
let resdata = res.data
console.log(resdata)
if (resdata.code === 200) {
that.$message.success(resdata.msg);
this.$router.push(
{
path:'/waf-host/wafrule',
},
);
}else{
that.$message.warning(resdata.msg);
}
})
.catch((e: Error) => {
console.log(e);
})
.finally(() => {
});
} else {
console.log('Errors: ', result);
that.$message.warning(firstError);
}
},
},
};
</script>
<style lang="less" scoped>
@import './index';
</style>
@@ -1,106 +0,0 @@
@import '@/style/variables.less';
.detail-base {
/deep/ .t-card {
padding: 8px;
}
/deep/ .t-card__title {
font-size: 20px;
font-weight: 500;
}
&-info-steps {
padding-top: 12px;
}
}
.info-block {
column-count: 2;
.info-item {
padding: 12px 0;
display: flex;
color: var(--td-text-color-primary);
h1 {
width: 200px;
font-weight: normal;
font-size: @font-size-base;
color: var(--td-text-color-secondary);
text-align: left;
line-height: 22px;
@media (max-width: @screen-sm-max) {
width: 100px;
}
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) {
width: 120px;
}
}
span {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-left: 24px;
}
i {
display: inline-block;
width: 8px;
height: 8px;
border-radius: @border-radius-50;
background: var(--td-success-color-5);
}
.inProgress {
color: var(--td-success-color-5);
}
.pdf {
color: var(--td-brand-color);
&:hover {
cursor: pointer;
}
}
}
}
.dialog-info-block {
.info-item {
padding: 12px 0;
display: flex;
h1 {
width: 84px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: var(--td-text-color-secondary);
text-align: left;
line-height: 22px;
}
span {
margin-left: 24px;
}
i {
display: inline-block;
width: 8px;
height: 8px;
border-radius: @border-radius-50;
background: var(--td-success-color-5);
}
.green {
color: var(--td-success-color-5);
}
.blue {
color: var(--td-brand-color-8);
}
}
}
@@ -1,153 +0,0 @@
<template>
<div class="detail-base">
<t-card title="网站详情">
<div class="info-block">
<div class="info-item">
<h1> 创建时间</h1>
<span>
{{ detail_data.create_time }}
</span>
</div>
<div class="info-item">
<h1> 网站</h1>
<span>
{{ detail_data.host }}
</span>
</div>
<div class="info-item">
<h1> 网站端口</h1>
<span>
{{ detail_data.port }}
</span>
</div>
<div class="info-item">
<h1> 加密证书</h1>
<span>
{{ detail_data.ssl }}
</span>
</div>
<div class="info-item">
<h1> 后端系统类型</h1>
<span>
{{ detail_data.remote_system }}
</span>
</div>
<div class="info-item">
<h1> 后端系统应用类型</h1>
<span>
{{ detail_data.remote_app }}
</span>
</div>
<div class="info-item">
<h1> 后端域名</h1>
<span>
{{ detail_data.remote_host }}
</span>
</div>
<div class="info-item">
<h1> 后端端口</h1>
<span>
{{ detail_data.remote_port }}
</span>
</div>
</div>
</t-card>
<t-card title="最近配置记录" class="container-base-margin-top">
<t-list :split="true">
<t-list-item>
<t-list-item-meta title="请求头" :description="detail_data.header"></t-list-item-meta>
</t-list-item>
<t-list-item>
<t-list-item-meta title="请求用户浏览器" :description="detail_data.user_agent"></t-list-item-meta>
</t-list-item>
<t-list-item>
<t-list-item-meta title="请求cookies" :description="detail_data.cookies"></t-list-item-meta>
</t-list-item>
<t-list-item>
<t-list-item-meta title="请求BODY" :description="detail_data.body"></t-list-item-meta>
</t-list-item>
</t-list>
</t-card>
</div>
</template>
<script lang="ts">
import {
prefix
} from '@/config/global';
import model from '@/service/service-detail-base';
export default {
name: 'WafAttackLogDetail',
data() {
return {
prefix,
baseInfoData: model.getBaseInfoData(),
detail_data: {}
};
},
beforeRouteUpdate(to, from) {
console.log('beforeRouteUpdate')
},
mounted() {
console.log('----mounted----')
//console.log(this.$route.params.req_uuid);
//this.getDetail(this.$route.params.req_uuid);
this.getDetail(this.$route.query.req_uuid);
},
beforeCreate() {
console.log('----beforeCreate----')
},
created() {
console.log('----created----')
},
beforeMount() {
console.log('----beforeMount----')
},
beforeUpdate() {
console.log('----beforeUpdate----')
},
updated() {
console.log('----updated----')
},
watch: {
'$route.query.code'(newVal, oldVal) {
console.log('route.query.code changed', newVal, oldVal)
this.getDetail(newVal)
},
},
methods: {
getDetail(id) {
let that = this
this.$request
.get('/wafhost/host/detail', {
params: {
CODE: id,
}
})
.then((res) => {
let resdata = res.data
console.log(resdata)
if (resdata.code === 200) {
//const { list = [] } = resdata.data.list;
that.detail_data = resdata.data;
}
})
.catch((e: Error) => {
console.log(e);
})
.finally(() => {});
},
},
};
</script>
<style lang="less" scoped>
@import './index';
</style>
+311 -78
View File
@@ -1,75 +1,203 @@
<template>
<div class="detail-base">
<t-card title="网站详情">
<div class="info-block">
<t-form :data="formData" @submit="onSubmit"> <!--:rules="rules"-->
<!--基本信息 开始-->
<t-card title="基本信息">
<t-form-item label="规则名称" name="rule_name">
<t-input placeholder="请输入内容" v-model="formData.rule_base.rule_name" />
</t-form-item>
<t-form-item label="防护网站" name="rule_domain_code">
<t-input placeholder="请输入内容" v-model="formData.rule_base.rule_domain_code" />
</t-form-item>
<t-form-item label="防护级别" name="salience">
<t-input placeholder="请输入内容" v-model="formData.rule_base.salience" />
</t-form-item>
</t-card>
<!--基本信息 结束-->
<div class="info-item">
<h1> 创建时间</h1>
<span>
{{ detail_data.create_time }}
</span>
</div>
<div class="info-item">
<h1> 网站</h1>
<span>
{{ detail_data.host }}
</span>
</div>
<div class="info-item">
<h1> 网站端口</h1>
<span>
{{ detail_data.port }}
</span>
</div>
<div class="info-item">
<h1> 加密证书</h1>
<span>
{{ detail_data.ssl }}
</span>
</div>
<div class="info-item">
<h1> 后端系统类型</h1>
<span>
{{ detail_data.remote_system }}
</span>
</div>
<div class="info-item">
<h1> 后端系统应用类型</h1>
<span>
{{ detail_data.remote_app }}
</span>
</div>
<div class="info-item">
<h1> 后端域名</h1>
<span>
{{ detail_data.remote_host }}
</span>
</div>
<div class="info-item">
<h1> 后端端口</h1>
<span>
{{ detail_data.remote_port }}
</span>
</div>
</div>
</t-card>
<t-card title="最近配置记录" class="container-base-margin-top">
<!--规则编排 开始-->
<t-card title="规则编排">
<t-form-item label="关系" name="relation_symbol">
<t-select clearable :style="{ width: '480px' }"
v-model="formData.rule_condition_detail.relation_symbol">
<t-option v-for="(item, index) in relation_symbol_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
<t-card title="条件" v-for="condition_item in formData.rule_condition_detail.relation_detail">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }">
<t-col :span="4">
<div>
<t-form-item label="内置实体名称">
<t-select clearable :style="{ width: '480px' }" v-model="condition_item.fact_name">
<t-option v-for="(item, index) in fact_option" :value="item.value" :label="item.label" :key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="作用域" name="attr">
<t-select clearable :style="{ width: '480px' }" v-model="condition_item.attr">
<t-option v-for="(item, index) in attr_option" :value="item.value" :label="item.label" :key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="值类型" name="attr_type">
<t-select clearable :style="{ width: '480px' }" v-model="condition_item.attr_type">
<t-option v-for="(item, index) in attr_type_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
</t-row>
<t-form-item label="值" name="att_val">
<t-input placeholder="请输入内容" v-model="condition_item.attr_val" />
</t-form-item>
</t-card>
</t-card>
<!--规则编排 结束-->
<t-list :split="true">
<t-list-item>
<t-list-item-meta title="请求头" :description="detail_data.header"></t-list-item-meta>
</t-list-item>
<t-list-item>
<t-list-item-meta title="请求用户浏览器" :description="detail_data.user_agent"></t-list-item-meta>
</t-list-item>
<t-list-item>
<t-list-item-meta title="请求cookies" :description="detail_data.cookies"></t-list-item-meta>
</t-list-item>
<t-list-item>
<t-list-item-meta title="请求BODY" :description="detail_data.body"></t-list-item-meta>
</t-list-item>
</t-list>
</t-card>
<!--符合则执行部分 开始-->
<t-card title="符合则执行如下">
<!--赋值总区块 开始-->
<t-card title="赋值">
<t-card title="赋值明细" v-for="do_assignment_item in formData.rule_do_assignment">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }">
<t-col :span="4">
<div>
<t-form-item label="内置实体名称">
<t-select clearable :style="{ width: '480px' }" v-model="do_assignment_item.fact_name">
<t-option v-for="(item, index) in fact_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="作用域" name="attr">
<t-select clearable :style="{ width: '480px' }" v-model="do_assignment_item.attr">
<t-option v-for="(item, index) in attr_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="4">
<div>
<t-form-item label="值类型" name="attr_type">
<t-select clearable :style="{ width: '480px' }" v-model="do_assignment_item.attr_type">
<t-option v-for="(item, index) in attr_type_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
</t-row>
<t-form-item label="值" name="att_val">
<t-input placeholder="请输入内容" v-model="do_assignment_item.attr_val" />
</t-form-item>
</t-card>
</t-card>
<!--赋值总区块 结束-->
<!--方法执行总区块 开始-->
<t-card title="方法执行">
<!--方法执行明细 开始-->
<t-card title="方法明细" v-for="do_method_item in formData.rule_do_method">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }">
<t-col :span="6">
<div>
<t-form-item label="内置实体名称">
<t-select clearable :style="{ width: '480px' }" v-model="do_method_item.fact_name">
<t-option v-for="(item, index) in fact_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="6">
<div>
<t-form-item label="内置方法名称">
<t-select clearable :style="{ width: '480px' }" v-model="do_method_item.method_name">
<t-option v-for="(item, index) in method_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
</t-row>
<!--传参列表明细 开始-->
<t-card title="传参">
<t-row :gutter="{ xs: 8, sm: 16, md: 24, lg: 32, xl: 32, xxl: 40 }"
v-for="do_method_parms_item in do_method_item.parms">
<t-col :span="6">
<div>
<t-form-item label="值类型" name="attr_type">
<t-select clearable :style="{ width: '480px' }" v-model="do_method_parms_item.attr_type">
<t-option v-for="(item, index) in attr_type_option" :value="item.value" :label="item.label"
:key="index">
{{ item.label }}
</t-option>
</t-select>
</t-form-item>
</div>
</t-col>
<t-col :span="6">
<div>
<t-form-item label="值" name="att_val">
<t-input placeholder="请输入内容" v-model="do_method_parms_item.attr_val" />
</t-form-item>
</div>
</t-col>
</t-row>
</t-card>
<!--传参列表明细 结束-->
</t-card>
<!--方法执行明细 结束-->
</t-card>
<!--方法执行总区块 结束-->
</t-card>
<!--符合则执行部分 结束-->
<t-form-item style="margin-left: 100px">
<t-space size="10px">
<!-- type = submit,表单中的提交按钮,原生行为 -->
<t-button theme="primary" type="submit">提交</t-button>
<!-- type = reset,表单中的重置按钮,原生行为 -->
<t-button theme="default" variant="base" type="reset">重置</t-button>
</t-space>
</t-form-item>
</t-form>
</div>
@@ -78,15 +206,64 @@
import {
prefix
} from '@/config/global';
import model from '@/service/service-detail-base';
import {
RULE
} from '@/service/service-rule';
export default {
name: 'WafAttackLogDetail',
name: 'WafRuleEdit',
data() {
return {
op_type :"add",
op_rule_no :"",//规则识别号
prefix,
baseInfoData: model.getBaseInfoData(),
detail_data: {}
detail_data: {},
rules: {
rule_name: [{ required: true, message: '请输入规则名称', type: 'error' }],
},
fact_option: [{
label: '默认',
value: 'MF'
}, ],
method_option: [{
label: '做动作',
value: 'DoSomeThing'
}, ],
attr_option: [{
label: '网址',
value: 'URL'
},
{
label: '请求端口',
value: 'PORT'
},
{
label: '访客IP',
value: 'SRC_IP'
},
],
attr_type_option: [{
label: '文本',
value: 'string'
},
{
label: '数字',
value: 'int'
},
],
relation_symbol_option: [{
label: '并且',
value: '&&'
},
{
label: '或者',
value: 'or'
},
],
formData: {
...RULE
},
};
},
beforeRouteUpdate(to, from) {
@@ -94,10 +271,18 @@
},
mounted() {
console.log('----mounted----')
console.log(RULE)
//console.log(this.$route.params.req_uuid);
//this.getDetail(this.$route.params.req_uuid);
this.getDetail(this.$route.query.req_uuid);
if(this.$route.query.code != undefined){
this.op_rule_no = this.$route.query.code
this.getDetail(this.op_rule_no);
}
if(this.$route.query.type != undefined){
this.op_type = this.$route.query.type
}
},
beforeCreate() {
console.log('----beforeCreate----')
@@ -115,8 +300,14 @@
console.log('----updated----')
},
watch: {
'$route.query.type'(newVal, oldVal) {
console.log('route.query.type changed', newVal, oldVal)
//this.getDetail(newVal)
this.op_type = newVal
},
'$route.query.code'(newVal, oldVal) {
console.log('route.query.code changed', newVal, oldVal)
this.op_rule_no = newVal
this.getDetail(newVal)
},
},
@@ -124,7 +315,7 @@
getDetail(id) {
let that = this
this.$request
.get('/wafhost/host/detail', {
.get('/wafhost/rule/detail', {
params: {
CODE: id,
}
@@ -134,10 +325,10 @@
console.log(resdata)
if (resdata.code === 200) {
//const { list = [] } = resdata.data.list;
that.detail_data = resdata.data;
//const { list = [] } = resdata.data;
that.formData = JSON.parse(resdata.data.rule_content_json);
console.log('返回的', that.formData )
}
})
.catch((e: Error) => {
@@ -145,6 +336,48 @@
})
.finally(() => {});
},
onSubmit({ result, firstError }): void {
let that = this
if (!firstError) {
let postdata = {}
let url = ''
if(that.op_type == "add"){
url = '/wafhost/rule/add'
postdata = {RuleJson : JSON.stringify(that.formData)}
}else{
url = '/wafhost/rule/edit'
postdata = {Code:that.op_rule_no,RuleJson : JSON.stringify(that.formData)}
}
this.$request
.post(url, {
...postdata
})
.then((res) => {
let resdata = res.data
console.log(resdata)
if (resdata.code === 200) {
that.$message.success(resdata.msg);
this.$router.push(
{
path:'/waf-host/wafrule',
},
);
}else{
that.$message.warning(resdata.msg);
}
})
.catch((e: Error) => {
console.log(e);
})
.finally(() => {
});
} else {
console.log('Errors: ', result);
that.$message.warning(firstError);
}
},
},
};
</script>
+18 -21
View File
@@ -53,8 +53,7 @@
</p>
</template>
<template #op="slotProps">
<a class="t-button-link" @click="handleClickDetail(slotProps)">详情</a>
<template #op="slotProps">
<a class="t-button-link" @click="handleClickEdit(slotProps)">编辑</a>
<a class="t-button-link" @click="handleClickDelete(slotProps)">删除</a>
</template>
@@ -149,7 +148,7 @@ export default Vue.extend({
title: '操作',
},
],
rowKey: 'code',
rowKey: 'rule_code',
tableLayout: 'auto',
verticalAlign: 'top',
hover: true,
@@ -228,30 +227,28 @@ export default Vue.extend({
rehandleChange(changeParams, triggerAndData) {
console.log('统一Change', changeParams, triggerAndData);
},
handleClickDetail(e) {
console.log(e)
const { code } = e.row
console.log(code)
this.$router.push(
{
path:'/waf-host/wafhostdetail',
query: {
code: code,
},
},
);
},
handleClickEdit(e) {
console.log(e)
const { code } = e.row
console.log(code)
this.editFormVisible = true
this.getDetail(code)
const { rule_code } = e.row
console.log(rule_code)
this.$router.push(
{
path:'/waf-host/wafruleedit',
query: {
type: "edit",
code: rule_code
},
},
);
},
handleAddRule() {
this.$router.push(
{
path:'/waf-host/WafruleAdd'
path:'/waf-host/wafruleedit',
query: {
type: "add",
},
},
);
},
+4 -16
View File
@@ -28,25 +28,13 @@ export default [
name: 'WafRule',
component: () => import('@/pages/waf-host/rule/index.vue'),
meta: { title: '防御规则' },
},
{
path: 'wafruledetail',
name: 'WafruleDetail',
component: () => import('@/pages/waf-host/rule/detail/index.vue'),
meta: { title: '防御规则详情' ,hidden: true,keepAlive:false},
},
{
path: 'wafruleadd',
name: 'WafruleAdd',
component: () => import('@/pages/waf-host/rule/add/index.vue'),
meta: { title: '防御规则添加' ,keepAlive:false},
},
},
{
path: 'wafruleedit',
name: 'WafruleEdit',
name: 'Wafruleedit',
component: () => import('@/pages/waf-host/rule/edit/index.vue'),
meta: { title: '防御规则编辑' ,hidden: true,keepAlive:false},
},
meta: { title: '防御规则编辑' ,keepAlive:false},
},
],
},
];
+2 -1
View File
@@ -44,7 +44,7 @@ func main() {
continue
}
var ruleconfig model.Rules
global.GWAF_LOCAL_DB.Debug().Where("host_code = ? and user_code=? ", code, global.GWAF_USER_CODE).Find(&ruleconfig)
global.GWAF_LOCAL_DB.Debug().Where("host_code = ? and user_code=? and rule_status= 1 ", code, global.GWAF_USER_CODE).Find(&ruleconfig)
if ruleconfig.RuleVersion > hostTarget[host].RuleData.RuleVersion {
//说明该code有更新
hostRuleChan <- ruleconfig
@@ -59,6 +59,7 @@ func main() {
for {
select {
case remoteConfig := <-hostRuleChan:
//TODO 需要把删除的那部分数据从数据口里面去掉
hostTarget[hostCode[remoteConfig.HostCode]].RuleData = remoteConfig
hostTarget[hostCode[remoteConfig.HostCode]].Rule.LoadRule(remoteConfig)
log.Println(remoteConfig)
+1 -1
View File
@@ -2,5 +2,5 @@ package request
type WafRuleEditReq struct {
CODE string `json:"code"`
RuleJson string
RuleJson string `json:"rulejson"`
}
+1 -1
View File
@@ -12,5 +12,5 @@ type Rules struct {
RuleVersion int `json:"rule_version"` //规则版本号
UserCode string `json:"user_code"` //用户编码
IsPublicRule int `json:"is_public_rule"` //是否为公共规则
RuleStatus string `json:"rule_status"` //规则是否开启 1,开启 0,关闭不生效
RuleStatus int `json:"rule_status"` //规则是否开启 1,开启 0,关闭不生效 999 删除
}