Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/op_waf/waf/lua/init.lua

62 lines
1.7 KiB

6 years ago
local cpath = "{$WAF_PATH}/"
6 years ago
local rpath = "{$WAF_PATH}/rule/"
6 years ago
local logdir = "{$ROOT_PATH}/wwwlogs/waf/"
6 years ago
local json = require "cjson"
6 years ago
local ngx_match = ngx.re.find
6 years ago
6 years ago
local _C = require "common"
6 years ago
local C = _C:new(cpath, rpath, logdir)
6 years ago
6 years ago
local config = C:read_file_body_decode(cpath .. 'config.json')
local site_config = C:read_file_body_decode(cpath .. 'site.json')
6 years ago
C:setConfData(config, site_config)
6 years ago
6 years ago
6 years ago
local get_html = C:read_file_body(config["reqfile_path"] .. '/' .. config["get"]["reqfile"])
6 years ago
local args_rules = C:read_file_table('args')
6 years ago
6 years ago
local ip_white_rules = C:read_file('ip_white')
function initParams()
local data = {}
data['ip'] = C:get_client_ip()
data['request_header'] = ngx.req.get_headers()
data['uri'] = ngx.unescape_uri(ngx.var.uri)
data['server_name'] = string.gsub(C:get_server_name(),'_','.')
data['uri_request_args'] = ngx.req.get_uri_args()
return data
end
6 years ago
6 years ago
local params = initParams()
C:setParams(params)
6 years ago
6 years ago
-- function min_route()
-- if ngx.var.remote_addr ~= '127.0.0.1' then return false end
-- if uri == '/get_waf_drop_ip' then
-- return_message(200,get_waf_drop_ip())
-- elseif uri == '/remove_waf_drop_ip' then
-- return_message(200,remove_waf_drop_ip())
-- elseif uri == '/clean_waf_drop_ip' then
-- return_message(200,clean_waf_drop_ip())
-- end
-- end
6 years ago
6 years ago
function waf_args()
if not config['get']['open'] or not C:is_site_config('get') then return false end
6 years ago
if C:is_ngx_match(args_rules, params['uri_request_args'],'args') then
C:write_log('args','regular')
C:return_html(config['get']['status'], get_html)
6 years ago
return true
end
return false
end
6 years ago
6 years ago
ngx.header.content_type = "text/html"
6 years ago
function waf()
6 years ago
waf_args()
6 years ago
end
6 years ago
waf()