2020-10-08 11:11:37 +08:00
|
|
|
package waf
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2020-11-17 15:41:43 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-10-08 11:11:37 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-12-23 09:52:31 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
2020-10-08 11:11:37 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DeleteSetAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *DeleteSetAction) RunPost(params struct {
|
|
|
|
|
GroupId int64
|
|
|
|
|
SetId int64
|
|
|
|
|
}) {
|
2020-11-17 15:41:43 +08:00
|
|
|
// 日志
|
2020-11-20 15:32:42 +08:00
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "删除WAF规则分组 %d 中的规则集 %d", params.GroupId, params.SetId)
|
2020-11-17 15:41:43 +08:00
|
|
|
|
2020-12-23 09:52:31 +08:00
|
|
|
groupConfig, err := dao.SharedHTTPFirewallRuleGroupDAO.FindRuleGroupConfig(this.AdminContext(), params.GroupId)
|
2020-10-08 11:11:37 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if groupConfig == nil {
|
|
|
|
|
this.NotFound("firewallRuleGroup", params.GroupId)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newRefs := []*firewallconfigs.HTTPFirewallRuleSetRef{}
|
|
|
|
|
for _, ref := range groupConfig.SetRefs {
|
|
|
|
|
if ref.SetId != params.SetId {
|
|
|
|
|
newRefs = append(newRefs, ref)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
newRefsJSON, err := json.Marshal(newRefs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
_, err = this.RPC().HTTPFirewallRuleGroupRPC().UpdateHTTPFirewallRuleGroupSets(this.AdminContext(), &pb.UpdateHTTPFirewallRuleGroupSetsRequest{
|
|
|
|
|
FirewallRuleGroupId: params.GroupId,
|
|
|
|
|
FirewallRuleSetsJSON: newRefsJSON,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|