WAF策略:可以修改分组代号/导入时可以根据名称合并/导出时可以导出停用的分组

This commit is contained in:
刘祥超
2021-12-12 20:24:15 +08:00
parent 16b4eb67d4
commit 8f06bccd48
13 changed files with 85 additions and 23 deletions

View File

@@ -30,6 +30,7 @@ func (this *CreateGroupPopupAction) RunPost(params struct {
Type string Type string
Name string Name string
Code string
Description string Description string
IsOn bool IsOn bool
@@ -52,6 +53,7 @@ func (this *CreateGroupPopupAction) RunPost(params struct {
createResp, err := this.RPC().HTTPFirewallRuleGroupRPC().CreateHTTPFirewallRuleGroup(this.AdminContext(), &pb.CreateHTTPFirewallRuleGroupRequest{ createResp, err := this.RPC().HTTPFirewallRuleGroupRPC().CreateHTTPFirewallRuleGroup(this.AdminContext(), &pb.CreateHTTPFirewallRuleGroupRequest{
IsOn: params.IsOn, IsOn: params.IsOn,
Name: params.Name, Name: params.Name,
Code: params.Code,
Description: params.Description, Description: params.Description,
}) })
if err != nil { if err != nil {

View File

@@ -32,24 +32,36 @@ func (this *ExportAction) RunGet(params struct {
return return
} }
inboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{} enabledInboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
outboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{} enabledOutboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
disabledInboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
disabledOutboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
if policy.Inbound != nil { if policy.Inbound != nil {
for _, g := range policy.Inbound.Groups { for _, g := range policy.Inbound.Groups {
if g.IsOn { if g.IsOn {
inboundGroups = append(inboundGroups, g) enabledInboundGroups = append(enabledInboundGroups, g)
} else {
disabledInboundGroups = append(disabledInboundGroups, g)
} }
} }
} }
if policy.Outbound != nil { if policy.Outbound != nil {
for _, g := range policy.Outbound.Groups { for _, g := range policy.Outbound.Groups {
if g.IsOn { if g.IsOn {
outboundGroups = append(outboundGroups, g) enabledOutboundGroups = append(enabledOutboundGroups, g)
} else {
disabledOutboundGroups = append(disabledOutboundGroups, g)
} }
} }
} }
this.Data["inboundGroups"] = inboundGroups
this.Data["outboundGroups"] = outboundGroups this.Data["enabledInboundGroups"] = enabledInboundGroups
this.Data["enabledOutboundGroups"] = enabledOutboundGroups
this.Data["disabledInboundGroups"] = disabledInboundGroups
this.Data["disabledOutboundGroups"] = disabledOutboundGroups
this.Show() this.Show()
} }
@@ -116,5 +128,6 @@ func (this *ExportAction) RunPost(params struct {
ttlcache.DefaultCache.Write(key, configJSON, time.Now().Unix()+600) ttlcache.DefaultCache.Write(key, configJSON, time.Now().Unix()+600)
this.Data["key"] = key this.Data["key"] = key
this.Data["id"] = params.FirewallPolicyId
this.Success() this.Success()
} }

View File

@@ -3,6 +3,7 @@ package waf
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/ttlcache" "github.com/TeaOSLab/EdgeAdmin/internal/ttlcache"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/types"
"strconv" "strconv"
) )
@@ -16,6 +17,7 @@ func (this *ExportDownloadAction) Init() {
func (this *ExportDownloadAction) RunGet(params struct { func (this *ExportDownloadAction) RunGet(params struct {
Key string Key string
PolicyId int64
}) { }) {
item := ttlcache.DefaultCache.Read(params.Key) item := ttlcache.DefaultCache.Read(params.Key)
if item == nil || item.Value == nil { if item == nil || item.Value == nil {
@@ -27,7 +29,7 @@ func (this *ExportDownloadAction) RunGet(params struct {
data, ok := item.Value.([]byte) data, ok := item.Value.([]byte)
if ok { if ok {
this.AddHeader("Content-Disposition", "attachment; filename=\"WAF.json\";") this.AddHeader("Content-Disposition", "attachment; filename=\"WAF-"+types.String(params.PolicyId)+".json\";")
this.AddHeader("Content-Length", strconv.Itoa(len(data))) this.AddHeader("Content-Length", strconv.Itoa(len(data)))
this.Write(data) this.Write(data)
} else { } else {

View File

@@ -43,7 +43,8 @@ func (this *GroupsAction) RunGet(params struct {
"isOn": g.IsOn, "isOn": g.IsOn,
"description": g.Description, "description": g.Description,
"countSets": len(g.Sets), "countSets": len(g.Sets),
"canDelete": len(g.Code) == 0, "isTemplate": g.IsTemplate,
"canDelete": !g.IsTemplate,
}) })
} }
} }
@@ -60,7 +61,8 @@ func (this *GroupsAction) RunGet(params struct {
"isOn": g.IsOn, "isOn": g.IsOn,
"description": g.Description, "description": g.Description,
"countSets": len(g.Sets), "countSets": len(g.Sets),
"canDelete": len(g.Code) == 0, "isTemplate": g.IsTemplate,
"canDelete": !g.IsTemplate,
}) })
} }
} }

View File

@@ -35,6 +35,7 @@ func (this *UpdateGroupPopupAction) RunGet(params struct {
"name": groupConfig.Name, "name": groupConfig.Name,
"description": groupConfig.Description, "description": groupConfig.Description,
"isOn": groupConfig.IsOn, "isOn": groupConfig.IsOn,
"code": groupConfig.Code,
} }
this.Show() this.Show()
@@ -43,6 +44,7 @@ func (this *UpdateGroupPopupAction) RunGet(params struct {
func (this *UpdateGroupPopupAction) RunPost(params struct { func (this *UpdateGroupPopupAction) RunPost(params struct {
GroupId int64 GroupId int64
Name string Name string
Code string
Description string Description string
IsOn bool IsOn bool
@@ -59,6 +61,7 @@ func (this *UpdateGroupPopupAction) RunPost(params struct {
FirewallRuleGroupId: params.GroupId, FirewallRuleGroupId: params.GroupId,
IsOn: params.IsOn, IsOn: params.IsOn,
Name: params.Name, Name: params.Name,
Code: params.Code,
Description: params.Description, Description: params.Description,
}) })
if err != nil { if err != nil {

View File

@@ -13,6 +13,13 @@
<p class="comment">给分组起一个容易识别的名称</p> <p class="comment">给分组起一个容易识别的名称</p>
</td> </td>
</tr> </tr>
<tr>
<td>代号</td>
<td>
<input type="text" name="code" maxlength="100"/>
<p class="comment">在导入时可以合并相同代号的分组。</p>
</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>

View File

@@ -7,27 +7,47 @@
<table class="ui table definition selectable"> <table class="ui table definition selectable">
<tr> <tr>
<td class="title">选择入站规则</td> <td class="title">启用的入站规则</td>
<td> <td>
<span v-if="inboundGroups.length == 0" class="disabled">暂时还没有入站规则。</span> <span v-if="enabledInboundGroups.length == 0" class="disabled">暂时还没有入站规则。</span>
<div class="groups-box" v-show="inboundGroups.length > 0"> <div class="groups-box" v-show="enabledInboundGroups.length > 0">
<div v-for="g in inboundGroups" class="group-box"> <div v-for="g in enabledInboundGroups" class="group-box">
<checkbox name="inboundGroupIds" :value="true" :v-value="g.id">{{g.name}}</checkbox> <checkbox name="inboundGroupIds" :value="true" :v-value="g.id">{{g.name}}</checkbox>
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr v-if="disabledInboundGroups.length > 0">
<td>选择出站规则</td> <td class="title">停用的入站规则</td>
<td> <td>
<span v-if="outboundGroups.length == 0" class="disabled">暂时还没有出站规则。</span> <div class="groups-box" v-show="disabledInboundGroups.length > 0">
<div class="groups-box" v-show="outboundGroups.length > 0"> <div v-for="g in disabledInboundGroups" class="group-box">
<div v-for="g in outboundGroups" class="group-box"> <checkbox name="inboundGroupIds" :value="false" :v-value="g.id">{{g.name}} &nbsp;<sup><span class="red">停用</span></sup></checkbox>
</div>
</div>
</td>
</tr>
<tr>
<td>启用的出站规则</td>
<td>
<span v-if="enabledOutboundGroups.length == 0" class="disabled">暂时还没有出站规则。</span>
<div class="groups-box" v-show="enabledOutboundGroups.length > 0">
<div v-for="g in enabledOutboundGroups" class="group-box">
<checkbox name="outboundGroupIds" :value="true" :v-value="g.id">{{g.name}}</checkbox> <checkbox name="outboundGroupIds" :value="true" :v-value="g.id">{{g.name}}</checkbox>
</div> </div>
</div> </div>
</td> </td>
</tr> </tr>
<tr v-if="disabledOutboundGroups.length > 0">
<td>停用的出站规则</td>
<td>
<div class="groups-box" v-show="disabledOutboundGroups.length > 0">
<div v-for="g in disabledOutboundGroups" class="group-box">
<checkbox name="outboundGroupIds" :value="false" :v-value="g.id">{{g.name}} &nbsp;<sup><span class="red">停用</span></sup></checkbox>
</div>
</div>
</td>
</tr>
</table> </table>
<submit-btn>导出</submit-btn> <submit-btn>导出</submit-btn>
</form> </form>

View File

@@ -1,5 +1,5 @@
Tea.context(function () { Tea.context(function () {
this.success = function (resp) { this.success = function (resp) {
window.location = "/servers/components/waf/exportDownload?key=" + resp.data.key window.location = "/servers/components/waf/exportDownload?key=" + resp.data.key + "&policyId=" + resp.data.id
} }
}) })

View File

@@ -8,6 +8,13 @@
<td class="title">名称</td> <td class="title">名称</td>
<td>{{group.name}}</td> <td>{{group.name}}</td>
</tr> </tr>
<tr>
<td>代号</td>
<td>
<span v-if="group.code.length > 0">{{group.code}}</span>
<span v-else class="disabled">没有设置。</span>
</td>
</tr>
<tr> <tr>
<td>描述</td> <td>描述</td>
<td> <td>

View File

@@ -22,7 +22,6 @@ Tea.context(function () {
// 更改分组 // 更改分组
this.updateGroup = function (groupId) { this.updateGroup = function (groupId) {
teaweb.popup("/servers/components/waf/updateGroupPopup?groupId=" + groupId, { teaweb.popup("/servers/components/waf/updateGroupPopup?groupId=" + groupId, {
height: "16em",
callback: function () { callback: function () {
teaweb.success("保存成功", function () { teaweb.success("保存成功", function () {
window.location.reload() window.location.reload()

View File

@@ -25,8 +25,9 @@
<p style="margin-top: 0.5em"> <p style="margin-top: 0.5em">
<span v-if="group.isOn" class="ui label tiny basic green">启用</span> <span v-if="group.isOn" class="ui label tiny basic green">启用</span>
<span v-if="!group.isOn" class="ui label tiny basic red">停用</span> <span v-if="!group.isOn" class="ui label tiny basic red">停用</span>
<span v-if="group.code.length > 0" class="ui label basic tiny">预置</span> <span v-if="group.isTemplate" class="ui label basic tiny">预置</span>
<span v-if="group.code.length == 0" class="ui label basic tiny">自定义</span> <span v-if="!group.isTemplate" class="ui label basic tiny">自定义</span>
<span v-if="group.code.length > 0" class="ui label basic tiny">代号:{{group.code}}</span>
</p> </p>
</td> </td>
<td class="center"> <td class="center">

View File

@@ -57,7 +57,6 @@ Tea.context(function () {
// 添加分组 // 添加分组
this.createGroup = function (type) { this.createGroup = function (type) {
teaweb.popup("/servers/components/waf/createGroupPopup?firewallPolicyId=" + this.firewallPolicyId + "&type=" + type, { teaweb.popup("/servers/components/waf/createGroupPopup?firewallPolicyId=" + this.firewallPolicyId + "&type=" + type, {
height: "16em",
callback: function () { callback: function () {
teaweb.success("保存成功", function () { teaweb.success("保存成功", function () {
window.location.reload() window.location.reload()

View File

@@ -12,6 +12,13 @@
<p class="comment">给分组起一个容易识别的名称</p> <p class="comment">给分组起一个容易识别的名称</p>
</td> </td>
</tr> </tr>
<tr>
<td>代号</td>
<td>
<input type="text" name="code" maxlength="100" v-model="group.code"/>
<p class="comment">在导入时可以合并相同代号的分组。</p>
</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>