]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix lua plugins.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 May 2015 11:59:13 +0000 (12:59 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 May 2015 11:59:13 +0000 (12:59 +0100)
src/plugins/lua/emails.lua
src/plugins/lua/forged_recipients.lua
src/plugins/lua/multimap.lua
src/plugins/lua/once_received.lua
src/plugins/lua/phishing.lua
src/plugins/lua/rbl.lua
src/plugins/lua/trie.lua

index 1dc1a0c97aeff174eb56d3d84d741960399e729d..7df5262d02331d9d1169707c680cbc522b4232ce 100644 (file)
@@ -113,7 +113,6 @@ if opts and type(opts) == 'table' then
                                logger.err('incomplete rule')
                        else
                                table.insert(rules, rule)
-                               rspamd_config:register_virtual_symbol(rule['symbol'], 1.0)
                        end
                end
        end
@@ -121,9 +120,8 @@ end
 
 if table.maxn(rules) > 0 then
        -- add fake symbol to check all maps inside a single callback
-       if type(rspamd_config.get_api_version) ~= 'nil' then
-               rspamd_config:register_callback_symbol('EMAILS', 1.0, check_emails)
-       else
-               rspamd_config:register_symbol('EMAILS', 1.0, check_emails)
+       local id = rspamd_config:register_callback_symbol(1.0, check_emails)
+       for _,rule in ipairs(rules) do
+        rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id)
        end
 end
index 6c553aa0445ffdef8ef2959ccc9e1cc9d4fe6405..170c2cd53d4423f94e9e13016cd9bdcf1ca13583 100644 (file)
@@ -84,14 +84,15 @@ end
 local opts =  rspamd_config:get_all_opt('forged_recipients')
 if opts then
        if opts['symbol_rcpt'] or opts['symbol_sender'] then
+    local id = rspamd_config:register_callback_symbol(1.0, 
+      check_forged_headers)
                if opts['symbol_rcpt'] then
                        symbol_rcpt = opts['symbol_rcpt']
-                       rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, check_forged_headers)
+                       rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, id)
                end
                if opts['symbol_sender'] then
                        symbol_sender = opts['symbol_sender']
-                       rspamd_config:register_virtual_symbol(symbol_sender, 1.0)
+                       rspamd_config:register_virtual_symbol(symbol_sender, 1.0, id)
                end
-               rspamd_config:register_callback_symbol('FORGED_RECIPIENTS', 1.0, check_forged_headers)
        end
 end
\ No newline at end of file
index c7908ea9bd12087a9a27fd7892b707d40c515a43..d9c9dd09948e562c1aa2ace0688b2346ec726ba2 100644 (file)
@@ -164,12 +164,6 @@ local function add_multimap_rule(key, newrule)
 end
 
 -- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
-  if rspamd_config:get_api_version() >= 1 then
-    rspamd_config:register_module_option('multimap', 'rule', 'string')
-  end
-end
-
 local opts =  rspamd_config:get_all_opt('multimap')
 if opts and type(opts) == 'table' then
   for k,m in pairs(opts) do
@@ -179,9 +173,6 @@ if opts and type(opts) == 'table' then
         rspamd_logger.err('cannot add rule: "'..k..'"')
       else
         table.insert(rules, rule)
-        if type(rspamd_config.get_api_version) ~= 'nil' then
-          rspamd_config:register_virtual_symbol(rule['symbol'], 1.0)
-        end
       end
     else
       rspamd_logger.err('parameter ' .. k .. ' is invalid, must be an object')
@@ -189,10 +180,10 @@ if opts and type(opts) == 'table' then
   end
   -- add fake symbol to check all maps inside a single callback
   if type(rspamd_config.get_api_version) ~= 'nil' then
-    if rspamd_config.get_api_version() >= 4 then
-      rspamd_config:register_callback_symbol_priority('MULTIMAP', 1.0, -1, check_multimap)
-    else
-      rspamd_config:register_callback_symbol('MULTIMAP', 1.0, check_multimap)
+    local id = rspamd_config:register_callback_symbol_priority(1.0, -1, 
+      check_multimap)
+    for i,rule in ipairs(rules) do
+      rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id)
     end
   end
 end
index 80ef8cf29af4a00b5875a9a1c44ce22260f6ba27..7cbdacf50188f3943bf71bf938610607591fb8df 100644 (file)
@@ -124,31 +124,28 @@ end
 -- Configuration
 local opts =  rspamd_config:get_all_opt('once_received')
 if opts then
-    if opts['symbol'] then
-        local symbol = opts['symbol']
+  if opts['symbol'] then
+    local symbol = opts['symbol']
 
-      for n,v in pairs(opts) do
+    local id = rspamd_config:register_symbol(symbol, 1.0, check_quantity_received)
+
+    for n,v in pairs(opts) do
       if n == 'symbol_strict' then
         symbol_strict = v
-        if type(rspamd_config.get_api_version) ~= 'nil' then
-          rspamd_config:register_virtual_symbol(symbol_strict, 1.0)
-        end
+        rspamd_config:register_virtual_symbol(symbol_strict, 1.0, id)
       elseif n == 'bad_host' then
         if type(v) == 'string' then
-            bad_hosts[1] = v
+          bad_hosts[1] = v
         else
           bad_hosts = v
         end
       elseif n == 'good_host' then
         if type(v) == 'string' then
-            good_hosts[1] = v
+          good_hosts[1] = v
         else
           good_hosts = v
         end
-        end
       end
-
-    -- Register symbol's callback
-    rspamd_config:register_symbol(symbol, 1.0, check_quantity_received)
+    end
   end
 end
index 78d3b209906350b47c8adc35abbe57402b62e669..a96977d05136ff2ef21de0460c965b67ddc0a670 100644 (file)
@@ -32,7 +32,7 @@ local domains = nil
 local strict_domains = {}
 local rspamd_logger = require "rspamd_logger"
 
-function phishing_cb (task)
+local function phishing_cb(task)
        local urls = task:get_urls();
 
        if urls then
@@ -79,41 +79,37 @@ end
 
 local opts = rspamd_config:get_all_opt('phishing')
 if opts then
-    if opts['symbol'] then
-        symbol = opts['symbol']
-        
-        -- Register symbol's callback
-        rspamd_config:register_symbol(symbol, 1.0, 'phishing_cb')
+  if opts['symbol'] then
+    symbol = opts['symbol']
+    -- Register symbol's callback
+    local id = rspamd_config:register_symbol(symbol, 1.0, phishing_cb)
+    if opts['domains'] and type(opt['domains']) == 'string' then
+      domains = rspamd_config:add_hash_map (opts['domains'])
     end
-       if opts['domains'] and type(opt['domains']) == 'string' then
-               domains = rspamd_config:add_hash_map (opts['domains'])
-       end
-       if opts['strict_domains'] then
-               local sd = {}
-               if type(opts['strict_domains']) == 'table' then
-                       sd = opts['strict_domains']
-               else
-                       sd[1] = opts['strict_domains']
-               end
-               for _,d in ipairs(sd) do
-                       local s, _ = string.find(d, ':[^:]+$')
-                       if s then
-                               local sym = string.sub(d, s + 1, -1)
-                               local map = string.sub(d, 1, s - 1)
-                               if type(rspamd_config.get_api_version) ~= 'nil' then
-                                       rspamd_config:register_virtual_symbol(sym, 1)
-                               end
-                               local rmap = rspamd_config:add_hash_map (map, 'Phishing strict domains map')
-                               if rmap then
-                                       local rule = {symbol = sym, map = rmap}
-                                       table.insert(strict_domains, rule)
-                               else
-                                       rspamd_logger.info('cannot add map: ' .. map .. ' for symbol: ' .. sym)
-                               end
-                       else
-                               rspamd_logger.info('strict_domains option must be in format <map>:<symbol>')
-                       end
-               end
-       end
-    -- If no symbol defined, do not register this module
+    if opts['strict_domains'] then
+      local sd = {}
+      if type(opts['strict_domains']) == 'table' then
+        sd = opts['strict_domains']
+      else
+        sd[1] = opts['strict_domains']
+      end
+      for _,d in ipairs(sd) do
+        local s, _ = string.find(d, ':[^:]+$')
+        if s then
+          local sym = string.sub(d, s + 1, -1)
+          local map = string.sub(d, 1, s - 1)
+          rspamd_config:register_virtual_symbol(sym, 1, id)
+          local rmap = rspamd_config:add_hash_map (map, 'Phishing strict domains map')
+          if rmap then
+            local rule = {symbol = sym, map = rmap}
+            table.insert(strict_domains, rule)
+          else
+            rspamd_logger.info('cannot add map: ' .. map .. ' for symbol: ' .. sym)
+          end
+        else
+          rspamd_logger.info('strict_domains option must be in format <map>:<symbol>')
+        end
+      end
+    end
+  end
 end
index eddb4c77bcaab263f8375d0ecbf3c0230ba0e494..cceb00449e91f7ba223d9c2622923cd2e929e93d 100644 (file)
@@ -342,6 +342,8 @@ end
 local white_symbols = {}
 local black_symbols = {}
 
+local id = rspamd_config:register_callback_symbol_priority(1.0, 0, rbl_cb)
+
 for key,rbl in pairs(opts['rbls']) do
   for default, default_v in pairs(default_defaults) do
     if(rbl[default_v[2]] == nil) then
@@ -351,7 +353,7 @@ for key,rbl in pairs(opts['rbls']) do
   if type(rbl['returncodes']) == 'table' then
     for s,_ in pairs(rbl['returncodes']) do
       if type(rspamd_config.get_api_version) ~= 'nil' then
-        rspamd_config:register_virtual_symbol(s, 1)
+        rspamd_config:register_virtual_symbol(s, 1, id)
         if(rbl['is_whitelist']) then
           table.insert(white_symbols, s)
         else
@@ -364,7 +366,7 @@ for key,rbl in pairs(opts['rbls']) do
     rbl['symbol'] = key
   end
   if type(rspamd_config.get_api_version) ~= 'nil' and rbl['symbol'] then
-    rspamd_config:register_virtual_symbol(rbl['symbol'], 1)
+    rspamd_config:register_virtual_symbol(rbl['symbol'], 1, id)
     if(rbl['is_whitelist']) then
       table.insert(white_symbols, rbl['symbol'])
     else
@@ -380,7 +382,6 @@ for _, w in pairs(white_symbols) do
     csymbol = 'RBL_COMPOSITE_' .. w .. '_' .. b
     rspamd_config:set_metric_symbol(csymbol, 0, 'Autogenerated composite')
     rspamd_config:add_composite(csymbol, w .. ' & ' .. b)
-    rspamd_config:register_virtual_symbol(csymbol, 1)
+    rspamd_config:register_virtual_symbol(csymbol, 1, id)
   end
 end
-rspamd_config:register_callback_symbol_priority('RBL', 1.0, 0, rbl_cb)
index 279fc2d67981664f3a1e824352234b06ec4e739c..d41d12b5ddf64e26974e0e48ac7d56d7cac0c92a 100644 (file)
@@ -128,8 +128,6 @@ local function process_trie_conf(symbol, cf)
       process_single_pattern(pat, symbol, cf)
     end, cf['patterns'])
   end
-  
-  rspamd_config:register_virtual_symbol(symbol, 1.0)
 end
 
 local opts =  rspamd_config:get_all_opt("trie")
@@ -147,10 +145,17 @@ if opts then
     mime_trie = rspamd_trie.create(mime_patterns)
     rspamd_logger.infox('registered mime search trie from %1 patterns', #mime_patterns)
   end
-
+  
+  local id = -1
   if mime_trie or raw_trie then
-    rspamd_config:register_callback_symbol('TRIE', 1.0, tries_callback)
+    id = rspamd_config:register_callback_symbol('TRIE', 1.0, tries_callback)
   else
     rspamd_logger.err('no tries defined')
   end
+  
+  if id ~= -1 then
+    for sym, opt in pairs(opts) do
+      rspamd_config:register_virtual_symbol(sym, 1.0, id)
+    end
+  end
 end