[waf]可以配置阻止动作的状态码和提示内容

This commit is contained in:
GoEdgeLab
2020-11-22 16:54:31 +08:00
parent 37313cfe68
commit 5c68607583
6 changed files with 86 additions and 11 deletions

View File

@@ -47,11 +47,12 @@ func (this *PolicyAction) RunGet(params struct {
} }
this.Data["firewallPolicy"] = maps.Map{ this.Data["firewallPolicy"] = maps.Map{
"id": firewallPolicy.Id, "id": firewallPolicy.Id,
"name": firewallPolicy.Name, "name": firewallPolicy.Name,
"isOn": firewallPolicy.IsOn, "isOn": firewallPolicy.IsOn,
"description": firewallPolicy.Description, "description": firewallPolicy.Description,
"groups": internalGroups, "groups": internalGroups,
"blockOptions": firewallPolicy.BlockOptions,
} }
// 正在使用此策略的服务 // 正在使用此策略的服务

View File

@@ -8,6 +8,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"net/http"
) )
type UpdateAction struct { type UpdateAction struct {
@@ -30,11 +31,21 @@ func (this *UpdateAction) RunGet(params struct {
this.NotFound("firewallPolicy", params.FirewallPolicyId) this.NotFound("firewallPolicy", params.FirewallPolicyId)
return return
} }
if firewallPolicy.BlockOptions == nil {
firewallPolicy.BlockOptions = &firewallconfigs.HTTPFirewallBlockAction{
StatusCode: http.StatusForbidden,
Body: "Blocked By WAF",
URL: "",
}
}
this.Data["firewallPolicy"] = maps.Map{ this.Data["firewallPolicy"] = maps.Map{
"id": firewallPolicy.Id, "id": firewallPolicy.Id,
"name": firewallPolicy.Name, "name": firewallPolicy.Name,
"description": firewallPolicy.Description, "description": firewallPolicy.Description,
"isOn": firewallPolicy.IsOn, "isOn": firewallPolicy.IsOn,
"blockOptions": firewallPolicy.BlockOptions,
} }
// 预置分组 // 预置分组
@@ -63,6 +74,7 @@ func (this *UpdateAction) RunPost(params struct {
FirewallPolicyId int64 FirewallPolicyId int64
Name string Name string
GroupCodes []string GroupCodes []string
BlockOptionsJSON []byte
Description string Description string
IsOn bool IsOn bool
@@ -81,6 +93,7 @@ func (this *UpdateAction) RunPost(params struct {
Name: params.Name, Name: params.Name,
Description: params.Description, Description: params.Description,
FirewallGroupCodes: params.GroupCodes, FirewallGroupCodes: params.GroupCodes,
BlockOptionsJSON: params.BlockOptionsJSON,
}) })
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)

View File

@@ -0,0 +1,37 @@
Vue.component("http-firewall-block-options", {
props: ["v-block-options"],
data: function () {
return {
blockOptions: this.vBlockOptions,
statusCode: this.vBlockOptions.statusCode
}
},
watch: {
statusCode: function (v) {
let statusCode = parseInt(v)
if (isNaN(statusCode)) {
this.blockOptions.statusCode = 403
} else {
this.blockOptions.statusCode = statusCode
}
}
},
template: `<div>
<input type="hidden" name="blockOptionsJSON" :value="JSON.stringify(blockOptions)"/>
<table class="ui table">
<tr>
<td class="title">状态码</td>
<td>
<input type="text" v-model="statusCode" style="width:4.5em" maxlength="3"/>
</td>
</tr>
<tr>
<td>提示内容</td>
<td>
<textarea rows="3" v-model="blockOptions.body"></textarea>
</td>
</tr>
</table>
</div>
`
})

View File

@@ -41,7 +41,7 @@
<tbody v-for="set in sets" :data-set-id="set.id"> <tbody v-for="set in sets" :data-set-id="set.id">
<tr> <tr>
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td> <td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
<td><span :class="{disabled:!set.isOn}">{{set.name}}</span> <td nowrap=""><span :class="{disabled:!set.isOn}">{{set.name}}</span>
<p style="margin-top:0.5em"> <p style="margin-top:0.5em">
<label-on :v-is-on="set.isOn"></label-on> <label-on :v-is-on="set.isOn"></label-on>
</p> </p>
@@ -53,7 +53,7 @@
<span class="ui disabled" v-if="set.rules.length == 0">暂时还没有规则</span> <span class="ui disabled" v-if="set.rules.length == 0">暂时还没有规则</span>
</td> </td>
<td class="center">{{set.connector.toUpperCase()}}</td> <td class="center">{{set.connector.toUpperCase()}}</td>
<td><span :class="{red:set.action == 'BLOCK' || set.action == 'CAPTCHA', green:set.action != 'BLOCK' && set.action != 'CAPTCHA'}">{{set.actionName}}[{{set.action.toUpperCase()}}]</span> <td nowrap=""><span :class="{red:set.action == 'BLOCK' || set.action == 'CAPTCHA', green:set.action != 'BLOCK' && set.action != 'CAPTCHA'}">{{set.actionName}}[{{set.action.toUpperCase()}}]</span>
<div v-if="set.actionLinks != null && set.actionLinks.length > 0" style="margin-top:0.3em"> <div v-if="set.actionLinks != null && set.actionLinks.length > 0" style="margin-top:0.3em">
<span class="disabled">-&gt;</span> <span v-for="link in set.actionLinks"><a :href="link.url"><span class="disabled">[{{link.name}}]</span></a> &nbsp;</span> <span class="disabled">-&gt;</span> <span v-for="link in set.actionLinks"><a :href="link.url"><span class="disabled">[{{link.name}}]</span></a> &nbsp;</span>
</div> </div>

View File

@@ -21,6 +21,24 @@
<span class="ui label tiny basic" v-for="group in firewallPolicy.groups" style="margin-bottom:0.5em" :class="{disabled:!group.isOn}">{{group.name}}</span> <span class="ui label tiny basic" v-for="group in firewallPolicy.groups" style="margin-bottom:0.5em" :class="{disabled:!group.isOn}">{{group.name}}</span>
</td> </td>
</tr> </tr>
<tr>
<td>阻止动作设置</td>
<td>
<span v-if="firewallPolicy.blockOptions == null" class="disabled">还没有设置。</span>
<div v-else>
<table class="ui table">
<tr>
<td class="title">状态码</td>
<td>{{firewallPolicy.blockOptions.statusCode}}</td>
</tr>
<tr>
<td>提示内容</td>
<td>{{firewallPolicy.blockOptions.body}}</td>
</tr>
</table>
</div>
</td>
</tr>
<tr> <tr>
<td>描述</td> <td>描述</td>
<td> <td>

View File

@@ -24,6 +24,12 @@
<p class="comment">可以启用一些我们预置的规则组。</p> <p class="comment">可以启用一些我们预置的规则组。</p>
</td> </td>
</tr> </tr>
<tr>
<td>阻止动作配置</td>
<td>
<http-firewall-block-options :v-block-options="firewallPolicy.blockOptions"></http-firewall-block-options>
</td>
</tr>
<tr> <tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td> <td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr> </tr>