MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Perform

Method Perform

internal/waf/action_block.go:70–147  ·  view source on GitHub ↗
(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter)

Source from the content-addressed store, hash-verified

68}
69
70func (this *BlockAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
71 // 加入到黑名单
72 var timeout = this.Timeout
73 if timeout <= 0 {
74 timeout = 300 // 默认封锁300秒
75 }
76
77 // 随机时长
78 var timeoutMax = this.TimeoutMax
79 if timeoutMax > timeout {
80 timeout = timeout + int32(rands.Int64()%int64(timeoutMax-timeout+1))
81 }
82
83 SharedIPBlackList.RecordIP(IPTypeAll, this.Scope, request.WAFServerId(), request.WAFRemoteIP(), time.Now().Unix()+int64(timeout), waf.Id, waf.UseLocalFirewall && (this.FailBlockScopeAll || this.Scope == firewallconfigs.FirewallScopeGlobal), group.Id, set.Id, "")
84
85 if writer != nil {
86 // close the connection
87 defer request.WAFClose()
88
89 // output response
90 if this.StatusCode > 0 {
91 request.ProcessResponseHeaders(writer.Header(), this.StatusCode)
92 writer.WriteHeader(this.StatusCode)
93 } else {
94 request.ProcessResponseHeaders(writer.Header(), http.StatusForbidden)
95 writer.WriteHeader(http.StatusForbidden)
96 }
97 if len(this.URL) > 0 {
98 if urlPrefixReg.MatchString(this.URL) {
99 req, err := http.NewRequest(http.MethodGet, this.URL, nil)
100 if err != nil {
101 logs.Error(err)
102 return PerformResult{}
103 }
104 req.Header.Set("User-Agent", teaconst.GlobalProductName+"/"+teaconst.Version)
105
106 resp, err := httpClient.Do(req)
107 if err != nil {
108 logs.Error(err)
109 return PerformResult{}
110 }
111 defer func() {
112 _ = resp.Body.Close()
113 }()
114
115 for k, v := range resp.Header {
116 for _, v1 := range v {
117 writer.Header().Add(k, v1)
118 }
119 }
120
121 var buf = utils.BytePool1k.Get()
122 _, _ = io.CopyBuffer(writer, resp.Body, buf.Bytes)
123 utils.BytePool1k.Put(buf)
124 } else {
125 var path = this.URL
126 if !filepath.IsAbs(this.URL) {
127 path = Tea.Root + string(os.PathSeparator) + path

Callers

nothing calls this directly

Calls 15

RecordIPMethod · 0.80
UnixMethod · 0.80
MatchStringMethod · 0.80
DoMethod · 0.80
WAFServerIdMethod · 0.65
WAFRemoteIPMethod · 0.65
WAFCloseMethod · 0.65
WriteHeaderMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected