mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-17 22:30:25 +08:00
WAF支持更多动作
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user