From e625b8b416a4975f7faaa2ec9f6b07eae1bf604b Mon Sep 17 00:00:00 2001 From: midoks Date: Sat, 27 Apr 2019 09:30:52 +0800 Subject: [PATCH] up --- plugins/op_waf/waf/lua/common.lua | 27 +++++++++++++++++++++++++-- plugins/op_waf/waf/lua/init.lua | 17 ++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/plugins/op_waf/waf/lua/common.lua b/plugins/op_waf/waf/lua/common.lua index 1698f943a..c8488ce55 100644 --- a/plugins/op_waf/waf/lua/common.lua +++ b/plugins/op_waf/waf/lua/common.lua @@ -7,16 +7,24 @@ local json = require "cjson" function _M.new(cpath, rpath) - ngx.log(ngx.ERR,"read:"..cpath..",rpath:"..rpath) + -- ngx.log(ngx.ERR,"read:"..cpath..",rpath:"..rpath) local self = { cpath = cpath, rpath = rpath, + config = '', + site_config = '' } local p = setmetatable(self, mt) return p end +function _M.setConfData( self, config, site_config ) + self.config = config + self.site_config = site_config +end + + function _M.return_message(self, status, msg) ngx.header.content_type = "application/json;" @@ -34,7 +42,7 @@ function _M.return_html(self,status,html) end function _M.read_file_body(self, filename) - ngx.log(ngx.ERR,"read_file_body:"..filename) + -- ngx.log(ngx.ERR,"read_file_body:"..filename) fp = io.open(filename, 'r') if fp == nil then return nil @@ -47,6 +55,17 @@ function _M.read_file_body(self, filename) return fbody end +function _M.continue_key(self,key) + key = tostring(key) + if string.len(key) > 64 then return false end; + local keys = {"content","contents","body","msg","file","files","img","newcontent"} + for _,k in ipairs(keys) + do + if k == key then return false end; + end + return true; +end + function _M.array_len(self, arr) if not arr then return 0 end @@ -98,6 +117,10 @@ function _M.read_file(self, name) return json.decode(fbody) end +function _M.read_file_table( self, name ) + return self:select_rule(self:read_file('args')) +end + function _M.t(self) ngx.say(',,,') end diff --git a/plugins/op_waf/waf/lua/init.lua b/plugins/op_waf/waf/lua/init.lua index f9ccde682..3a7d53e68 100644 --- a/plugins/op_waf/waf/lua/init.lua +++ b/plugins/op_waf/waf/lua/init.lua @@ -27,6 +27,8 @@ ngx.header.content_type = "text/plain" local config = C:read_file_body_decode(cpath .. 'config.json') local site_config = C:read_file_body_decode(cpath .. 'site.json') +C.setConfData(config, site_config) + @@ -76,7 +78,7 @@ function get_server_name() return c_name end -local args_rules = C:select_rule(C:read_file('args')) +local args_rules = C:read_file_table('args') local retry = config['retry'] local retry_time = config['retry_time'] @@ -85,18 +87,7 @@ local ip local server_name -function continue_key(key) - key = tostring(key) - if string.len(key) > 64 then return false end; - local keys = {"content","contents","body","msg","file","files","img","newcontent"} - for _,k in ipairs(keys) - do - ngx.say(k..'---'..key) - if k == key then return false end; - end - ngx.say('ok:'..key) - return true; -end + function is_ngx_match(rules,sbody,rule_name)