body_filter_by_lua '

function file_exists(path)
	local file = io.open(path, "rb")
	if file then file:close() end
	return file ~= nil
end

function string.indexOf(s, pattern, init)
    init = init or 0
    local index = string.find(s, pattern, init, true)
    return index or -1;
end

function string.insert(str,index,insertStr)
    local first = string.sub(str,1,index-1)
    local last = string.sub(str,index,-1)
    local createStr = string.format("%s%s%s",first,insertStr,last)
    return createStr
end

function writeMsg(host,url,msg)

	if (file_exists("/var/tmp/count"))
	then
		file=io.open("/var/tmp/msg.txt","a");
		io.output(file);
		io.write(string.format("%s----%s	---%s\\n",host,url,msg));
		io.close()
	end
end

local ngx = require "ngx";


local url = ngx.var.uri;
local host = ngx.var.host;
local agent = ngx.var.http_user_agent
local request_url = ngx.var.request_uri;
local request_method = ngx.var.request_method;
local accpet = ngx.var.http_accept
local referer = ngx.var.http_referer
        

request_url = string.format(" url: %s %s%s",request_method,host,request_url);

if url==nil then
	return
end

if referer==nil then
	return
end

writeMsg(host,referer,request_url);
';