comparison mod_report_forward/mod_report_forward.lua @ 6110:9db1529c06c2

Merge upstream
author tmolitor <thilo@eightysoft.de>
date Sun, 05 Jan 2025 17:50:02 +0100
parents 226886ffafb0
children fc521fb5ffa0
comparison
equal deleted inserted replaced
6109:4cb1cad2badd 6110:9db1529c06c2
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 -----------------
28 {reported_message_time&The reported message was sent at: {reported_message_time}} 29 {reported_message_time&The reported message was sent at: {reported_message_time}}
29 30
30 -- 31 --
31 This message contains also machine-readable payloads, including XEP-0377, in case 32 This message contains also machine-readable payloads, including XEP-0377, in case
32 you want to automate handling of these reports. You can receive these reports 33 you want to automate handling of these reports. You can receive these reports
33 to a different address by setting 'spam-report-addresses' in your server 34 to a different address by setting 'report-addresses' in your server
34 contact info configuration. For more information, see https://xmppbl.org/reports/ 35 contact info configuration. For more information, see https://xmppbl.org/reports/
35 ]]):gsub("^%s+", ""):gsub("(%S)\n(%S)", "%1 %2"); 36 ]]):gsub("^%s+", ""):gsub("(%S)\n(%S)", "%1 %2");
36 37
37 local report_addresses = require "util.cache".new(cache_size); 38 local report_addresses = require "util.cache".new(cache_size);
38 39
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, "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)