From 422749d19d44b508f226adbe66072d8a633dcc33 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 19 Mar 2018 15:26:30 +0000 Subject: [Minor] Fix X-Originating-Ip handle in elastic plugin --- src/plugins/lua/elastic.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua index 3c7830de6..854f5ec64 100644 --- a/src/plugins/lua/elastic.lua +++ b/src/plugins/lua/elastic.lua @@ -120,8 +120,16 @@ local function get_general_metadata(task) r.is_local = ip_addr:is_local() local origin = task:get_header('X-Originating-IP') if origin then - r.webmail = true - r.ip = origin + origin = string.sub(origin, 2, -2) + local rspamd_ip = require "rspamd_ip" + local test = rspamd_ip.from_string(origin) + + if test and test:is_valid() then + r.webmail = true + r.ip = origin + else + r.ip = tostring(ip_addr) + end else r.ip = tostring(ip_addr) end -- cgit v1.2.3