Mercurial > prosody-modules
changeset 2004:41fd55eba4a8
mod_block_outgoing: Module to block outgoing stanzas from users
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 13 Jan 2016 14:26:44 +0000 |
parents | 8ccf347c7753 |
children | c769ed3e5b2b |
files | mod_block_outgoing/mod_block_outgoing.lua |
diffstat | 1 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_block_outgoing/mod_block_outgoing.lua Wed Jan 13 14:26:44 2016 +0000 @@ -0,0 +1,28 @@ +-- Module to block all outgoing stanzas from a list of users + +local jid_bare = require "util.jid".bare; + +local block_users = module:get_option_set("block_outgoing_users", {}); +local block_all = block_users:empty(); + +local stanza_types = { "iq", "presence", "message" }; +local jid_types = { "host", "bare", "full" }; + +local function block_stanza(event) + local stanza = event.stanza; + if stanza.attr.to == nil then + return; + end + if block_all or block_users:contains(jid_bare(stanza.attr.from)) then + module:log("debug", "Blocked outgoing %s stanza from %s", stanza.name, stanza.attr.from); + return true; + end +end + +function module.load() + for _, stanza_type in ipairs(stanza_types) do + for _, jid_type in ipairs(jid_types) do + module:hook("pre-"..stanza_type.."/"..jid_type, block_stanza, 10000); + end + end +end