Skip to content

Commit

Permalink
Optimization: disable rule if variables are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Aug 21, 2024
1 parent b00efea commit 275e082
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions rootfs/etc/knot-resolver/knot-aliases-alt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Dummy file. Filled by antizapret script.
blocked_hosts = {}
regex_blocked = '^$'
regex_allowed = '^$'
regex_blocked = ''
regex_allowed = ''
46 changes: 22 additions & 24 deletions rootfs/etc/knot-resolver/kresd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,30 @@ local adguard = os.getenv('ADGUARD')
-- if not dns then dns = '127.0.0.11' end
-- if not dns_ru then dns = '77.88.8.8' end

policy.add(
function (_, query)
if (regex_allowed == '' or regex_allowed == nil) and (regex_blocked == '' or regex_blocked == nil) then
return nil
end
if (regex_allowed ~= '' or regex_blocked ~= '') then
policy.add(
function (_, query)
local command = string.format(
'/etc/knot-resolver/regex.sh "%s" "%s" "%s"',
kres.dname2str(query.sname),
regex_allowed,
regex_blocked
)
local handle = io.popen(command)
local result = handle:read("*line")
handle:close()

local command = string.format(
'/etc/knot-resolver/regex.sh "%s" "%s" "%s"',
kres.dname2str(query.sname),
regex_allowed,
regex_blocked
)
local handle = io.popen(command)
local result = handle:read("*line")
handle:close()

if result == 'blocked' then
return policy.STUB({'127.0.0.4'})
elseif result == 'allowed' then
return policy.FORWARD({dns})
end
if result == 'blocked' then
return policy.STUB({'127.0.0.4'})
elseif result == 'allowed' then
return policy.FORWARD({dns})
end

-- filter did not match, continue with next filter
return nil
end
)
-- filter did not match, continue with next filter
return nil
end
)
end

-- Forward blocked domains to dnsmap
policy.add(
Expand Down

0 comments on commit 275e082

Please sign in to comment.