Annotate

mod_block_outgoing/mod_block_outgoing.lua @ 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
child 2005:c769ed3e5b2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2004
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Module to block all outgoing stanzas from a list of users
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local block_users = module:get_option_set("block_outgoing_users", {});
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local block_all = block_users:empty();
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local stanza_types = { "iq", "presence", "message" };
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local jid_types = { "host", "bare", "full" };
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function block_stanza(event)
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local stanza = event.stanza;
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 if stanza.attr.to == nil then
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 return;
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 if block_all or block_users:contains(jid_bare(stanza.attr.from)) then
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 module:log("debug", "Blocked outgoing %s stanza from %s", stanza.name, stanza.attr.from);
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 return true;
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 function module.load()
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 for _, stanza_type in ipairs(stanza_types) do
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 for _, jid_type in ipairs(jid_types) do
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 module:hook("pre-"..stanza_type.."/"..jid_type, block_stanza, 10000);
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end