# HG changeset patch # User Matthew Wild # Date 1378202820 -3600 # Node ID 513aa2e0c045541eafb9661406e5ca399b15f5d6 # Parent 27b4e01ddbc487c8e908f73def35b1823398b753 mod_host_blacklist: Similar to mod_s2s_blacklist, but stanza-based. Works between hosts on the same server, at a slight performance impact. diff -r 27b4e01ddbc4 -r 513aa2e0c045 mod_host_blacklist/mod_host_blacklist.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_host_blacklist/mod_host_blacklist.lua Tue Sep 03 11:07:00 2013 +0100 @@ -0,0 +1,25 @@ +local jid_split = require "util.jid".split; +local st = require "util.stanza"; +local set = require "util.set"; +local select = select; + +local blacklist = module:get_option_inherited_set("host_blacklist", {}); + +local function stanza_checker(attr) + return function (event) + local host = select(2, jid_split(stanza.attr[attr])); + if blacklist:contains(host) then + module:send(st.error_reply(event.stanza, "cancel", "not-allowed", "Communication with this domain is restricted")); + end + end +end + +check_incoming_stanza = stanza_checker("from"); +check_outgoing_stanza = stanza_checker("to"); + +for stanza_type in set.new{"presence","message","iq"}:items() do + for jid_type in set.new{"bare", "full", "host"}:items() do + module:hook("pre-"..stanza_type.."/"..jid_type, check_outgoing_stanza, 500); + module:hook(stanza_type.."/"..jid_type, check_incoming_stanza, 500); + end +end