comparison mod_report_forward/mod_report_forward.lua @ 6038:91590d92b919

mod_report_forward: Add default fallback to domain JID when sending reports No harm in trying...
author Matthew Wild <mwild1@gmail.com>
date Tue, 26 Nov 2024 12:12:59 +0000
parents 7b093a9b95ea
children 93efc6c4fe93
comparison
equal deleted inserted replaced
6037:7d4386cc73d3 6038:91590d92b919
12 12
13 local archive = module:open_store("archive", "archive"); 13 local archive = module:open_store("archive", "archive");
14 14
15 local cache_size = module:get_option_number("report_forward_contact_cache_size", 256); 15 local cache_size = module:get_option_number("report_forward_contact_cache_size", 256);
16 local report_to_origin = module:get_option_boolean("report_forward_to_origin", true); 16 local report_to_origin = module:get_option_boolean("report_forward_to_origin", true);
17 local report_to_origin_fallback = module:get_option_boolean("report_forward_to_origin_fallback", true);
17 local contact_lookup_timeout = module:get_option_number("report_forward_contact_lookup_timeout", 180); 18 local contact_lookup_timeout = module:get_option_number("report_forward_contact_lookup_timeout", 180);
18 19
19 local body_template = module:get_option_string("report_forward_body_template", [[ 20 local body_template = module:get_option_string("report_forward_body_template", [[
20 SPAM/ABUSE REPORT 21 SPAM/ABUSE REPORT
21 ----------------- 22 -----------------
63 64
64 return module:send_iq(contact_query, prosody.hosts[module.host], contact_lookup_timeout) 65 return module:send_iq(contact_query, prosody.hosts[module.host], contact_lookup_timeout)
65 :next(function (result) 66 :next(function (result)
66 module:log("debug", "Processing contact form..."); 67 module:log("debug", "Processing contact form...");
67 local response = result.stanza; 68 local response = result.stanza;
68 if response.attr.type ~= "result" then 69 if response.attr.type == "result" then
69 module:log("warn", "Failed to query contact addresses of %s: %s", host, response); 70 for form in response.tags[1]:childtags("x", "jabber:x:data") do
70 return; 71 local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE");
72 if form_type and form_type:get_child_text("value") == "http://jabber.org/network/serverinfo" then
73 address = get_address(form, "spam-report-addresses", "abuse-addresses");
74 break;
75 end
76 end
71 end 77 end
72 78
73 for form in response.tags[1]:childtags("x", "jabber:x:data") do 79 if not address then
74 local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE"); 80 if report_to_origin_fallback then
75 if form_type and form_type:get_child_text("value") == "http://jabber.org/network/serverinfo" then 81 -- If no contact address found, but fallback is enabled,
76 address = get_address(form, "spam-report-addresses", "abuse-addresses"); 82 -- just send the report to the domain
77 break; 83 module:log("debug", "Falling back to domain to send report to %s", host);
84 address = host;
85 else
86 module:log("warn", "Failed to query contact addresses of %s: %s", host, response);
78 end 87 end
79 end 88 end
89
80 return address; 90 return address;
81 end); 91 end);
82 end 92 end
83 93
84 local function send_report(to, message) 94 local function send_report(to, message)