6.38. Lua脚本¶
Syntax:
lua:[!]<scriptfilename>;
脚本文件名将附加到默认规则位置。
脚本有两部分,一个init函数和一个match函数。首先,初始化。
6.38.1. 初始化函数¶
function init (args)
local needs = {}
needs["http.request_line"] = tostring(true)
return needs
end
init函数注册需要检查的缓冲区。目前有以下几种:
包——整个包,包括头
有效负载——包有效负载(非流)
buffer——当前的粘性缓冲区
http.uri
http.uri.raw
http.request_line
http.request_headers
http.request_headers.raw
http.request_cookie
http.request_user_agent
http.request_body
http.response_headers
http.response_headers.raw
http.response_body
http.response_cookie
所有HTTP缓冲区都有一个限制:一个脚本一次只能检查一个缓冲区。
6.38.2. 匹配函数¶
function match(args)
a = tostring(args["http.request_line"])
if #a > 0 then
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
return 1
end
end
return 0
end
脚本可以返回1或0。如果检查条件是否匹配,则返回1;如果不匹配,则返回0。
整个脚本:
function init (args)
local needs = {}
needs["http.request_line"] = tostring(true)
return needs
end
function match(args)
a = tostring(args["http.request_line"])
if #a > 0 then
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
return 1
end
end
return 0
end
return 0