Software /
code /
prosody-modules
Annotate
mod_report_forward/mod_report_forward.lua @ 5880:6fe4dab27187
mod_report_forward: Depend on mod_spam_reporting for auto-loading
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 03 Mar 2024 16:10:14 +0000 |
parent | 5879:05356f2d4425 |
child | 5881:ff90dad75352 |
rev | line source |
---|---|
5868
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"; |
5868
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 |
5880
6fe4dab27187
mod_report_forward: Depend on mod_spam_reporting for auto-loading
Matthew Wild <mwild1@gmail.com>
parents:
5879
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:
5879
diff
changeset
|
10 |
5878
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5871
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 |
5879
05356f2d4425
mod_report_forward: Open archive store correctly (thanks Menel)
Matthew Wild <mwild1@gmail.com>
parents:
5878
diff
changeset
|
13 local archive = module:open_store("archive", "archive"); |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
14 |
5878
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5871
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:
5871
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:
5871
diff
changeset
|
17 local contact_lookup_timeout = module:get_option_number("report_forward_contact_lookup_timeout", 180); |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
18 |
5878
fcfe490de8a4
mod_spam_report_forwarder: Rename to mod_report_forward
Matthew Wild <mwild1@gmail.com>
parents:
5871
diff
changeset
|
19 local body_template = module:get_option_string("report_forward_body_template", [[ |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
20 SPAM/ABUSE REPORT |
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 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
30 -- |
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, ...); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
42 local field = form:get_child_with_attr("field", "jabber:x:data", "var", field_var); |
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 |
5871
d00af6ebb326
mod_spam_report_forwarder: Only forward to xmpp: URIs, and exclude MUCs
Matthew Wild <mwild1@gmail.com>
parents:
5868
diff
changeset
|
44 local parsed = url.parse(field:get_child_text("value")); |
d00af6ebb326
mod_spam_report_forwarder: Only forward to xmpp: URIs, and exclude MUCs
Matthew Wild <mwild1@gmail.com>
parents:
5868
diff
changeset
|
45 if parsed.scheme == "xmpp" and parsed.path and not parsed.query then |
d00af6ebb326
mod_spam_report_forwarder: Only forward to xmpp: URIs, and exclude MUCs
Matthew Wild <mwild1@gmail.com>
parents:
5868
diff
changeset
|
46 return parsed.path; |
d00af6ebb326
mod_spam_report_forwarder: Only forward to xmpp: URIs, and exclude MUCs
Matthew Wild <mwild1@gmail.com>
parents:
5868
diff
changeset
|
47 end |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
48 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
49 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
50 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
51 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 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
|
56 |
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 contact_query = st.iq({ to = host, from = module.host, id = new_id() }) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
58 :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
|
59 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
60 return module:send_iq(contact_query, prosody.hosts[module.host], contact_lookup_timeout) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
61 :next(function (response) |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
62 if response.attr.type ~= "result" then return; end |
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 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
|
65 local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE"); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
66 if form_type == "http://jabber.org/network/serverinfo" then |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
67 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
|
68 break; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
69 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
70 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
71 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
|
72 end); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
73 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
74 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
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 |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 function forward_report(event) |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 local report = st.clone(event.report); |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
87 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
|
88 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
89 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
|
90 "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
|
91 "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
|
92 "by", |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
93 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
|
94 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
|
95 ); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
96 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
103 end |
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 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
|
106 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
|
107 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
|
108 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
|
109 }); |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 local message = st.message({ from = module.host }) |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
112 :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
|
113 :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
|
114 |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 :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
|
119 :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
|
120 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
|
121 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
122 |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 for destination in destinations do |
5868
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
124 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
|
125 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
126 |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 return; |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
133 end |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
134 send_report(origin_report_address, message); |
37e38ee534ea
mod_spam_report_forwarder: Support for reporting messages, and reporting to origin server
Matthew Wild <mwild1@gmail.com>
parents:
5238
diff
changeset
|
135 end); |
5238
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 end |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 end |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 |
94472eb41d0a
mod_spam_report_forwarder: Forward spam/abuse reports to one or more JIDs
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 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
|
140 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
|
141 module:hook("spam_reporting/unknown-report", forward_report, -1); |