diff mod_firewall/actions.lib.lua @ 5235:d0d251abf595

mod_firewall: Add 'REPORT TO' to report (XEP-0377) a stanza to a specified JID
author Matthew Wild <mwild1@gmail.com>
date Sat, 11 Mar 2023 18:41:49 +0000
parents 5a3dfb970888
children 96dec7681af8
line wrap: on
line diff
--- a/mod_firewall/actions.lib.lua	Sat Mar 11 18:29:38 2023 +0000
+++ b/mod_firewall/actions.lib.lua	Sat Mar 11 18:41:49 2023 +0000
@@ -241,4 +241,22 @@
 	       { "rostermanager", "core_post_stanza", "st", "split_to", "bare_to", "bare_from" };
 end
 
+function action_handlers.REPORT_TO(spec)
+	local where, reason, text = spec:match("^%s*(%S+) *(%S*) *(.*)$");
+	if reason == "spam" then
+		reason = "urn:xmpp:reporting:spam";
+	elseif reason == "abuse" or not reason then
+		reason = "urn:xmpp:reporting:abuse";
+	end
+	local code = [[
+		local newstanza = st.stanza("message", { to = %q, from = current_host }):tag("forwarded", { xmlns = "urn:xmpp:forward:0" });
+		local tmp_stanza = st.clone(stanza); tmp_stanza.attr.xmlns = "jabber:client"; newstanza:add_child(tmp_stanza):up();
+		newstanza:tag("report", { xmlns = "urn:xmpp:reporting:1", reason = %q })
+		do local text = %q; if text ~= "" then newstanza:text_tag("text", text); end end
+		newstanza:up();
+		core_post_stanza(session, newstanza);
+	]];
+	return code:format(where, reason, text), { "core_post_stanza", "current_host", "st" };
+end
+
 return action_handlers;