--[[ <HCExtension>@name Ad-Blocker@rule .*@event RequestHeaderReceived/validate</HCExtension> ]]--Get URL stringfunction GetURL(s) _,_,x = string.find(s, '[gG]ET *([^;\r\n]+) HTTP/') if x==nil then return -1 else return x endend--Validate URLfunction 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 endend--Blacklistfunction 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 falseend--Exlusion listfunction WhiteList(url) whitelist = {'googleusercontent.com'} for i, host in ipairs(whitelist) do if re.match(url, host) then return true end end return falseendfunction ResponseBody() hc.answer_body = '<html><body>Blocked.</body></html>'print(url)end
--Validate URLfunction 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 endend
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.
--Validate URLfunction 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 endend
Dear user Test!Rule server2.tld is blocked.
--[[ <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 endendfunction 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' endendfunction 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 falseend
--[[ <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 endendfunction 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' endendfunction 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 falseend
...images = '[[\.(bmp|png|gif|i[mp]g|jpe?g|swf|flv|mp4|mp3|rar|zip)(\?|$)]]'if re.match (hc.url, images) then...