Mercurial > prosody-modules
comparison mod_adhoc/adhoc/mod_adhoc.lua @ 244:e0802b2716c3
mod_adhoc: Code restructuring
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Sat, 21 Aug 2010 19:20:12 +0200 |
parents | 1ae653712e37 |
children | 84d03c44bdb9 |
comparison
equal
deleted
inserted
replaced
243:6202ce4d12d6 | 244:e0802b2716c3 |
---|---|
14 | 14 |
15 module:add_feature(xmlns_cmd); | 15 module:add_feature(xmlns_cmd); |
16 | 16 |
17 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) | 17 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) |
18 local origin, stanza = event.origin, event.stanza; | 18 local origin, stanza = event.origin, event.stanza; |
19 -- Required for Prosody <= 0.7 | |
20 local privileged = is_admin(stanza.attr.from) | |
21 or is_admin(stanza.attr.from, stanza.attr.to); | |
22 if stanza.attr.type == "get" and stanza.tags[1].attr.node | 19 if stanza.attr.type == "get" and stanza.tags[1].attr.node |
23 and stanza.tags[1].attr.node == xmlns_cmd then | 20 and stanza.tags[1].attr.node == xmlns_cmd then |
21 -- Required for Prosody <= 0.7 | |
22 local privileged = is_admin(stanza.attr.from) | |
23 or is_admin(stanza.attr.from, stanza.attr.to); | |
24 reply = st.reply(stanza); | 24 reply = st.reply(stanza); |
25 reply:tag("query", { xmlns = xmlns_disco.."#items", | 25 reply:tag("query", { xmlns = xmlns_disco.."#items", |
26 node = xmlns_cmd }); | 26 node = xmlns_cmd }); |
27 for node, command in pairs(commands) do | 27 for node, command in pairs(commands) do |
28 if (command.permission == "admin" and privileged) | 28 if (command.permission == "admin" and privileged) |
35 origin.send(reply); | 35 origin.send(reply); |
36 return true; | 36 return true; |
37 end | 37 end |
38 end, 500); | 38 end, 500); |
39 | 39 |
40 module:hook("iq/host", function (event) | 40 module:hook("iq/host"..xmlns_cmd..":command", function (event) |
41 local origin, stanza = event.origin, event.stanza; | 41 local origin, stanza = event.origin, event.stanza; |
42 if stanza.attr.type == "set" and stanza.tags[1] | 42 if stanza.attr.type == "set" then |
43 and stanza.tags[1].name == "command" then | |
44 local node = stanza.tags[1].attr.node | 43 local node = stanza.tags[1].attr.node |
45 -- Required for Prosody <= 0.7 | |
46 local privileged = is_admin(event.stanza.attr.from) | |
47 or is_admin(stanza.attr.from, stanza.attr.to); | |
48 if commands[node] then | 44 if commands[node] then |
45 -- Required for Prosody <= 0.7 | |
46 local privileged = is_admin(event.stanza.attr.from) | |
47 or is_admin(stanza.attr.from, stanza.attr.to); | |
49 if commands[node].permission == "admin" | 48 if commands[node].permission == "admin" |
50 and not privileged then | 49 and not privileged then |
51 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() | 50 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() |
52 :add_child(commands[node]:cmdtag("canceled") | 51 :add_child(commands[node]:cmdtag("canceled") |
53 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); | 52 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); |