49 |
49 |
50 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) |
50 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) |
51 local origin, stanza = event.origin, event.stanza; |
51 local origin, stanza = event.origin, event.stanza; |
52 if stanza.attr.type == "get" and stanza.tags[1].attr.node |
52 if stanza.attr.type == "get" and stanza.tags[1].attr.node |
53 and stanza.tags[1].attr.node == xmlns_cmd then |
53 and stanza.tags[1].attr.node == xmlns_cmd then |
54 local privileged = is_admin(stanza.attr.from, stanza.attr.to); |
54 local admin = is_admin(stanza.attr.from, stanza.attr.to); |
|
55 local global_admin = is_admin(stanza.attr.from); |
55 reply = st.reply(stanza); |
56 reply = st.reply(stanza); |
56 reply:tag("query", { xmlns = xmlns_disco.."#items", |
57 reply:tag("query", { xmlns = xmlns_disco.."#items", |
57 node = xmlns_cmd }); |
58 node = xmlns_cmd }); |
58 for node, command in pairs(commands) do |
59 for node, command in pairs(commands) do |
59 if (command.permission == "admin" and privileged) |
60 if (command.permission == "admin" and admin) |
|
61 or (command.permission == "global_admin" and global_admin) |
60 or (command.permission == "user") then |
62 or (command.permission == "user") then |
61 reply:tag("item", { name = command.name, |
63 reply:tag("item", { name = command.name, |
62 node = node, jid = module:get_host() }); |
64 node = node, jid = module:get_host() }); |
63 reply:up(); |
65 reply:up(); |
64 end |
66 end |
71 module:hook("iq/host/"..xmlns_cmd..":command", function (event) |
73 module:hook("iq/host/"..xmlns_cmd..":command", function (event) |
72 local origin, stanza = event.origin, event.stanza; |
74 local origin, stanza = event.origin, event.stanza; |
73 if stanza.attr.type == "set" then |
75 if stanza.attr.type == "set" then |
74 local node = stanza.tags[1].attr.node |
76 local node = stanza.tags[1].attr.node |
75 if commands[node] then |
77 if commands[node] then |
76 local privileged = is_admin(stanza.attr.from, stanza.attr.to); |
78 local admin = is_admin(stanza.attr.from, stanza.attr.to); |
77 if commands[node].permission == "admin" |
79 local global_admin = is_admin(stanza.attr.from); |
78 and not privileged then |
80 if (commands[node].permission == "admin" and not admin) |
|
81 or (commands[node].permission == "global_admin" and not global_admin) then |
79 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() |
82 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() |
80 :add_child(commands[node]:cmdtag("canceled") |
83 :add_child(commands[node]:cmdtag("canceled") |
81 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); |
84 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); |
82 return true |
85 return true |
83 end |
86 end |