mod_s2s_blacklist/mod_s2s_blacklist.lua
author Matthew Wild <mwild1@gmail.com>
Tue, 05 Mar 2024 18:26:29 +0000
changeset 5863 259ffdbf8906
parent 2897 d958558e0058
permissions -rw-r--r--
mod_anti_spam: New module for spam filtering (pre-alpha)

local st = require "util.stanza";

local blacklist = module:get_option_inherited_set("s2s_blacklist", {});

module:hook("route/remote", function (event)
	if blacklist:contains(event.to_host) then
		if event.stanza.attr.type ~= "error" then
			module:send(st.error_reply(event.stanza, "cancel", "not-allowed", "Communication with this domain is restricted"));
		end
		return true;
	end
end, 100);

module:hook("s2s-stream-features", function (event)
	if blacklist:contains(event.origin.from_host) then
		event.origin:close({
			condition = "policy-violation";
			text = "Communication with this domain is restricted";
		});
	end
end, 1000);