Название: Show variables
Отправлено: truefriend-cz от 16 июня 2017, 16:31:02
Hi users. How i can show variables on page to clients from LUA script? I have script: --[[ <HCExtension> @name Ad-Blocker @rule .* @event RequestHeaderReceived/validate </HCExtension> ]]
--Get URL string function GetURL(s) _,_,x = string.find(s, '[gG]ET *([^;\r\n]+) HTTP/') if x==nil then return -1 else return x end end
--Validate URL function validate() local reqURL = GetURL(hc.request_header) if not WhiteList(reqURL) then if Blacklist(reqURL) then hc.white_mask = "SDORU" if re.find(hc.request_header, [[Accept: text/html]]) then hc.call_me_for ('BeforeAnswerBodySend', 'ResponseBody') hc.monitor_string = hc.monitor_string..', Ad-Hidden' hc.action = 'stop' else hc.monitor_string = hc.monitor_string..', Ad-Blocked' hc.action = 'stop' end end end end
--Blacklist function Blacklist(url) ad_servers = {'server1.tld', 'badword1', 'server2.tld', 'server3.tld', 'badword2'}
for i, host in ipairs(ad_servers) do if re.match(url, host) then return true end end return false end
--Exlusion list function WhiteList(url) whitelist = {'googleusercontent.com'} for i, host in ipairs(whitelist) do if re.match(url, host) then return true end end return false end
function ResponseBody() hc.answer_body = '<html><body>Blocked.</body></html>'print(url) end This output to clients: Blocked.How i can show to clients bad word, or server as Blocked server2.tld.?
Название: Re: Show variables
Отправлено: mai62 от 17 июня 2017, 13:23:04
--Validate URL function validate() local reqURL = GetURL(hc.request_header) if not WhiteList(reqURL) then if Blacklist(reqURL) then hc.answer_header= 'HTTP/1.1 200 OK\r\n'.. 'Server: HandyCache\r\n'.. 'Content-Type: text/html\r\n'.. 'Pragma: no-cache\r\n'.. 'Cache-control: no-cache, must-revalidate, no-store\r\n'.. 'Connection: close\r\n\r\n' hc.answer_body = '<p>Dear user '..hc.user_name..'!<br> Site '..reqURL..' is blocked</p>' end end end
Название: Re: Show variables
Отправлено: truefriend-cz от 19 июня 2017, 13:05:12
Yes, but if going to search google then show results as: Dear user Test! Site /search?q=g+http%3A%2F%2Fserver2.tld%2F&oq=g+http%3A%2F%2Fserver2.tld%2F&aqs=chrome..69i57j69i64.1303j0j1&sourceid=chrome&ie=UTF-8 is blocked. I want show variable define this restriction. Not get bad word from URL contain, but from blacklist rule database as: Example idea... --Validate URL function validate() local reqURL = GetURL(hc.request_header) if not WhiteList(reqURL) then if Blacklist(reqURL) then hc.answer_header= 'HTTP/1.1 200 OK\r\n'.. 'Server: HandyCache\r\n'.. 'Content-Type: text/html\r\n'.. 'Pragma: no-cache\r\n'.. 'Cache-control: no-cache, must-revalidate, no-store\r\n'.. 'Connection: close\r\n\r\n' hc.answer_body = '<p>Dear user '..hc.user_name..'!<br> Rule '..Blacklist..' is blocked</p>' end end end where output form search URL is: Dear user Test! Rule server2.tld is blocked. I have problem get for show one blacklist rule (as variable).
Название: Re: Show variables
Отправлено: truefriend-cz от 29 июня 2017, 12:46:36
This works... But one bug. If i color text no colored. It i use version colored show colored text in monitor. How i can use "no colored" version for colored text solution? Version - no colored--[[ <HCExtension> @name URL - Bad Word Blocker @rule .* @event RequestHeaderReceived/validate </HCExtension> ]]
function GetURL(s) _,_,x = string.find(s, '[gG]ET *([^;\r\n]+) HTTP/') if x==nil then return -1 else return x end end
function validate() local reqURL = GetURL(hc.request_header) if words(reqURL) then hc.answer_header= 'HTTP/1.1 200 OK\r\n'.. 'Server: HandyCache\r\n'.. 'Content-Type: text/html\r\n'.. 'Pragma: no-cache\r\n'.. 'Cache-control: no-cache, must-revalidate, no-store\r\n'.. 'Connection: close\r\n\r\n' hc.answer_body = '<html><body>This page is blocked by rule: <b>'..word..'</b></body></html>' hc.monitor_string = ', URL Blocked by "'..word..'" rule' hc.monitor_text_color = 255 hc.action = 'dont_save' end end
function words(url) badwords = {'google', 'badword1', 'server2.tld', 'server3.tld', 'badword2'}
for i, host in ipairs(badwords) do if url:match(host) then word=host hc.put_msg(5, 'Apply rule for Bad Words:\r\n \r\n'..host..'\r\n \r\n User: '..hc.user_name) return true end end return false end
Version - colored--[[ <HCExtension> @name URL - Bad Word Blocker @rule .* @event RequestHeaderReceived/validate </HCExtension> ]]
function GetURL(s) _,_,x = string.find(s, '[gG]ET *([^;\r\n]+) HTTP/') if x==nil then return -1 else return x end end
function validate() local reqURL = GetURL(hc.request_header) if words(reqURL) then hc.answer_body = '<html><body>This page is blocked by rule: <b>'..word..'</b></body></html>' hc.monitor_string = ', URL Blocked by "'..word..'" rule' hc.monitor_text_color = 255 hc.action = 'dont_save' end end
function words(url) badwords = {'google', 'badword1', 'server2.tld', 'server3.tld', 'badword2'}
for i, host in ipairs(badwords) do if url:match(host) then word=host hc.put_msg(5, 'Apply rule for Bad Words:\r\n \r\n'..host..'\r\n \r\n User: '..hc.user_name) return true end end return false end
Название: Re: Show variables
Отправлено: truefriend-cz от 07 июля 2017, 14:29:17
Why not use variable: ... images = '[[\.(bmp|png|gif|i[mp]g|jpe?g|swf|flv|mp4|mp3|rar|zip)(\?|$)]]' if re.match (hc.url, images) then ... HandyCache ended with error.
Название: Re: Show variables
Отправлено: truefriend-cz от 13 июля 2017, 21:05:26
Problem solved after remove "?" char.
|