This commit is contained in:
midoks
2022-10-15 00:34:14 +08:00
parent c74a2c9655
commit 6b42d35cd4
2 changed files with 5 additions and 16 deletions
+2 -12
View File
@@ -505,9 +505,9 @@ function _M.write_log(self, name, rule)
local count, _ = ngx.shared.waf_drop_ip:get(ip) local count, _ = ngx.shared.waf_drop_ip:get(ip)
if count then if count then
ngx.shared.waf_drop_ip:incr(ip,1) ngx.shared.waf_drop_ip:incr(ip, 1)
else else
ngx.shared.waf_drop_ip:set(ip,1,retry_cycle) ngx.shared.waf_drop_ip:set(ip, 1, retry_cycle)
end end
if config['log'] ~= true or self:is_site_config('log') ~= true then return false end if config['log'] ~= true or self:is_site_config('log') ~= true then return false end
@@ -596,16 +596,6 @@ function _M.split_bylog_debug(self, str,reps)
return resultStrList return resultStrList
end end
function _M.split_bylog(self, str,reps)
local resultStrList = {}
string.gsub(str,'[^'..reps..']+', function(w)
table.insert(resultStrList,w)
end)
return resultStrList
end
function _M.get_real_ip(self, server_name) function _M.get_real_ip(self, server_name)
local client_ip = "unknown" local client_ip = "unknown"
local site_config = self.site_config local site_config = self.site_config
+3 -4
View File
@@ -231,7 +231,6 @@ local function waf_cc()
local waf_limit = config['cc']['limit'] local waf_limit = config['cc']['limit']
local cycle = config['cc']['cycle'] local cycle = config['cc']['cycle']
if count then if count then
if count > waf_limit then if count > waf_limit then
local safe_count, _ = ngx.shared.waf_drop_sum:get(ip) local safe_count, _ = ngx.shared.waf_drop_sum:get(ip)
@@ -245,17 +244,17 @@ local function waf_cc()
if lock_time > 86400 then lock_time = 86400 end if lock_time > 86400 then lock_time = 86400 end
-- lock_time = 10 -- lock_time = 10
ngx.shared.waf_drop_ip:set(ip,1,lock_time) ngx.shared.waf_drop_ip:set(ip, 1, lock_time)
C:write_log('cc',cycle..'秒内累计超过'..waf_limit..'次请求,封锁' .. lock_time .. '秒') C:write_log('cc',cycle..'秒内累计超过'..waf_limit..'次请求,封锁' .. lock_time .. '秒')
C:write_drop_ip('cc',lock_time) C:write_drop_ip('cc',lock_time)
ngx.exit(config['cc']['status']) ngx.exit(config['cc']['status'])
return true return true
else else
ngx.shared.waf_limit:incr(token,1) ngx.shared.waf_limit:incr(token, 1)
end end
else else
ngx.shared.waf_drop_sum:set(ip,1,86400) ngx.shared.waf_drop_sum:set(ip, 1, 86400)
ngx.shared.waf_limit:set(token, 1, cycle) ngx.shared.waf_limit:set(token, 1, cycle)
end end
return false return false