WAF支持更多动作

This commit is contained in:
刘祥超
2021-07-14 22:45:52 +08:00
parent 6a5c979d2a
commit 9c231a2b8c
14 changed files with 836 additions and 145 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"strconv"
"strings"
)
type CreateSetPopupAction struct {
@@ -53,6 +52,7 @@ func (this *CreateSetPopupAction) RunGet(params struct {
},
}
// 所有可选的动作
actionMaps := []maps.Map{}
for _, action := range firewallconfigs.AllActions {
actionMaps = append(actionMaps, maps.Map{
@@ -69,10 +69,10 @@ func (this *CreateSetPopupAction) RunGet(params struct {
func (this *CreateSetPopupAction) RunPost(params struct {
GroupId int64
Name string
RulesJSON []byte
Connector string
Action string
Name string
RulesJSON []byte
Connector string
ActionsJSON []byte
Must *actions.Must
}) {
@@ -96,32 +96,34 @@ func (this *CreateSetPopupAction) RunPost(params struct {
err = json.Unmarshal(params.RulesJSON, &rules)
if err != nil {
this.ErrorPage(err)
return
}
if len(rules) == 0 {
this.Fail("请添加至少一个规则")
}
setConfig := &firewallconfigs.HTTPFirewallRuleSet{
Id: 0,
IsOn: true,
Name: params.Name,
Code: "",
Description: "",
Connector: params.Connector,
RuleRefs: nil,
Rules: rules,
Action: params.Action,
ActionOptions: maps.Map{},
var actionConfigs = []*firewallconfigs.HTTPFirewallActionConfig{}
if len(params.ActionsJSON) > 0 {
err = json.Unmarshal(params.ActionsJSON, &actionConfigs)
if err != nil {
this.ErrorPage(err)
return
}
}
if len(actionConfigs) == 0 {
this.Fail("请添加至少一个动作")
}
for k, v := range this.ParamsMap {
if len(v) == 0 {
continue
}
index := strings.Index(k, "action_")
if index > -1 {
setConfig.ActionOptions[k[len("action_"):]] = v[0]
}
setConfig := &firewallconfigs.HTTPFirewallRuleSet{
Id: 0,
IsOn: true,
Name: params.Name,
Code: "",
Description: "",
Connector: params.Connector,
RuleRefs: nil,
Rules: rules,
Actions: actionConfigs,
}
setConfigJSON, err := json.Marshal(setConfig)