comparison mod_adhoc/adhoc/mod_adhoc.lua @ 43:adc9eff8adb2

mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 16 Oct 2009 01:36:04 +0200
parents 58d326d86a9a
children 59f490390528
comparison
equal deleted inserted replaced
42:bbb3d3a90a70 43:adc9eff8adb2
3 -- This file is MIT/X11 licensed. Please see the 3 -- This file is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information. 4 -- COPYING file in the source package for more information.
5 -- 5 --
6 6
7 local st = require "util.stanza"; 7 local st = require "util.stanza";
8 local is_admin = require "core.usermanager".is_admin;
8 local commands = {}; 9 local commands = {};
9 10
10 module:add_feature("http://jabber.org/protocol/commands"); 11 module:add_feature("http://jabber.org/protocol/commands");
11 12
12 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function (event) 13 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function (event)
13 local origin, stanza = event.origin, event.stanza; 14 local origin, stanza = event.origin, event.stanza;
15 local privileged = is_admin(event.stanza.attr.from);
14 if stanza.attr.type == "get" and stanza.tags[1].attr.node and stanza.tags[1].attr.node == "http://jabber.org/protocol/commands" then 16 if stanza.attr.type == "get" and stanza.tags[1].attr.node and stanza.tags[1].attr.node == "http://jabber.org/protocol/commands" then
15 reply = st.reply(stanza); 17 reply = st.reply(stanza);
16 reply:tag("query", {xmlns="http://jabber.org/protocol/disco#items", node="http://jabber.org/protocol/commands"}) 18 reply:tag("query", {xmlns="http://jabber.org/protocol/disco#items", node="http://jabber.org/protocol/commands"})
17 for i = 1, #commands do 19 for i = 1, #commands do
18 -- module:log("info", "adding command %s", commands[i].name); 20 -- module:log("info", "adding command %s", commands[i].name);
19 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()}); 21 if (commands[i].permission == "admin" and privileged) or (commands[i].permission == "user") then
20 reply:up(); 22 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()});
23 reply:up();
24 end
21 end 25 end
22 origin.send(reply); 26 origin.send(reply);
23 return true; 27 return true;
24 end 28 end
25 end, 500); 29 end, 500);