mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
WAF策略:可以修改分组代号/导入时可以根据名称合并/导出时可以导出停用的分组
This commit is contained in:
@@ -30,6 +30,7 @@ func (this *CreateGroupPopupAction) RunPost(params struct {
|
||||
Type string
|
||||
|
||||
Name string
|
||||
Code string
|
||||
Description string
|
||||
IsOn bool
|
||||
|
||||
@@ -52,6 +53,7 @@ func (this *CreateGroupPopupAction) RunPost(params struct {
|
||||
createResp, err := this.RPC().HTTPFirewallRuleGroupRPC().CreateHTTPFirewallRuleGroup(this.AdminContext(), &pb.CreateHTTPFirewallRuleGroupRequest{
|
||||
IsOn: params.IsOn,
|
||||
Name: params.Name,
|
||||
Code: params.Code,
|
||||
Description: params.Description,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -32,24 +32,36 @@ func (this *ExportAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
inboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||
outboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||
enabledInboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||
enabledOutboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||
|
||||
disabledInboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||
disabledOutboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||
|
||||
if policy.Inbound != nil {
|
||||
for _, g := range policy.Inbound.Groups {
|
||||
if g.IsOn {
|
||||
inboundGroups = append(inboundGroups, g)
|
||||
enabledInboundGroups = append(enabledInboundGroups, g)
|
||||
} else {
|
||||
disabledInboundGroups = append(disabledInboundGroups, g)
|
||||
}
|
||||
}
|
||||
}
|
||||
if policy.Outbound != nil {
|
||||
for _, g := range policy.Outbound.Groups {
|
||||
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()
|
||||
}
|
||||
@@ -116,5 +128,6 @@ func (this *ExportAction) RunPost(params struct {
|
||||
ttlcache.DefaultCache.Write(key, configJSON, time.Now().Unix()+600)
|
||||
|
||||
this.Data["key"] = key
|
||||
this.Data["id"] = params.FirewallPolicyId
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package waf
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/ttlcache"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -15,7 +16,8 @@ func (this *ExportDownloadAction) Init() {
|
||||
}
|
||||
|
||||
func (this *ExportDownloadAction) RunGet(params struct {
|
||||
Key string
|
||||
Key string
|
||||
PolicyId int64
|
||||
}) {
|
||||
item := ttlcache.DefaultCache.Read(params.Key)
|
||||
if item == nil || item.Value == nil {
|
||||
@@ -27,7 +29,7 @@ func (this *ExportDownloadAction) RunGet(params struct {
|
||||
|
||||
data, ok := item.Value.([]byte)
|
||||
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.Write(data)
|
||||
} else {
|
||||
|
||||
@@ -43,7 +43,8 @@ func (this *GroupsAction) RunGet(params struct {
|
||||
"isOn": g.IsOn,
|
||||
"description": g.Description,
|
||||
"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,
|
||||
"description": g.Description,
|
||||
"countSets": len(g.Sets),
|
||||
"canDelete": len(g.Code) == 0,
|
||||
"isTemplate": g.IsTemplate,
|
||||
"canDelete": !g.IsTemplate,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ func (this *UpdateGroupPopupAction) RunGet(params struct {
|
||||
"name": groupConfig.Name,
|
||||
"description": groupConfig.Description,
|
||||
"isOn": groupConfig.IsOn,
|
||||
"code": groupConfig.Code,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
@@ -43,6 +44,7 @@ func (this *UpdateGroupPopupAction) RunGet(params struct {
|
||||
func (this *UpdateGroupPopupAction) RunPost(params struct {
|
||||
GroupId int64
|
||||
Name string
|
||||
Code string
|
||||
Description string
|
||||
IsOn bool
|
||||
|
||||
@@ -59,6 +61,7 @@ func (this *UpdateGroupPopupAction) RunPost(params struct {
|
||||
FirewallRuleGroupId: params.GroupId,
|
||||
IsOn: params.IsOn,
|
||||
Name: params.Name,
|
||||
Code: params.Code,
|
||||
Description: params.Description,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
<p class="comment">给分组起一个容易识别的名称</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>代号</td>
|
||||
<td>
|
||||
<input type="text" name="code" maxlength="100"/>
|
||||
<p class="comment">在导入时可以合并相同代号的分组。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
||||
</tr>
|
||||
|
||||
@@ -7,27 +7,47 @@
|
||||
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">选择入站规则</td>
|
||||
<td class="title">启用的入站规则</td>
|
||||
<td>
|
||||
<span v-if="inboundGroups.length == 0" class="disabled">暂时还没有入站规则。</span>
|
||||
<div class="groups-box" v-show="inboundGroups.length > 0">
|
||||
<div v-for="g in inboundGroups" class="group-box">
|
||||
<span v-if="enabledInboundGroups.length == 0" class="disabled">暂时还没有入站规则。</span>
|
||||
<div class="groups-box" v-show="enabledInboundGroups.length > 0">
|
||||
<div v-for="g in enabledInboundGroups" class="group-box">
|
||||
<checkbox name="inboundGroupIds" :value="true" :v-value="g.id">{{g.name}}</checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="disabledInboundGroups.length > 0">
|
||||
<td class="title">停用的入站规则</td>
|
||||
<td>
|
||||
<div class="groups-box" v-show="disabledInboundGroups.length > 0">
|
||||
<div v-for="g in disabledInboundGroups" class="group-box">
|
||||
<checkbox name="inboundGroupIds" :value="false" :v-value="g.id">{{g.name}} <sup><span class="red">停用</span></sup></checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>选择出站规则</td>
|
||||
<td>启用的出站规则</td>
|
||||
<td>
|
||||
<span v-if="outboundGroups.length == 0" class="disabled">暂时还没有出站规则。</span>
|
||||
<div class="groups-box" v-show="outboundGroups.length > 0">
|
||||
<div v-for="g in outboundGroups" class="group-box">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</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}} <sup><span class="red">停用</span></sup></checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn>导出</submit-btn>
|
||||
</form>
|
||||
@@ -1,5 +1,5 @@
|
||||
Tea.context(function () {
|
||||
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
|
||||
}
|
||||
})
|
||||
@@ -8,6 +8,13 @@
|
||||
<td class="title">名称</td>
|
||||
<td>{{group.name}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>代号</td>
|
||||
<td>
|
||||
<span v-if="group.code.length > 0">{{group.code}}</span>
|
||||
<span v-else class="disabled">没有设置。</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>描述</td>
|
||||
<td>
|
||||
|
||||
@@ -22,7 +22,6 @@ Tea.context(function () {
|
||||
// 更改分组
|
||||
this.updateGroup = function (groupId) {
|
||||
teaweb.popup("/servers/components/waf/updateGroupPopup?groupId=" + groupId, {
|
||||
height: "16em",
|
||||
callback: function () {
|
||||
teaweb.success("保存成功", function () {
|
||||
window.location.reload()
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
<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 red">停用</span>
|
||||
<span v-if="group.code.length > 0" 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.isTemplate" class="ui label basic tiny">自定义</span>
|
||||
<span v-if="group.code.length > 0" class="ui label basic tiny">代号:{{group.code}}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="center">
|
||||
|
||||
@@ -57,7 +57,6 @@ Tea.context(function () {
|
||||
// 添加分组
|
||||
this.createGroup = function (type) {
|
||||
teaweb.popup("/servers/components/waf/createGroupPopup?firewallPolicyId=" + this.firewallPolicyId + "&type=" + type, {
|
||||
height: "16em",
|
||||
callback: function () {
|
||||
teaweb.success("保存成功", function () {
|
||||
window.location.reload()
|
||||
|
||||
@@ -12,6 +12,13 @@
|
||||
<p class="comment">给分组起一个容易识别的名称</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>代号</td>
|
||||
<td>
|
||||
<input type="text" name="code" maxlength="100" v-model="group.code"/>
|
||||
<p class="comment">在导入时可以合并相同代号的分组。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user