+  HandyCache форум
|-+  Главная категория» English forum» Show variables
Имя пользователя:
Пароль:
Страниц: [1]   Вниз
  Отправить эту тему    Печать  
Автор Тема: Show variables  (Прочитано 2828 раз)
0 Пользователей и 1 Гость смотрят эту тему.
truefriend-cz
Постоялец
***

Репутация: +3/-1
Offline Offline

Сообщений: 118


« : 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.?
Сообщить модератору   Записан
mai62
Автор HC
*****

Репутация: +226/-4
Offline Offline

Сообщений: 6383


« Ответ #1 : 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
Сообщить модератору   Записан
truefriend-cz
Постоялец
***

Репутация: +3/-1
Offline Offline

Сообщений: 118


« Ответ #2 : 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).
« Последнее редактирование: 19 июня 2017, 13:13:18 от truefriend-cz » Сообщить модератору   Записан
truefriend-cz
Постоялец
***

Репутация: +3/-1
Offline Offline

Сообщений: 118


« Ответ #3 : 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
Сообщить модератору   Записан
truefriend-cz
Постоялец
***

Репутация: +3/-1
Offline Offline

Сообщений: 118


« Ответ #4 : 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.
Сообщить модератору   Записан
truefriend-cz
Постоялец
***

Репутация: +3/-1
Offline Offline

Сообщений: 118


« Ответ #5 : 13 июля 2017, 21:05:26 »

Problem solved after remove "?" char.
Сообщить модератору   Записан
Страниц: [1]   Вверх
  Отправить эту тему    Печать  

 
Перейти в: