]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add maps based on Top Level Domains
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 12 Jun 2018 14:42:58 +0000 (15:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 12 Jun 2018 14:42:58 +0000 (15:42 +0100)
src/plugins/lua/multimap.lua
test/functional/cases/102_multimap.robot
test/functional/configs/maps/top.list [new file with mode: 0644]
test/functional/configs/multimap.conf

index 7e83988c6e46f88599e9174fa90a6c31c45f3fe0..8a2b21ddfc859873ccfc9166db3b9422a2774c79 100644 (file)
@@ -93,6 +93,9 @@ local function apply_hostname_filter(task, filter, hostname, r)
   if filter == 'tld' then
     local tld = util.get_tld(hostname)
     return tld
+  elseif filter == 'top' then
+    local tld = util.get_tld(hostname)
+    return tld:match('[^.]*$') or tld
   else
     if not r['re_filter'] then
       local pat = string.match(filter, 'tld:regexp:(.+)')
@@ -123,6 +126,9 @@ local function apply_url_filter(task, filter, url, r)
 
   if filter == 'tld' then
     return url:get_tld()
+  elseif filter == 'top' then
+    local tld = url:get_tld()
+    return tld:match('[^.]*$') or tld
   elseif filter == 'full' then
     return url:get_text()
   elseif filter == 'is_phished' then
index c46fff39b17ce18862efe294e054f69804e67ee6..7aac43e4eb77898dd714765f50c0e7010e65de92 100644 (file)
@@ -133,6 +133,14 @@ MAP - HOSTNAME MISS
   ${result} =  Scan Message With Rspamc  ${MESSAGE}  --ip  127.0.0.1  --hostname  rspamd.com
   Check Rspamc  ${result}  HOSTNAME_MAP  inverse=1
 
+MAP - TOP
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --ip  127.0.0.1  --hostname  example.com.au
+  Check Rspamc  ${result}  HOSTNAME_TOP_MAP
+
+MAP - TOP MISS
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --ip  127.0.0.1  --hostname  example.com.bg
+  Check Rspamc  ${result}  HOSTNAME_TOP_MAP  inverse=1
+
 MAP - CDB - HOSTNAME
   ${result} =  Scan Message With Rspamc  ${MESSAGE}  --ip  127.0.0.1  --hostname  example.com
   Check Rspamc  ${result}  CDB_HOSTNAME
diff --git a/test/functional/configs/maps/top.list b/test/functional/configs/maps/top.list
new file mode 100644 (file)
index 0000000..d8a152e
--- /dev/null
@@ -0,0 +1,2 @@
+au
+#bg
\ No newline at end of file
index 98701794f74ff099f42a235747762291d8f7c06f..61bd310a8a3cdaf437d7b2ee2fe0f98aee1598dc 100644 (file)
@@ -58,6 +58,11 @@ multimap {
     type = "hostname";
     map = "${TESTDIR}/configs/maps/domains.list";
   }
+  HOSTNAME_TOP_MAP {
+    type = "hostname";
+    filter = "top";
+    map = "${TESTDIR}/configs/maps/top.list";
+  }
   CDB_HOSTNAME {
     type = "hostname";
     map = "cdb://${TESTDIR}/configs/maps/domains.cdb";