mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	WAF增加“跳转”动作
This commit is contained in:
		@@ -15,6 +15,9 @@ type PageAction struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *PageAction) Init(waf *WAF) error {
 | 
					func (this *PageAction) Init(waf *WAF) error {
 | 
				
			||||||
 | 
						if this.Status <= 0 {
 | 
				
			||||||
 | 
							this.Status = http.StatusForbidden
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										43
									
								
								internal/waf/action_redirect.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								internal/waf/action_redirect.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package waf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RedirectAction struct {
 | 
				
			||||||
 | 
						BaseAction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Status int    `yaml:"status" json:"status"`
 | 
				
			||||||
 | 
						URL    string `yaml:"url" json:"url"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (this *RedirectAction) Init(waf *WAF) error {
 | 
				
			||||||
 | 
						if this.Status <= 0 {
 | 
				
			||||||
 | 
							this.Status = http.StatusTemporaryRedirect
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (this *RedirectAction) Code() string {
 | 
				
			||||||
 | 
						return ActionRedirect
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (this *RedirectAction) IsAttack() bool {
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// WillChange determine if the action will change the request
 | 
				
			||||||
 | 
					func (this *RedirectAction) WillChange() bool {
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Perform the action
 | 
				
			||||||
 | 
					func (this *RedirectAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) (continueRequest bool, goNextSet bool) {
 | 
				
			||||||
 | 
						writer.Header().Set("Location", this.URL)
 | 
				
			||||||
 | 
						writer.WriteHeader(this.Status)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return false, false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -15,6 +15,7 @@ const (
 | 
				
			|||||||
	ActionRecordIP         ActionString = "record_ip" // 记录IP
 | 
						ActionRecordIP         ActionString = "record_ip" // 记录IP
 | 
				
			||||||
	ActionTag              ActionString = "tag"       // 标签
 | 
						ActionTag              ActionString = "tag"       // 标签
 | 
				
			||||||
	ActionPage             ActionString = "page"      // 显示网页
 | 
						ActionPage             ActionString = "page"      // 显示网页
 | 
				
			||||||
 | 
						ActionRedirect         ActionString = "redirect"  // 跳转
 | 
				
			||||||
	ActionAllow            ActionString = "allow"     // allow
 | 
						ActionAllow            ActionString = "allow"     // allow
 | 
				
			||||||
	ActionGoGroup          ActionString = "go_group"  // go to next rule group
 | 
						ActionGoGroup          ActionString = "go_group"  // go to next rule group
 | 
				
			||||||
	ActionGoSet            ActionString = "go_set"    // go to next rule set
 | 
						ActionGoSet            ActionString = "go_set"    // go to next rule set
 | 
				
			||||||
@@ -87,6 +88,12 @@ var AllActions = []*ActionDefinition{
 | 
				
			|||||||
		Instance: new(PageAction),
 | 
							Instance: new(PageAction),
 | 
				
			||||||
		Type:     reflect.TypeOf(new(PageAction)).Elem(),
 | 
							Type:     reflect.TypeOf(new(PageAction)).Elem(),
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							Name:     "跳转",
 | 
				
			||||||
 | 
							Code:     ActionRedirect,
 | 
				
			||||||
 | 
							Instance: new(RedirectAction),
 | 
				
			||||||
 | 
							Type:     reflect.TypeOf(new(RedirectAction)).Elem(),
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		Name:     "跳到下一个规则分组",
 | 
							Name:     "跳到下一个规则分组",
 | 
				
			||||||
		Code:     ActionGoGroup,
 | 
							Code:     ActionGoGroup,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user