11 local xmlns_cmd = "http://jabber.org/protocol/commands"; |
11 local xmlns_cmd = "http://jabber.org/protocol/commands"; |
12 local xmlns_disco = "http://jabber.org/protocol/disco"; |
12 local xmlns_disco = "http://jabber.org/protocol/disco"; |
13 local commands = {}; |
13 local commands = {}; |
14 |
14 |
15 module:add_feature(xmlns_cmd); |
15 module:add_feature(xmlns_cmd); |
|
16 |
|
17 module:hook("iq/host/"..xmlns_disco.."#info:query", function (event) |
|
18 local origin, stanza = event.origin, event.stanza; |
|
19 local node = stanza.tags[1].attr.node; |
|
20 if stanza.attr.type == "get" and node |
|
21 and commands[node] then |
|
22 -- Required for Prosody <= 0.7 |
|
23 local privileged = is_admin(stanza.attr.from) |
|
24 or is_admin(stanza.attr.from, stanza.attr.to); |
|
25 if (commands[node].permission == "admin" and privileged) |
|
26 or (commands[node].permission == "user") then |
|
27 reply = st.reply(stanza); |
|
28 reply:tag("query", { xmlns = xmlns_disco.."#info", |
|
29 node = node }); |
|
30 reply:tag("identity", { name = commands[node].name, |
|
31 category = "automation", type = "command-node" }):up(); |
|
32 reply:tag("feature", { var = xmlns_cmd }):up(); |
|
33 reply:tag("feature", { var = "jabber:x:data" }):up(); |
|
34 else |
|
35 reply = st.error_reply(stanza, "auth", "forbidden", "This item is not available to you"); |
|
36 end |
|
37 origin.send(reply); |
|
38 return true; |
|
39 end |
|
40 end); |
16 |
41 |
17 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) |
42 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) |
18 local origin, stanza = event.origin, event.stanza; |
43 local origin, stanza = event.origin, event.stanza; |
19 if stanza.attr.type == "get" and stanza.tags[1].attr.node |
44 if stanza.attr.type == "get" and stanza.tags[1].attr.node |
20 and stanza.tags[1].attr.node == xmlns_cmd then |
45 and stanza.tags[1].attr.node == xmlns_cmd then |