-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
68 lines (63 loc) · 2.31 KB
/
test.lua
File metadata and controls
68 lines (63 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local re
local re_pattern_adblock='^(\\|){2}(.*)\\^$' -- Matches Adblock Format
local re_chars="(.*)[$^|](.*)" -- Matches PCRE Format
local re_wild="^[*.]" -- Matches Wildcard Format
local re_hosts="^(0.0.0.0|::|2001:1::1)\\s+.*" -- Matches HOSTS Format
local s_test_adblock="||example-dom.com^"
local s_test_normal="example-dom.com"
local s_test_regex="(\\.|^)example-dom\\.com$"
local s_test_hosts_4="0.0.0.0 example.com"
local s_test_hosts_6=":: example.com"
local s_test_hosts_6_sink="2001:1::1 example.com"
local s_test_wildcard="*.example-dom.com"
local s_tests={
s_test_adblock,
s_test_normal,
s_test_regex,
s_test_hosts_4,
s_test_hosts_6,
s_test_hosts_6_sink,
s_test_wildcard,
}
local test_val="mail.example-dom.com"
local function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)") or "."
end
g = {}
f = require('functions')
g.pdns_scripts_path = script_path()
g.options = require('defaults')
g.options_overrides = require('overrides-handler')
package.path = package.path .. ";"..g.pdns_scripts_path.."/?.lua"
if f.isModuleAvailable("rex_pcre") then
re = require"rex_pcre"
elseif f.isModuleAvailable("rex_pcre2") then
re = require"rex_pcre2"
else
error("pdns-recursor-scripts malware-filter.lua requires rex_pcre or rex_pcre2 to be installed")
end
for key, line in pairs(s_tests) do
if re.match(line, re_pattern_adblock) then -- ADBLOCK FORMAT
local stripped = string.gsub(line, "||", "")
stripped = string.gsub(stripped, "%^", "") -- Escape Special character ^ with %
print("ADBLOCK: ".." (Index: "..key..") | \""..stripped.."\"")
elseif re.match(line, re_chars) then -- PCRE FORMAT
print("PCRE: ".." (Index: "..key..") | \""..line.."\"")
elseif re.match(line, re_wild) then -- WILDCARD FORMAT
local wilded = string.gsub(line, '*%.', "") -- Escape Special character . with %
wilded = ".*\\.*?"..string.gsub(wilded, '%.', "\\.")
print("WILD: ".." (Index: "..key..") | \""..wilded.."\"")
test_re = wilded
elseif re.match(line, re_hosts) then
local domain = f.extract_hosts_domain(line)
print("HOSTS: ".." (Index: "..key..") | \""..domain.."\"")
else -- STANDARD HOSTS FORMAT
print("STANDARD: ".." (Index: "..key..") | \""..line.."\"")
end
end
if re.match(test_val, test_re) then
print("Test Wildcard Regex Matched")
else
print("Test Wildcard Regex was not Matched")
end