Browse Source

[Feature] Spf: Add external_relay option

tags/2.3
Vsevolod Stakhov 4 years ago
parent
commit
e2dfcf15cc
2 changed files with 37 additions and 3 deletions
  1. 1
    1
      lualib/lua_util.lua
  2. 36
    2
      src/plugins/lua/spf.lua

+ 1
- 1
lualib/lua_util.lua View File

@@ -1344,7 +1344,7 @@ exports.is_skip_local_or_authed = function(task, conf, ip)
conf = {false, false}
end
if ((not conf[2] and task:get_user()) or
(not conf[1] and ip and ip:is_local())) then
(not conf[1] and type(ip) == 'userdata' and ip:is_local())) then
return true
end


+ 36
- 2
src/plugins/lua/spf.lua View File

@@ -41,6 +41,8 @@ spf {
min_cache_ttl = 5m;
# Disable all IPv6 lookups
disable_ipv6 = false;
# Use IP address from a received header produced by this relay (using by attribute)
external_relay = "192.168.1.1";
}
]])
return
@@ -63,7 +65,8 @@ local default_config = {
whitelist = nil,
min_cache_ttl = 60 * 5,
disable_ipv6 = false,
symbols = symbols
symbols = symbols,
external_relay = nil,
}

local local_config = rspamd_config:get_all_opt('spf')
@@ -78,7 +81,38 @@ end

local function spf_check_callback(task)

local ip = task:get_from_ip()
local ip

if local_config.external_relay then
-- Search received headers to get header produced by an external relay
local rh = task:get_received_headers() or {}
local found = false

for i,hdr in ipairs(rh) do
if hdr.real_ip and hdr.real_ip == local_config.external_relay then
-- We can use the next header as a source of IP address
if rh[i + 1] then
local nhdr = rh[i + 1]
lua_util.debugm(N, task, 'found external relay %s at received header %s -> %s',
local_config.external_relay, hdr, nhdr.real_ip)

if nhdr.real_ip then
ip = nhdr.real_ip
found = true
end
end

break
end
end
if not found then
rspamd_logger.warnx(task, "cannot find external relay with IP %s",
local_config.external_relay)
ip = task:get_from_ip()
end
else
ip = task:get_from_ip()
end

local function flag_to_symbol(fl)
if bit.band(fl, rspamd_spf.flags.temp_fail) ~= 0 then

Loading…
Cancel
Save