Mercurial > prosody-modules
diff 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 |
line wrap: on
line diff
--- a/mod_report_forward/mod_report_forward.lua Mon Nov 25 14:33:01 2024 +0000 +++ b/mod_report_forward/mod_report_forward.lua Tue Nov 26 12:12:59 2024 +0000 @@ -14,6 +14,7 @@ local cache_size = module:get_option_number("report_forward_contact_cache_size", 256); local report_to_origin = module:get_option_boolean("report_forward_to_origin", true); +local report_to_origin_fallback = module:get_option_boolean("report_forward_to_origin_fallback", true); local contact_lookup_timeout = module:get_option_number("report_forward_contact_lookup_timeout", 180); local body_template = module:get_option_string("report_forward_body_template", [[ @@ -65,18 +66,27 @@ :next(function (result) module:log("debug", "Processing contact form..."); local response = result.stanza; - if response.attr.type ~= "result" then - module:log("warn", "Failed to query contact addresses of %s: %s", host, response); - return; + if response.attr.type == "result" then + for form in response.tags[1]:childtags("x", "jabber:x:data") do + local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE"); + if form_type and form_type:get_child_text("value") == "http://jabber.org/network/serverinfo" then + address = get_address(form, "spam-report-addresses", "abuse-addresses"); + break; + end + end end - for form in response.tags[1]:childtags("x", "jabber:x:data") do - local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE"); - if form_type and form_type:get_child_text("value") == "http://jabber.org/network/serverinfo" then - address = get_address(form, "spam-report-addresses", "abuse-addresses"); - break; + if not address then + if report_to_origin_fallback then + -- If no contact address found, but fallback is enabled, + -- just send the report to the domain + module:log("debug", "Falling back to domain to send report to %s", host); + address = host; + else + module:log("warn", "Failed to query contact addresses of %s: %s", host, response); end end + return address; end); end
