Annotate

mod_block_outgoing/mod_block_outgoing.lua @ 2006:cb810a2bca47

mod_block_outgoing: Allow stanzas to user's login host (e.g. disco queries)
author Matthew Wild <mwild1@gmail.com>
date Wed, 13 Jan 2016 16:10:27 +0000
parent 2005:c769ed3e5b2b
child 2007:dc1299ca0185
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;
2005
c769ed3e5b2b mod_block_outgoing: Make admins exempt from restrictions
Matthew Wild <mwild1@gmail.com>
parents: 2004
diff changeset
4 local is_admin = require "core.usermanager".is_admin;
2004
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 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
7 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
8
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 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
10 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
11
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local function block_stanza(event)
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local stanza = event.stanza;
2005
c769ed3e5b2b mod_block_outgoing: Make admins exempt from restrictions
Matthew Wild <mwild1@gmail.com>
parents: 2004
diff changeset
14 local from_jid = jid_bare(stanza.attr.from);
2006
cb810a2bca47 mod_block_outgoing: Allow stanzas to user's login host (e.g. disco queries)
Matthew Wild <mwild1@gmail.com>
parents: 2005
diff changeset
15 if stanza.attr.to == nil or stanza.attr.to == module.host or is_admin(from_jid, module.host) then
2004
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 return;
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
2005
c769ed3e5b2b mod_block_outgoing: Make admins exempt from restrictions
Matthew Wild <mwild1@gmail.com>
parents: 2004
diff changeset
18 if block_all or block_users:contains(from_jid) then
2004
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 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
20 return true;
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 function module.load()
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 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
26 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
27 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
28 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end
41fd55eba4a8 mod_block_outgoing: Module to block outgoing stanzas from users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end