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