Mercurial > prosody-modules
comparison mod_block_outgoing/mod_block_outgoing.lua @ 2005:c769ed3e5b2b
mod_block_outgoing: Make admins exempt from restrictions
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 13 Jan 2016 14:56:19 +0000 |
parents | 41fd55eba4a8 |
children | cb810a2bca47 |
comparison
equal
deleted
inserted
replaced
2004:41fd55eba4a8 | 2005:c769ed3e5b2b |
---|---|
1 -- Module to block all outgoing stanzas from a list of users | 1 -- Module to block all outgoing stanzas from a list of users |
2 | 2 |
3 local jid_bare = require "util.jid".bare; | 3 local jid_bare = require "util.jid".bare; |
4 local is_admin = require "core.usermanager".is_admin; | |
4 | 5 |
5 local block_users = module:get_option_set("block_outgoing_users", {}); | 6 local block_users = module:get_option_set("block_outgoing_users", {}); |
6 local block_all = block_users:empty(); | 7 local block_all = block_users:empty(); |
7 | 8 |
8 local stanza_types = { "iq", "presence", "message" }; | 9 local stanza_types = { "iq", "presence", "message" }; |
9 local jid_types = { "host", "bare", "full" }; | 10 local jid_types = { "host", "bare", "full" }; |
10 | 11 |
11 local function block_stanza(event) | 12 local function block_stanza(event) |
12 local stanza = event.stanza; | 13 local stanza = event.stanza; |
13 if stanza.attr.to == nil then | 14 local from_jid = jid_bare(stanza.attr.from); |
15 if stanza.attr.to == nil or is_admin(from_jid, module.host) then | |
14 return; | 16 return; |
15 end | 17 end |
16 if block_all or block_users:contains(jid_bare(stanza.attr.from)) then | 18 if block_all or block_users:contains(from_jid) then |
17 module:log("debug", "Blocked outgoing %s stanza from %s", stanza.name, stanza.attr.from); | 19 module:log("debug", "Blocked outgoing %s stanza from %s", stanza.name, stanza.attr.from); |
18 return true; | 20 return true; |
19 end | 21 end |
20 end | 22 end |
21 | 23 |