comparison mod_admin_probe/mod_admin_probe.lua @ 1281:f78661861e98

mod_admin_probe: Module allowing server administrators to probe any user
author Florian Zeitz <florob@babelmonkeys.de>
date Mon, 20 Jan 2014 16:07:00 +0100
parents
children
comparison
equal deleted inserted replaced
1280:42625801d15a 1281:f78661861e98
1 -- Prosody IM
2 -- Copyright (C) 2014 Florian Zeitz
3 --
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
6 --
7
8 local presence = module:depends("presence");
9 local send_presence_of_available_resources = presence.send_presence_of_available_resources;
10
11 local hosts = prosody.hosts;
12 local core_post_stanza = prosody.core_post_stanza;
13
14 local st = require "util.stanza";
15 local is_admin = require "core.usermanager".is_admin;
16 local jid_split = require "util.jid".split;
17
18 module:hook("presence/bare", function(data)
19 local origin, stanza = data.origin, data.stanza;
20 local to, from, type = stanza.attr.to, stanza.attr.from, stanza.attr.type;
21 local node, host = jid_split(to);
22
23 if type ~= "probe" then return; end
24 if not is_admin(from, module.host) then return; end
25
26 if 0 == send_presence_of_available_resources(node, host, from, origin) then
27 core_post_stanza(hosts[host], st.presence({from=to, to=from, type="unavailable"}), true);
28 end
29 return true;
30 end, 10);