diff --git a/localdb.go b/localdb.go
index 183a406..fd68291 100644
--- a/localdb.go
+++ b/localdb.go
@@ -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{})
+
}
}
diff --git a/localserver.go b/localserver.go
index f3de5ca..1e1ff1d 100644
--- a/localserver.go
+++ b/localserver.go
@@ -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{
diff --git a/localwaf/src/pages/waf-host/rule/add/index.less b/localwaf/src/pages/waf-host/rule/add/index.less
deleted file mode 100644
index d599763..0000000
--- a/localwaf/src/pages/waf-host/rule/add/index.less
+++ /dev/null
@@ -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);
- }
- }
-}
diff --git a/localwaf/src/pages/waf-host/rule/add/index.vue b/localwaf/src/pages/waf-host/rule/add/index.vue
deleted file mode 100644
index 7939b77..0000000
--- a/localwaf/src/pages/waf-host/rule/add/index.vue
+++ /dev/null
@@ -1,363 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ item.label }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 提交
-
- 重置
-
-
-
-
-
-
-
-
-
diff --git a/localwaf/src/pages/waf-host/rule/detail/index.less b/localwaf/src/pages/waf-host/rule/detail/index.less
deleted file mode 100644
index d599763..0000000
--- a/localwaf/src/pages/waf-host/rule/detail/index.less
+++ /dev/null
@@ -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);
- }
- }
-}
diff --git a/localwaf/src/pages/waf-host/rule/detail/index.vue b/localwaf/src/pages/waf-host/rule/detail/index.vue
deleted file mode 100644
index 0465fc8..0000000
--- a/localwaf/src/pages/waf-host/rule/detail/index.vue
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
-
-
-
创建时间
-
- {{ detail_data.create_time }}
-
-
-
-
网站
-
- {{ detail_data.host }}
-
-
-
-
网站端口
-
- {{ detail_data.port }}
-
-
-
-
加密证书
-
- {{ detail_data.ssl }}
-
-
-
-
后端系统类型
-
- {{ detail_data.remote_system }}
-
-
-
-
后端系统应用类型
-
- {{ detail_data.remote_app }}
-
-
-
-
后端域名
-
- {{ detail_data.remote_host }}
-
-
-
-
后端端口
-
- {{ detail_data.remote_port }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/localwaf/src/pages/waf-host/rule/edit/index.vue b/localwaf/src/pages/waf-host/rule/edit/index.vue
index 0465fc8..9412684 100644
--- a/localwaf/src/pages/waf-host/rule/edit/index.vue
+++ b/localwaf/src/pages/waf-host/rule/edit/index.vue
@@ -1,75 +1,203 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
创建时间
-
- {{ detail_data.create_time }}
-
-
-
-
网站
-
- {{ detail_data.host }}
-
-
-
-
网站端口
-
- {{ detail_data.port }}
-
-
-
-
加密证书
-
- {{ detail_data.ssl }}
-
-
-
-
后端系统类型
-
- {{ detail_data.remote_system }}
-
-
-
-
后端系统应用类型
-
- {{ detail_data.remote_app }}
-
-
-
-
后端域名
-
- {{ detail_data.remote_host }}
-
-
-
-
后端端口
-
- {{ detail_data.remote_port }}
-
-
-
-
-
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 提交
+
+ 重置
+
+
+
@@ -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);
+ }
+ },
},
};
diff --git a/localwaf/src/pages/waf-host/rule/index.vue b/localwaf/src/pages/waf-host/rule/index.vue
index 49a5752..b18403d 100644
--- a/localwaf/src/pages/waf-host/rule/index.vue
+++ b/localwaf/src/pages/waf-host/rule/index.vue
@@ -53,8 +53,7 @@
-
- 详情
+
编辑
删除
@@ -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",
+ },
},
);
},
diff --git a/localwaf/src/router/modules/wafhost.ts b/localwaf/src/router/modules/wafhost.ts
index 4f48780..0ea5d92 100644
--- a/localwaf/src/router/modules/wafhost.ts
+++ b/localwaf/src/router/modules/wafhost.ts
@@ -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},
+ },
],
},
];
diff --git a/main.go b/main.go
index 7340b5e..216d29f 100644
--- a/main.go
+++ b/main.go
@@ -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)
diff --git a/model/request/waf_rule_edit_req.go b/model/request/waf_rule_edit_req.go
index df8e335..2f3b415 100644
--- a/model/request/waf_rule_edit_req.go
+++ b/model/request/waf_rule_edit_req.go
@@ -2,5 +2,5 @@ package request
type WafRuleEditReq struct {
CODE string `json:"code"`
- RuleJson string
+ RuleJson string `json:"rulejson"`
}
diff --git a/model/rules.go b/model/rules.go
index 1383756..a4c7f38 100644
--- a/model/rules.go
+++ b/model/rules.go
@@ -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 删除
}