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

Method Perform

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

Source from the content-addressed store, hash-verified

134}
135
136func (this *RecordIPAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
137 var ipListId = this.IPListId
138 if ipListId <= 0 {
139 ipListId = firewallconfigs.GlobalListId
140 }
141
142 // 是否已删除
143 var ipListIsAvailable = (ipListId == firewallconfigs.GlobalListId) || (ipListId > 0 && !this.IPListIsDeleted && !ExistDeletedIPList(ipListId))
144
145 // 是否在本地白名单中
146 if SharedIPWhiteList.Contains("set:"+types.String(set.Id), this.Scope, request.WAFServerId(), request.WAFRemoteIP()) {
147 return PerformResult{
148 ContinueRequest: true,
149 IsAllowed: true,
150 AllowScope: AllowScopeGlobal,
151 }
152 }
153
154 var timeout = this.Timeout
155 var isForever = false
156 if timeout <= 0 {
157 isForever = true
158 timeout = 86400 // 1天
159 }
160 var expiresAt = time.Now().Unix() + int64(timeout)
161
162 if this.Type == "black" {
163 request.ProcessResponseHeaders(writer.Header(), http.StatusForbidden)
164 writer.WriteHeader(http.StatusForbidden)
165
166 request.WAFClose()
167
168 // 先加入本地的黑名单
169 if ipListIsAvailable {
170 SharedIPBlackList.Add(IPTypeAll, this.Scope, request.WAFServerId(), request.WAFRemoteIP(), expiresAt)
171 }
172 } else {
173 // 加入本地白名单
174 if ipListIsAvailable {
175 SharedIPWhiteList.Add("set:"+types.String(set.Id), this.Scope, request.WAFServerId(), request.WAFRemoteIP(), expiresAt)
176 }
177 }
178
179 // 上报
180 if ipListId > 0 && ipListIsAvailable {
181 var serverId int64
182 if this.Scope == firewallconfigs.FirewallScopeServer {
183 serverId = request.WAFServerId()
184 }
185
186 var realExpiresAt = expiresAt
187 if isForever {
188 realExpiresAt = 0
189 }
190
191 select {
192 case recordIPTaskChan <- &recordIPTask{
193 ip: request.WAFRemoteIP(),

Callers

nothing calls this directly

Calls 11

ExistDeletedIPListFunction · 0.85
UnixMethod · 0.80
WAFServerIdMethod · 0.65
WAFRemoteIPMethod · 0.65
WriteHeaderMethod · 0.65
WAFCloseMethod · 0.65
AddMethod · 0.65
ContainsMethod · 0.45
StringMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected