mdserver-web/plugins/op_waf/waf/lua/init.lua

53 lines
1.2 KiB
Lua
Raw Normal View History

2019-04-26 03:58:58 -04:00
local cpath = "{$WAF_PATH}/"
local logdir = "{$ROOT_PATH}/wwwlogs/waf/"
local json = require "cjson"
2019-04-26 03:12:57 -04:00
2019-04-26 03:58:58 -04:00
function return_message(status,msg)
ngx.header.content_type = "application/json;"
ngx.status = status
ngx.say(json.encode(msg))
ngx.exit(status)
2019-04-22 09:21:49 -04:00
end
2019-04-26 03:58:58 -04:00
function return_html(status,html)
ngx.header.content_type = "text/html"
ngx.status = status
ngx.say(html)
ngx.exit(status)
2019-04-22 09:21:49 -04:00
end
2019-04-26 03:58:58 -04:00
function read_file_body(filename)
fp = io.open(filename,'r')
if fp == nil then
return nil
2019-04-22 09:21:49 -04:00
end
2019-04-26 03:58:58 -04:00
fbody = fp:read("*a")
fp:close()
if fbody == '' then
2019-04-22 09:21:49 -04:00
return nil
end
2019-04-26 03:58:58 -04:00
return fbody
end
2019-04-22 09:21:49 -04:00
2019-04-26 03:58:58 -04:00
-- local config = read_file_body(cpath .. 'config.json')
local config = json.decode(read_file_body(cpath .. 'config.json'))
-- local site_config = json.decode(read_file_body(cpath .. 'site.json'))
2019-04-22 09:21:49 -04:00
2019-04-26 03:58:58 -04:00
-- function args()
-- if not config['get']['open'] or not is_site_config('get') then return false end
-- if is_ngx_match(args_rules,uri_request_args,'args') then
-- write_log('args','regular')
-- return_html(config['get']['status'],get_html)
-- return true
-- end
-- return false
-- end
2019-04-22 09:21:49 -04:00
2019-04-26 03:58:58 -04:00
function waf()
-- return_html(200,cpath .. 'config.json')
return_message(200, config)
2019-04-22 09:21:49 -04:00
end