Archived
修复WAF记录IP动作时无法不超时的Bug
This commit is contained in:
@@ -18,7 +18,7 @@ import (
|
|||||||
type recordIPTask struct {
|
type recordIPTask struct {
|
||||||
ip string
|
ip string
|
||||||
listId int64
|
listId int64
|
||||||
expiredAt int64
|
expiresAt int64
|
||||||
level string
|
level string
|
||||||
serverId int64
|
serverId int64
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ func init() {
|
|||||||
IpListId: task.listId,
|
IpListId: task.listId,
|
||||||
IpFrom: task.ip,
|
IpFrom: task.ip,
|
||||||
IpTo: "",
|
IpTo: "",
|
||||||
ExpiredAt: task.expiredAt,
|
ExpiredAt: task.expiresAt,
|
||||||
Reason: reason,
|
Reason: reason,
|
||||||
Type: ipType,
|
Type: ipType,
|
||||||
EventLevel: task.level,
|
EventLevel: task.level,
|
||||||
@@ -105,11 +105,13 @@ func (this *RecordIPAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, re
|
|||||||
return true, false
|
return true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := this.Timeout
|
var timeout = this.Timeout
|
||||||
|
var isForever = false
|
||||||
if timeout <= 0 {
|
if timeout <= 0 {
|
||||||
|
isForever = true
|
||||||
timeout = 86400 // 1天
|
timeout = 86400 // 1天
|
||||||
}
|
}
|
||||||
expiredAt := time.Now().Unix() + int64(timeout)
|
var expiresAt = time.Now().Unix() + int64(timeout)
|
||||||
|
|
||||||
if this.Type == "black" {
|
if this.Type == "black" {
|
||||||
writer.WriteHeader(http.StatusForbidden)
|
writer.WriteHeader(http.StatusForbidden)
|
||||||
@@ -117,10 +119,10 @@ func (this *RecordIPAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, re
|
|||||||
request.WAFClose()
|
request.WAFClose()
|
||||||
|
|
||||||
// 先加入本地的黑名单
|
// 先加入本地的黑名单
|
||||||
SharedIPBlackList.Add(IPTypeAll, this.Scope, request.WAFServerId(), request.WAFRemoteIP(), expiredAt)
|
SharedIPBlackList.Add(IPTypeAll, this.Scope, request.WAFServerId(), request.WAFRemoteIP(), expiresAt)
|
||||||
} else {
|
} else {
|
||||||
// 加入本地白名单
|
// 加入本地白名单
|
||||||
SharedIPWhiteList.Add("set:"+types.String(set.Id), this.Scope, request.WAFServerId(), request.WAFRemoteIP(), expiredAt)
|
SharedIPWhiteList.Add("set:"+types.String(set.Id), this.Scope, request.WAFServerId(), request.WAFRemoteIP(), expiresAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上报
|
// 上报
|
||||||
@@ -130,11 +132,16 @@ func (this *RecordIPAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, re
|
|||||||
serverId = request.WAFServerId()
|
serverId = request.WAFServerId()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var realExpiresAt = expiresAt
|
||||||
|
if isForever {
|
||||||
|
realExpiresAt = 0
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case recordIPTaskChan <- &recordIPTask{
|
case recordIPTaskChan <- &recordIPTask{
|
||||||
ip: request.WAFRemoteIP(),
|
ip: request.WAFRemoteIP(),
|
||||||
listId: this.IPListId,
|
listId: this.IPListId,
|
||||||
expiredAt: expiredAt,
|
expiresAt: realExpiresAt,
|
||||||
level: this.Level,
|
level: this.Level,
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
sourceServerId: request.WAFServerId(),
|
sourceServerId: request.WAFServerId(),
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func (this *IPList) RecordIP(ipType string,
|
|||||||
case recordIPTaskChan <- &recordIPTask{
|
case recordIPTaskChan <- &recordIPTask{
|
||||||
ip: ip,
|
ip: ip,
|
||||||
listId: firewallconfigs.GlobalListId,
|
listId: firewallconfigs.GlobalListId,
|
||||||
expiredAt: expiresAt,
|
expiresAt: expiresAt,
|
||||||
level: firewallconfigs.DefaultEventLevel,
|
level: firewallconfigs.DefaultEventLevel,
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
sourceServerId: serverId,
|
sourceServerId: serverId,
|
||||||
|
|||||||
Reference in New Issue
Block a user