mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	WAF策略中增加验证码相关定制设置
This commit is contained in:
		@@ -268,6 +268,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx,
 | 
			
		||||
	inboundJSON []byte,
 | 
			
		||||
	outboundJSON []byte,
 | 
			
		||||
	blockOptionsJSON []byte,
 | 
			
		||||
	captchaOptionsJSON []byte,
 | 
			
		||||
	mode firewallconfigs.FirewallMode,
 | 
			
		||||
	useLocalFirewall bool,
 | 
			
		||||
	synFloodConfig *firewallconfigs.SYNFloodConfig,
 | 
			
		||||
@@ -275,7 +276,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx,
 | 
			
		||||
	if policyId <= 0 {
 | 
			
		||||
		return errors.New("invalid policyId")
 | 
			
		||||
	}
 | 
			
		||||
	op := NewHTTPFirewallPolicyOperator()
 | 
			
		||||
	var op = NewHTTPFirewallPolicyOperator()
 | 
			
		||||
	op.Id = policyId
 | 
			
		||||
	op.IsOn = isOn
 | 
			
		||||
	op.Name = name
 | 
			
		||||
@@ -291,9 +292,12 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx,
 | 
			
		||||
	} else {
 | 
			
		||||
		op.Outbound = "null"
 | 
			
		||||
	}
 | 
			
		||||
	if len(blockOptionsJSON) > 0 {
 | 
			
		||||
	if IsNotNull(blockOptionsJSON) {
 | 
			
		||||
		op.BlockOptions = blockOptionsJSON
 | 
			
		||||
	}
 | 
			
		||||
	if IsNotNull(captchaOptionsJSON) {
 | 
			
		||||
		op.CaptchaOptions = captchaOptionsJSON
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if synFloodConfig != nil {
 | 
			
		||||
		synFloodConfigJSON, err := json.Marshal(synFloodConfig)
 | 
			
		||||
@@ -456,7 +460,7 @@ func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId in
 | 
			
		||||
 | 
			
		||||
	// Block动作配置
 | 
			
		||||
	if IsNotNull(policy.BlockOptions) {
 | 
			
		||||
		blockAction := &firewallconfigs.HTTPFirewallBlockAction{}
 | 
			
		||||
		var blockAction = &firewallconfigs.HTTPFirewallBlockAction{}
 | 
			
		||||
		err = json.Unmarshal(policy.BlockOptions, blockAction)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return config, err
 | 
			
		||||
@@ -464,6 +468,16 @@ func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId in
 | 
			
		||||
		config.BlockOptions = blockAction
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Captcha动作配置
 | 
			
		||||
	if IsNotNull(policy.CaptchaOptions) {
 | 
			
		||||
		var captchaAction = &firewallconfigs.HTTPFirewallCaptchaAction{}
 | 
			
		||||
		err = json.Unmarshal(policy.CaptchaOptions, captchaAction)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return config, err
 | 
			
		||||
		}
 | 
			
		||||
		config.CaptchaOptions = captchaAction
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// syn flood
 | 
			
		||||
	if IsNotNull(policy.SynFlood) {
 | 
			
		||||
		var synFloodConfig = &firewallconfigs.SYNFloodConfig{}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ type HTTPFirewallPolicy struct {
 | 
			
		||||
	Inbound          dbs.JSON `field:"inbound"`          // 入站规则
 | 
			
		||||
	Outbound         dbs.JSON `field:"outbound"`         // 出站规则
 | 
			
		||||
	BlockOptions     dbs.JSON `field:"blockOptions"`     // BLOCK选项
 | 
			
		||||
	CaptchaOptions   dbs.JSON `field:"captchaOptions"`   // 验证码选项
 | 
			
		||||
	Mode             string   `field:"mode"`             // 模式
 | 
			
		||||
	UseLocalFirewall uint8    `field:"useLocalFirewall"` // 是否自动使用本地防火墙
 | 
			
		||||
	SynFlood         dbs.JSON `field:"synFlood"`         // SynFlood防御设置
 | 
			
		||||
@@ -39,6 +40,7 @@ type HTTPFirewallPolicyOperator struct {
 | 
			
		||||
	Inbound          interface{} // 入站规则
 | 
			
		||||
	Outbound         interface{} // 出站规则
 | 
			
		||||
	BlockOptions     interface{} // BLOCK选项
 | 
			
		||||
	CaptchaOptions   interface{} // 验证码选项
 | 
			
		||||
	Mode             interface{} // 模式
 | 
			
		||||
	UseLocalFirewall interface{} // 是否自动使用本地防火墙
 | 
			
		||||
	SynFlood         interface{} // SynFlood防御设置
 | 
			
		||||
 
 | 
			
		||||
@@ -173,7 +173,7 @@ func (this *HTTPFirewallPolicyService) UpdateHTTPFirewallPolicy(ctx context.Cont
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	templatePolicy := firewallconfigs.HTTPFirewallTemplate()
 | 
			
		||||
	var templatePolicy = firewallconfigs.HTTPFirewallTemplate()
 | 
			
		||||
 | 
			
		||||
	tx := this.NullTx()
 | 
			
		||||
 | 
			
		||||
@@ -186,18 +186,18 @@ func (this *HTTPFirewallPolicyService) UpdateHTTPFirewallPolicy(ctx context.Cont
 | 
			
		||||
		return nil, errors.New("can not found firewall policy")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	inboundConfig := firewallPolicy.Inbound
 | 
			
		||||
	var inboundConfig = firewallPolicy.Inbound
 | 
			
		||||
	if inboundConfig == nil {
 | 
			
		||||
		inboundConfig = &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	outboundConfig := firewallPolicy.Outbound
 | 
			
		||||
	var outboundConfig = firewallPolicy.Outbound
 | 
			
		||||
	if outboundConfig == nil {
 | 
			
		||||
		outboundConfig = &firewallconfigs.HTTPFirewallOutboundConfig{IsOn: true}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 更新老的
 | 
			
		||||
	oldCodes := []string{}
 | 
			
		||||
	var oldCodes = []string{}
 | 
			
		||||
	if firewallPolicy.Inbound != nil {
 | 
			
		||||
		for _, g := range firewallPolicy.Inbound.Groups {
 | 
			
		||||
			if len(g.Code) > 0 {
 | 
			
		||||
@@ -301,7 +301,7 @@ func (this *HTTPFirewallPolicyService) UpdateHTTPFirewallPolicy(ctx context.Cont
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedHTTPFirewallPolicyDAO.UpdateFirewallPolicy(tx, req.HttpFirewallPolicyId, req.IsOn, req.Name, req.Description, inboundConfigJSON, outboundConfigJSON, req.BlockOptionsJSON, req.Mode, req.UseLocalFirewall, synFloodConfig, logConfig)
 | 
			
		||||
	err = models.SharedHTTPFirewallPolicyDAO.UpdateFirewallPolicy(tx, req.HttpFirewallPolicyId, req.IsOn, req.Name, req.Description, inboundConfigJSON, outboundConfigJSON, req.BlockOptionsJSON, req.CaptchaOptionsJSON, req.Mode, req.UseLocalFirewall, synFloodConfig, logConfig)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user