pull/216/head
midoks 3 years ago
parent 6b42d35cd4
commit abc778fb52
  1. 21
      plugins/op_waf/waf/lua/common.lua
  2. 21
      plugins/op_waf/waf/lua/init.lua

@ -165,19 +165,28 @@ function _M.compare_ip(self,ips)
end end
function _M.to_json(self, msg) function _M.to_json(self, msg)
return json.encode(msg) return json.encode(msg)
end end
function _M.return_state(status,msg)
result = {}
result['status'] = status
result['msg'] = msg
return result
end
function _M.return_message(self, status, msg) function _M.return_message(self, status, msg)
ngx.header.content_type = "application/json;" ngx.header.content_type = "application/json"
ngx.status = status
ngx.say(json.encode(msg)) local data = self:return_state(status,msg)
ngx.exit(status) ngx.say(json.encode(data))
ngx.exit(200)
end end
function _M.return_html(self,status,html) function _M.return_html(self,status, html)
ngx.header.content_type = "text/html" ngx.header.content_type = "text/html"
ngx.status = status ngx.status = status
ngx.say(html) ngx.say(html)
@ -274,7 +283,7 @@ end
function _M.continue_key(self,key) function _M.continue_key(self,key)
key = tostring(key) key = tostring(key)
if string.len(key) > 64 then return false end; if string.len(key) > 64 then return false end;
local keys = {"content","contents","body","msg","file","files","img","newcontent"} local keys = { "content", "contents", "body", "msg", "file", "files", "img", "newcontent" }
for _,k in ipairs(keys) for _,k in ipairs(keys)
do do
if k == key then return false end; if k == key then return false end;

@ -83,21 +83,21 @@ local function save_ip_on(data)
name='stop_ip' name='stop_ip'
local extime = 18000 local extime = 18000
data = json.encode(data) data = json.encode(data)
ngx.shared.btwaf:set(cpath2 .. name,data,extime) ngx.shared.waf_limit:set(cpath2 .. name,data,extime)
if not ngx.shared.btwaf:get(cpath2 .. name .. '_lock') then if not ngx.shared.waf_limit:get(cpath2 .. name .. '_lock') then
ngx.shared.btwaf:set(cpath2 .. name .. '_lock',1,0.5) ngx.shared.waf_limit:set(cpath2 .. name .. '_lock',1,0.5)
C:write_file(cpath2 .. name .. '.json',data) C:write_file(cpath2 .. name .. '.json',data)
end end
end end
local function remove_waf_drop_ip() local function remove_waf_drop_ip()
if not uri_request_args['ip'] or not C:is_ipaddr(uri_request_args['ip']) then return get_return_state(true,'格式错误') end if not uri_request_args['ip'] or not C:is_ipaddr(uri_request_args['ip']) then return get_return_state(true,'格式错误') end
if ngx.shared.btwaf:get(cpath2 .. 'stop_ip') then if ngx.shared.waf_limit:get(cpath2 .. 'stop_ip') then
ret=ngx.shared.btwaf:get(cpath2 .. 'stop_ip') ret=ngx.shared.waf_limit:get(cpath2 .. 'stop_ip')
ip_data=json.decode(ret) ip_data=json.decode(ret)
result = is_chekc_table(ip_data,uri_request_args['ip']) result = is_chekc_table(ip_data,uri_request_args['ip'])
os.execute("sleep " .. 0.6) os.execute("sleep " .. 0.6)
ret2=ngx.shared.btwaf:get(cpath2 .. 'stop_ip') ret2=ngx.shared.waf_limit:get(cpath2 .. 'stop_ip')
ip_data2 = json.decode(ret2) ip_data2 = json.decode(ret2)
if result == 3 then if result == 3 then
for k,v in pairs(ip_data2) for k,v in pairs(ip_data2)
@ -114,8 +114,8 @@ local function remove_waf_drop_ip()
end end
local function clean_waf_drop_ip() local function clean_waf_drop_ip()
if ngx.shared.btwaf:get(cpath2 .. 'stop_ip') then if ngx.shared.waf_limit:get(cpath2 .. 'stop_ip') then
ret2 = ngx.shared.btwaf:get(cpath2 .. 'stop_ip') ret2 = ngx.shared.waf_limit:get(cpath2 .. 'stop_ip')
ip_data2 = json.decode(ret2) ip_data2 = json.decode(ret2)
for k,v in pairs(ip_data2) for k,v in pairs(ip_data2)
do do
@ -127,7 +127,7 @@ local function clean_waf_drop_ip()
local data = get_waf_drop_ip() local data = get_waf_drop_ip()
for _,value in ipairs(data) for _,value in ipairs(data)
do do
ngx.shared.waf_waf_drop_ip:delete(value) ngx.shared.waf_drop_ip:delete(value)
end end
return get_return_state(true,'已解封所有封锁IP') return get_return_state(true,'已解封所有封锁IP')
end end
@ -165,7 +165,6 @@ local function waf_ip_white()
end end
local function waf_ip_black() local function waf_ip_black()
-- ipv4 ip black -- ipv4 ip black
for _,rule in ipairs(ip_black_rules) for _,rule in ipairs(ip_black_rules)
do do
@ -230,6 +229,8 @@ local function waf_cc()
local endtime = config['cc']['endtime'] local endtime = config['cc']['endtime']
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

Loading…
Cancel
Save