commit 48d68b1: [Rework] Migrate from ip_score to reputation

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jul 17 16:14:08 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-17 17:13:06 +0100
URL: https://github.com/rspamd/rspamd/commit/48d68b15e08a6c3b597f4de6400815e294c61ace (HEAD -> master)

[Rework] Migrate from ip_score to reputation

---
 conf/composites.conf         |  2 +-
 lualib/lua_cfg_transform.lua | 38 ++++++++++++++++++++++++++++++++++++++
 src/plugins/lua/ip_score.lua |  4 ++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/conf/composites.conf b/conf/composites.conf
index 77332b27f..37b1c3da9 100644
--- a/conf/composites.conf
+++ b/conf/composites.conf
@@ -138,7 +138,7 @@ composites {
 
   IP_SCORE_FREEMAIL {
     description = "Negate IP_SCORE when message comes from FreeMail";
-    expression = "FREEMAIL_FROM & IP_SCORE";
+    expression = "FREEMAIL_FROM & SENDER_REP_SPAM";
     score = 0.0;
     policy = "remove_weight";
   }
diff --git a/lualib/lua_cfg_transform.lua b/lualib/lua_cfg_transform.lua
index 83b979ac5..ac328f86f 100644
--- a/lualib/lua_cfg_transform.lua
+++ b/lualib/lua_cfg_transform.lua
@@ -17,6 +17,7 @@ limitations under the License.
 local logger = require "rspamd_logger"
 local lua_util = require "lua_util"
 local rspamd_util = require "rspamd_util"
+local fun = require "fun"
 
 local function is_implicit(t)
   local mt = getmetatable(t)
@@ -358,5 +359,42 @@ return function(cfg)
     end
   end
 
+  -- Deal with IP_SCORE
+  if cfg.ip_score then
+    logger.warnx(rspamd_config, 'ip_score module is deprecated in honor of reputation module!')
+
+    if not cfg.reputation then
+      cfg.reputation = {
+        rules = {}
+      }
+    end
+
+    if not fun.any(function(_, v) return v.selector and v.selector.ip end,
+        cfg.reputation.rules) then
+      logger.infox(rspamd_config, 'attach ip reputation element to use it')
+
+      cfg.reputation.rules.ip_score = {
+        selector = {
+          ip = {},
+        },
+        backend = {
+          redis = {},
+        }
+      }
+
+      if cfg.symbols['IP_SCORE'] then
+        local t = cfg.symbols['IP_SCORE']
+
+        if not cfg.symbols['SENDER_REP_SPAM'] then
+          cfg.symbols['SENDER_REP_SPAM'] = t
+          cfg.symbols['SENDER_REP_HAM'] = t
+          cfg.symbols['SENDER_REP_HAM'].weight = -(t.weight or 0)
+        end
+      end
+    else
+      logger.infox(rspamd_config, 'ip reputation already exists, do not do any IP_SCORE transforms')
+    end
+  end
+
   return ret, cfg
 end
diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua
new file mode 100644
index 000000000..e43fa3b78
--- /dev/null
+++ b/src/plugins/lua/ip_score.lua
@@ -0,0 +1,4 @@
+-- This module is deprecated and must not be used.
+-- This file serves as a tombstone to prevent old ip_score to be loaded
+
+return
\ No newline at end of file


More information about the Commits mailing list