From ad2f7cfc300e44eadaa9fdfb7e102e61c44a9748 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Tue, 1 Nov 2016 11:01:52 +0300 Subject: [PATCH] [Minor] phishing: rework map checks - organize map checks into a function - use as symbol option actually matched domain name part (eSLD or hostname) --- src/plugins/lua/phishing.lua | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/plugins/lua/phishing.lua b/src/plugins/lua/phishing.lua index adddce255..4314d7930 100644 --- a/src/plugins/lua/phishing.lua +++ b/src/plugins/lua/phishing.lua @@ -119,7 +119,6 @@ local function phishing_cb(task) end if url:is_phished() and not url:is_redirected() then - local found = false local purl = url:get_phished() local tld = url:get_tld() local ptld = purl:get_tld() @@ -138,29 +137,28 @@ local function phishing_cb(task) end rspamd_logger.debugx(task, "distance: %1 -> %2: %3", tld, ptld, dist) - if #redirector_domains > 0 then - for _,rule in ipairs(redirector_domains) do - if rule['map']:get_key(tld) or rule['map']:get_key(url:get_host()) then - task:insert_result(rule['symbol'], weight, ptld .. '->' .. tld) - found = true + local function found_in_map(map, url, weight) + if #map > 0 then + for _,rule in ipairs(map) do + for _,dn in ipairs({url:get_tld(), url:get_host()}) do + if rule['map']:get_key(dn) then + task:insert_result(rule['symbol'], weight, ptld .. '->' .. dn) + return true + end + end end end end - if not found and #strict_domains > 0 then - for _,rule in ipairs(strict_domains) do - if rule['map']:get_key(ptld) or rule['map']:get_key(purl:get_host()) then - task:insert_result(rule['symbol'], 1.0, ptld .. '->' .. tld) - found = true - end - end - end - if not found then - if domains then - if domains:get_key(ptld) then + + if not found_in_map(redirector_domains, url, weight) then + if not found_in_map(strict_domains, purl, 1.0) then + if domains then + if domains:get_key(ptld) then + task:insert_result(symbol, weight, ptld .. '->' .. tld) + end + else task:insert_result(symbol, weight, ptld .. '->' .. tld) end - else - task:insert_result(symbol, weight, ptld .. '->' .. tld) end end end -- 2.39.5