aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conf/lua.local.d/module.lua.example62
-rw-r--r--rules/rspamd.lua4
2 files changed, 66 insertions, 0 deletions
diff --git a/conf/lua.local.d/module.lua.example b/conf/lua.local.d/module.lua.example
new file mode 100644
index 000000000..336db6c49
--- /dev/null
+++ b/conf/lua.local.d/module.lua.example
@@ -0,0 +1,62 @@
+-- This directory is used to define user specific rules and plugins for Rspamd in Lua
+-- Each *.lua file is executed and added to the Rspamd
+
+-- Example of regexp rule:
+
+local reconf = config['regexp'] -- Create alias for regexp configs
+
+local re1 = 'From=/foo@/H' -- Mind local here
+local re2 = '/blah/P'
+
+reconf['SYMBOL'] = {
+ re = string.format('(%s) && !(%s)', re1, re2), -- use string.format to create expression
+ score = 1.2,
+ description = 'some description',
+
+ condition = function(task)
+ -- run this rule only if some condition is satisfied
+ return true
+ end,
+}
+
+-- Example of a simple lua rule:
+rspamd_config.SYMBOL = {
+ callback = function(task)
+ return true
+ end,
+ score = 1.2,
+ description = 'some description',
+
+ condition = function(task)
+ -- run this rule only if some condition is satisfied
+ return true
+ end,
+}
+
+-- Example of a plugin with configuration:
+local redis_params
+local lua_redis = require "lua_redis"
+
+local function symbol_cb(task)
+ local function redis_set_cb(err)
+ if err ~= nil then
+ rspamd_logger.errx(task, 'redis_set_cb received error: %1', err)
+ end
+ end
+ -- Create hash of message-id and store to redis
+ local key = make_key(task)
+ local ret = lua_redis.redis_make_request(task,
+ redis_params, -- connect params
+ key, -- hash key
+ true, -- is write
+ redis_set_cb, --callback
+ 'SETEX', -- command
+ { key, tostring(settings['expire']), "1" } -- arguments
+ )
+end
+
+-- Load redis server for module named 'module'
+redis_params = lua_redis.parse_redis_server('module')
+if redis_params then
+ -- Register symbol
+end
diff --git a/rules/rspamd.lua b/rules/rspamd.lua
index dcc872d15..3b80a035a 100644
--- a/rules/rspamd.lua
+++ b/rules/rspamd.lua
@@ -51,6 +51,10 @@ else
end
end
+for local_lua in rspamd_util.glob(local_conf .. '/lua.local.d/*.lua') do
+ dofile(local_lua)
+end
+
if rspamd_util.file_exists(local_conf .. '/local.d/rspamd.lua') then
dofile(local_conf .. '/local.d/rspamd.lua')
end