equal
deleted
inserted
replaced
|
1 local jid_split = require "util.jid".split; |
|
2 local st = require "util.stanza"; |
|
3 local set = require "util.set"; |
|
4 local select = select; |
|
5 |
|
6 local blacklist = module:get_option_inherited_set("host_blacklist", {}); |
|
7 |
|
8 local function stanza_checker(attr) |
|
9 return function (event) |
|
10 local host = select(2, jid_split(stanza.attr[attr])); |
|
11 if blacklist:contains(host) then |
|
12 module:send(st.error_reply(event.stanza, "cancel", "not-allowed", "Communication with this domain is restricted")); |
|
13 end |
|
14 end |
|
15 end |
|
16 |
|
17 check_incoming_stanza = stanza_checker("from"); |
|
18 check_outgoing_stanza = stanza_checker("to"); |
|
19 |
|
20 for stanza_type in set.new{"presence","message","iq"}:items() do |
|
21 for jid_type in set.new{"bare", "full", "host"}:items() do |
|
22 module:hook("pre-"..stanza_type.."/"..jid_type, check_outgoing_stanza, 500); |
|
23 module:hook(stanza_type.."/"..jid_type, check_incoming_stanza, 500); |
|
24 end |
|
25 end |