Mercurial > prosody-modules
annotate mod_report_forward/mod_report_forward.lua @ 5883:6c11e1b4066d
mod_http_admin_api: User activity gauges need to be summed (labels by host)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 16 Apr 2024 12:05:47 +0100 |
parents | b5a110544fd4 |
children | db5128d1a16c |
rev | line source |
---|---|
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
1 local dt = require "util.datetime"; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
2 local jid = require "util.jid"; |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local st = require "util.stanza"; |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
4 local url = require "socket.url"; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
5 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
6 local new_id = require "util.id".short; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
7 local render = require"util.interpolation".new("%b{}", function (s) return s; end); |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
5856
6fe4dab27187
mod_report_forward: Depend on mod_spam_reporting for auto-loading
Matthew Wild <mwild1@gmail.com>
parents:
5855
diff
changeset
|
9 module:depends("spam_reporting"); |
6fe4dab27187
mod_report_forward: Depend on mod_spam_reporting for auto-loading
Matthew Wild <mwild1@gmail.com>
parents:
5855
diff
changeset
|
10 |
5854
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5847
diff
changeset
|
11 local destinations = module:get_option_set("report_forward_to", {}); |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
5855
05356f2d4425
mod_report_forward: Open archive store correctly (thanks Menel)
Matthew Wild <mwild1@gmail.com>
parents:
5854
diff
changeset
|
13 local archive = module:open_store("archive", "archive"); |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
14 |
5854
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5847
diff
changeset
|
15 local cache_size = module:get_option_number("report_forward_contact_cache_size", 256); |
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5847
diff
changeset
|
16 local report_to_origin = module:get_option_boolean("report_forward_to_origin", true); |
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5847
diff
changeset
|
17 local contact_lookup_timeout = module:get_option_number("report_forward_contact_lookup_timeout", 180); |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
18 |
5854
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5847
diff
changeset
|
19 local body_template = module:get_option_string("report_forward_body_template", [[ |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
20 SPAM/ABUSE REPORT |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
21 ----------------- |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
22 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
23 Reported JID: {reported_jid} |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
24 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
25 A user on our service has reported a message originating from the above JID on |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
26 your server. |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
27 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
28 {reported_message_time&The reported message was sent at: {reported_message_time}} |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
29 |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
30 -- |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
31 This message contains also machine-readable payloads, including XEP-0377, in case |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
32 you want to automate handling of these reports. You can receive these reports |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
33 to a different address by setting 'spam-report-addresses' in your server |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
34 contact info configuration. For more information, see https://xmppbl.org/reports/ |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
35 ]]):gsub("^%s+", ""):gsub("(%S)\n(%S)", "%1 %2"); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
36 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
37 local report_addresses = require "util.cache".new(cache_size); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
38 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
39 local function get_address(form, ...) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
40 for i = 1, select("#", ...) do |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
41 local field_var = select(i, ...); |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
42 local field = form:get_child_with_attr("field", nil, "var", field_var); |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
43 if field then |
5860
fdff8cb54302
mod_report_forward: fix address detection when there are multiple field values
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
5857
diff
changeset
|
44 for value in field:childtags("value") do |
fdff8cb54302
mod_report_forward: fix address detection when there are multiple field values
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
5857
diff
changeset
|
45 local parsed = url.parse(value:get_text()); |
fdff8cb54302
mod_report_forward: fix address detection when there are multiple field values
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
5857
diff
changeset
|
46 if parsed.scheme == "xmpp" and parsed.path and not parsed.query then |
fdff8cb54302
mod_report_forward: fix address detection when there are multiple field values
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
5857
diff
changeset
|
47 return parsed.path; |
fdff8cb54302
mod_report_forward: fix address detection when there are multiple field values
Stephen Paul Weber <singpolyma@singpolyma.net>
parents:
5857
diff
changeset
|
48 end |
5847
d00af6ebb326
mod_spam_report_forwarder: Only forward to xmpp: URIs, and exclude MUCs
Matthew Wild <mwild1@gmail.com>
parents:
5844
diff
changeset
|
49 end |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
50 else |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
51 module:log("debug", "No field '%s'", field_var); |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
52 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
53 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
54 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
55 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
56 local function get_origin_report_address(reported_jid) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
57 local host = jid.host(reported_jid); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
58 local address = report_addresses:get(host); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
59 if address then return address; end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
60 |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
61 local contact_query = st.iq({ type = "get", to = host, from = module.host, id = new_id() }) |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
62 :query("http://jabber.org/protocol/disco#info"); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
63 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
64 return module:send_iq(contact_query, prosody.hosts[module.host], contact_lookup_timeout) |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
65 :next(function (result) |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
66 module:log("debug", "Processing contact form..."); |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
67 local response = result.stanza; |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
68 if response.attr.type ~= "result" then |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
69 module:log("warn", "Failed to query contact addresses of %s: %s", host, response); |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
70 return; |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
71 end |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
72 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
73 for form in response.tags[1]:childtags("x", "jabber:x:data") do |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
74 local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE"); |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
75 if form_type and form_type:get_child_text("value") == "http://jabber.org/network/serverinfo" then |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
76 address = get_address(form, "spam-report-addresses", "abuse-addresses"); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
77 break; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
78 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
79 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
80 return address; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
81 end); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
82 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
83 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
84 local function send_report(to, message) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
85 local m = st.clone(message); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
86 m.attr.to = to; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
87 module:send(m); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
88 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
89 |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 function forward_report(event) |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
91 local reporter_username = event.origin.username; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
92 local reporter_jid = jid.join(reporter_username, module.host); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
93 local reported_jid = event.jid; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
94 |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 local report = st.clone(event.report); |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
96 report:text_tag("jid", reported_jid, { xmlns = "urn:xmpp:jid:0" }); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
97 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
98 local reported_message_id = report:get_child_with_attr( |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
99 "stanza-id", |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
100 "urn:xmpp:sid:0", |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
101 "by", |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
102 reported_jid, |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
103 jid.prep |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
104 ); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
105 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
106 local reported_message, reported_message_time, reported_message_with; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
107 if reported_message_id then |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
108 reported_message, reported_message_time, reported_message_with = archive:get(reporter_username, reported_message_id); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
109 if jid.bare(reported_message_with) ~= event.jid then |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
110 reported_message = nil; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
111 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
112 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
113 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
114 local body_text = render(body_template, { |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
115 reporter_jid = reporter_jid; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
116 reported_jid = event.jid; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
117 reported_message_time = dt.datetime(reported_message_time); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
118 }); |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
5864
b5a110544fd4
mod_report_forward: Include id on report submissions
Matthew Wild <mwild1@gmail.com>
parents:
5860
diff
changeset
|
120 local message = st.message({ from = module.host, id = new_id() }) |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
121 :text_tag("body", body_text) |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 :add_child(report); |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
124 if reported_message then |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
125 reported_message.attr.xmlns = "jabber:client"; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
126 local fwd = st.stanza("forwarded", { xmlns = "urn:xmpp:forward:0" }) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
127 :tag("delay", { xmlns = "urn:xmpp:delay", stamp = dt.datetime(reported_message_time) }):up() |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
128 :add_child(reported_message); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
129 message:add_child(fwd); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
130 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
131 |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 for destination in destinations do |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
133 send_report(destination, message); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
134 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
135 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
136 if report_to_origin then |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
137 module:log("debug", "Sending report to origin server..."); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
138 get_origin_report_address(event.jid):next(function (origin_report_address) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
139 if not origin_report_address then |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
140 module:log("warn", "Couldn't report to origin: no contact address found for %s", jid.host(event.jid)); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
141 return; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
142 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
143 send_report(origin_report_address, message); |
5857
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
144 end):catch(function (e) |
ff90dad75352
mod_report_forward: Fixes for abuse contact address lookup in origin reporting
Matthew Wild <mwild1@gmail.com>
parents:
5856
diff
changeset
|
145 module:log("error", "Failed to report to origin server: %s", e); |
5844
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
146 end); |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 end |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 end |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 module:hook("spam_reporting/abuse-report", forward_report, -1); |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 module:hook("spam_reporting/spam-report", forward_report, -1); |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 module:hook("spam_reporting/unknown-report", forward_report, -1); |