* Provide compatibility for lua plugins for old versions of rspamdtags/0.3.7
@@ -16,6 +16,8 @@ | |||
extern const luaL_reg null_reg[]; | |||
#define RSPAMD_LUA_API_VERSION 1 | |||
/* Common utility functions */ | |||
void lua_newclass (lua_State *L, const gchar *classname, const struct luaL_reg *func); | |||
void lua_setclass (lua_State *L, const gchar *classname, gint objidx); |
@@ -44,6 +44,7 @@ LUA_FUNCTION_DEF (config, register_virtual_symbol); | |||
LUA_FUNCTION_DEF (config, register_callback_symbol); | |||
LUA_FUNCTION_DEF (config, register_post_filter); | |||
LUA_FUNCTION_DEF (config, register_module_option); | |||
LUA_FUNCTION_DEF (config, get_api_version); | |||
static const struct luaL_reg configlib_m[] = { | |||
LUA_INTERFACE_DEF (config, get_module_opt), | |||
@@ -57,6 +58,7 @@ static const struct luaL_reg configlib_m[] = { | |||
LUA_INTERFACE_DEF (config, register_callback_symbol), | |||
LUA_INTERFACE_DEF (config, register_module_option), | |||
LUA_INTERFACE_DEF (config, register_post_filter), | |||
LUA_INTERFACE_DEF (config, get_api_version), | |||
{"__tostring", lua_class_tostring}, | |||
{NULL, NULL} | |||
}; | |||
@@ -128,6 +130,13 @@ lua_check_trie (lua_State * L) | |||
} | |||
/*** Config functions ***/ | |||
static gint | |||
lua_config_get_api_version (lua_State *L) | |||
{ | |||
lua_pushinteger (L, RSPAMD_LUA_API_VERSION); | |||
return 1; | |||
} | |||
static gint | |||
lua_config_get_module_opt (lua_State * L) | |||
{ |
@@ -64,8 +64,12 @@ function check_forged_headers(task) | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string') | |||
rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
if rspamd_config:get_api_version() >= 1 then | |||
rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string') | |||
rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string') | |||
end | |||
end | |||
-- Configuration | |||
local opts = rspamd_config:get_all_opt('forged_recipients') | |||
@@ -73,13 +77,21 @@ if opts then | |||
if opts['symbol_rcpt'] or opts['symbol_sender'] then | |||
if opts['symbol_rcpt'] then | |||
symbol_rcpt = opts['symbol_rcpt'] | |||
rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, 'check_forged_headers') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, 'check_forged_headers') | |||
end | |||
end | |||
if opts['symbol_sender'] then | |||
symbol_sender = opts['symbol_sender'] | |||
rspamd_config:register_virtual_symbol(symbol_sender, 1.0) | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_virtual_symbol(symbol_sender, 1.0) | |||
end | |||
end | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_callback_symbol('FORGED_RECIPIENTS', 1.0, 'check_forged_headers') | |||
else | |||
rspamd_config:register_symbol('FORGED_RECIPIENTS', 1.0, 'check_forged_headers') | |||
end | |||
rspamd_config:register_callback_symbol('FORGED_RECIPIENTS', 1.0, 'check_forged_headers') | |||
end | |||
end |
@@ -163,7 +163,11 @@ function check_maillist(task) | |||
end | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('maillist', 'symbol', 'string') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
if rspamd_config:get_api_version() >= 1 then | |||
rspamd_config:register_module_option('maillist', 'symbol', 'string') | |||
end | |||
end | |||
-- Configuration | |||
local opts = rspamd_config:get_all_opt('maillist') | |||
if opts then |
@@ -130,7 +130,11 @@ function add_rule(params) | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('multimap', 'rule', 'string') | |||
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 then | |||
@@ -143,7 +147,9 @@ if opts then | |||
if not rule then | |||
rspamd_logger:err('cannot add rule: "'..value..'"') | |||
else | |||
rspamd_config:register_virtual_symbol(rule['symbol'], 1.0) | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_virtual_symbol(rule['symbol'], 1.0) | |||
end | |||
end | |||
end | |||
elseif type(strrules) == 'string' then | |||
@@ -152,7 +158,9 @@ if opts then | |||
if not rule then | |||
rspamd_logger:err('cannot add rule: "'..strrules..'"') | |||
else | |||
rspamd_config:register_virtual_symbol(rule['symbol'], 1.0) | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_virtual_symbol(rule['symbol'], 1.0) | |||
end | |||
end | |||
end | |||
end | |||
@@ -160,5 +168,9 @@ end | |||
if table.maxn(rules) > 0 then | |||
-- add fake symbol to check all maps inside a single callback | |||
rspamd_config:register_callback_symbol('MULTIMAP', 1.0, 'check_multimap') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_callback_symbol('MULTIMAP', 1.0, 'check_multimap') | |||
else | |||
rspamd_config:register_symbol('MULTIMAP', 1.0, 'check_multimap') | |||
end | |||
end |
@@ -45,10 +45,14 @@ function check_quantity_received (task) | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('once_received', 'symbol', 'string') | |||
rspamd_config:register_module_option('once_received', 'symbol_strict', 'string') | |||
rspamd_config:register_module_option('once_received', 'bad_host', 'string') | |||
rspamd_config:register_module_option('once_received', 'good_host', 'string') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
if rspamd_config:get_api_version() >= 1 then | |||
rspamd_config:register_module_option('once_received', 'symbol', 'string') | |||
rspamd_config:register_module_option('once_received', 'symbol_strict', 'string') | |||
rspamd_config:register_module_option('once_received', 'bad_host', 'string') | |||
rspamd_config:register_module_option('once_received', 'good_host', 'string') | |||
end | |||
end | |||
-- Configuration | |||
local opts = rspamd_config:get_all_opt('once_received') | |||
@@ -59,7 +63,9 @@ if opts then | |||
for n,v in pairs(opts) do | |||
if n == 'symbol_strict' then | |||
symbol_strict = v | |||
rspamd_config:register_virtual_symbol(symbol_strict, 1.0) | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_virtual_symbol(symbol_strict, 1.0) | |||
end | |||
elseif n == 'bad_host' then | |||
bad_hosts = v | |||
elseif n == 'good_host' then |
@@ -28,8 +28,12 @@ function phishing_cb (task) | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('phishing', 'symbol', 'string') | |||
rspamd_config:register_module_option('phishing', 'domains', 'map') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
if rspamd_config:get_api_version() >= 1 then | |||
rspamd_config:register_module_option('phishing', 'symbol', 'string') | |||
rspamd_config:register_module_option('phishing', 'domains', 'map') | |||
end | |||
end | |||
local opts = rspamd_config:get_all_opt('phishing') | |||
if opts then |
@@ -56,8 +56,12 @@ function received_cb (task) | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('received_rbl', 'symbol', 'string') | |||
rspamd_config:register_module_option('received_rbl', 'rbl', 'string') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
if rspamd_config:get_api_version() >= 1 then | |||
rspamd_config:register_module_option('received_rbl', 'symbol', 'string') | |||
rspamd_config:register_module_option('received_rbl', 'rbl', 'string') | |||
end | |||
end | |||
-- Configuration | |||
local opts = rspamd_config:get_all_opt('received_rbl') | |||
@@ -71,7 +75,9 @@ if opts then | |||
for _,rbl in ipairs(rbls) do | |||
local s, _ = string.find(rbl, ':') | |||
if s then | |||
rspamd_config:register_virtual_symbol(string.sub(rbl, s + 1, -1), 1) | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
rspamd_config:register_virtual_symbol(string.sub(rbl, s + 1, -1), 1) | |||
end | |||
end | |||
end | |||
-- Register symbol's callback |
@@ -33,10 +33,14 @@ function check_whitelist (task) | |||
end | |||
-- Registration | |||
rspamd_config:register_module_option('whitelist', 'symbol_ip', 'string') | |||
rspamd_config:register_module_option('whitelist', 'symbol_from', 'string') | |||
rspamd_config:register_module_option('whitelist', 'ip_whitelist', 'map') | |||
rspamd_config:register_module_option('whitelist', 'from_whitelist', 'map') | |||
if type(rspamd_config.get_api_version) ~= 'nil' then | |||
if rspamd_config:get_api_version() >= 1 then | |||
rspamd_config:register_module_option('whitelist', 'symbol_ip', 'string') | |||
rspamd_config:register_module_option('whitelist', 'symbol_from', 'string') | |||
rspamd_config:register_module_option('whitelist', 'ip_whitelist', 'map') | |||
rspamd_config:register_module_option('whitelist', 'from_whitelist', 'map') | |||
end | |||
end | |||
-- Configuration | |||
local opts = rspamd_config:get_all_opt('whitelist') |