comparison mod_adhoc/adhoc/mod_adhoc.lua @ 93:611d16867410

mod_adhoc: Check for global and host admins
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 14 Nov 2009 18:44:54 +0100
parents 59f490390528
children 9b63fd1196c0
comparison
equal deleted inserted replaced
92:7dad958aad15 93:611d16867410
10 10
11 module:add_feature("http://jabber.org/protocol/commands"); 11 module:add_feature("http://jabber.org/protocol/commands");
12 12
13 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)
14 local origin, stanza = event.origin, event.stanza; 14 local origin, stanza = event.origin, event.stanza;
15 local privileged = is_admin(event.stanza.attr.from); 15 local privileged = is_admin(event.stanza.attr.from) or is_admin(stanza.attr.from, stanza.attr.to); -- TODO: Is this correct, or should is_admin be changed?
16 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
17 reply = st.reply(stanza); 17 reply = st.reply(stanza);
18 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"})
19 for i = 1, #commands do 19 for i = 1, #commands do
20 -- module:log("info", "adding command %s", commands[i].name); 20 -- module:log("info", "adding command %s", commands[i].name);
30 30
31 module:hook("iq/host", function (event) 31 module:hook("iq/host", function (event)
32 local origin, stanza = event.origin, event.stanza; 32 local origin, stanza = event.origin, event.stanza;
33 if stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "command" then 33 if stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "command" then
34 local node = stanza.tags[1].attr.node 34 local node = stanza.tags[1].attr.node
35 for i = 1, #commands do 35 local privileged = is_admin(event.stanza.attr.from) or is_admin(stanza.attr.from, stanza.attr.to); -- TODO: Is this correct, or should is_admin be changed?
36 if commands[i].node == node then 36 for i = 1, #commands do
37 -- check whether user has permission to execute this command first 37 if commands[i].node == node then
38 if commands[i].permission == "admin" and not is_admin(stanza.attr.from) then 38 -- check whether user has permission to execute this command first
39 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() 39 if commands[i].permission == "admin" and not privileged then
40 :add_child(commands[i]:cmdtag("canceled") 40 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up()
41 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); 41 :add_child(commands[i]:cmdtag("canceled")
42 return true 42 :tag("note", {type="error"}):text("You don't have permission to execute this command")));
43 end 43 return true
44 -- User has permission now execute the command
45 return commands[i].handler(commands[i], origin, stanza);
46 end 44 end
45 -- User has permission now execute the command
46 return commands[i].handler(commands[i], origin, stanza);
47 end 47 end
48 end
48 end 49 end
49 end, 500); 50 end, 500);
50 51
51 module:hook("item-added/adhoc", function (event) 52 module:hook("item-added/adhoc", function (event)
52 commands[ # commands + 1] = event.item; 53 commands[ # commands + 1] = event.item;