Comparison

mod_adhoc/adhoc/mod_adhoc.lua @ 49:59f490390528

mod_adhoc, mod_adhoc_cmd_admin: Check permissions in one place for all commands
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 17 Oct 2009 01:37:25 +0200
parent 43:adc9eff8adb2
child 93:611d16867410
comparison
equal deleted inserted replaced
48:7fbaf590dc12 49:59f490390528
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 for i = 1, #commands do
36 if commands[i].node == node then 36 if commands[i].node == node then
37 -- check whether user has permission to execute this command first
38 if commands[i].permission == "admin" and not is_admin(stanza.attr.from) then
39 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up()
40 :add_child(commands[i]:cmdtag("canceled")
41 :tag("note", {type="error"}):text("You don't have permission to execute this command")));
42 return true
43 end
44 -- User has permission now execute the command
37 return commands[i].handler(commands[i], origin, stanza); 45 return commands[i].handler(commands[i], origin, stanza);
38 end 46 end
39 end 47 end
40 end 48 end
41 end, 500); 49 end, 500);