From ec3e4b6711f708b19fb3ebdb8fcb0dbef5e27e43 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 21 Jul 2016 09:25:09 +0100 Subject: [PATCH] [Feature] Allow client ip match in the settings --- src/plugins/lua/settings.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index ed44e2dba..410aad7af 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -139,7 +139,7 @@ local function check_settings(task) return false end - local function check_specific_setting(name, rule, ip, from, rcpt, user) + local function check_specific_setting(name, rule, ip, client_ip, from, rcpt, user) local res = false if rule['ip'] then @@ -157,6 +157,21 @@ local function check_settings(task) end end + if rule['client_ip'] then + if not client_ip or not client_ip:is_valid() then + return nil + end + for _, i in ipairs(rule['client_ip']) do + res = check_ip_setting(i, client_ip) + if res then + break + end + end + if not res then + return nil + end + end + if rule['from'] then if not from then return nil @@ -225,6 +240,7 @@ local function check_settings(task) rspamd_logger.infox(task, "check for settings") local ip = task:get_from_ip() + local client_ip = task:get_client_ip() local from = task:get_from() local rcpt = task:get_recipients() local uname = task:get_user() @@ -246,7 +262,7 @@ local function check_settings(task) for pri = max_pri,1,-1 do if settings[pri] then for name, r in pairs(settings[pri]) do - local rule = check_specific_setting(name, r, ip, from, rcpt, user) + local rule = check_specific_setting(name, r, ip, client_ip, from, rcpt, user) if rule then rspamd_logger.infox(task, "<%1> apply settings according to rule %2", task:get_message_id(), name) -- 2.39.5