Software / code / prosody
Comparison
plugins/adhoc/mod_adhoc.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parent | 10565:421b2f8369fd |
| child | 11209:f6661fac7e9a |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 6 -- | 6 -- |
| 7 | 7 |
| 8 local it = require "util.iterators"; | 8 local it = require "util.iterators"; |
| 9 local st = require "util.stanza"; | 9 local st = require "util.stanza"; |
| 10 local is_admin = require "core.usermanager".is_admin; | 10 local is_admin = require "core.usermanager".is_admin; |
| 11 local jid_split = require "util.jid".split; | 11 local jid_host = require "util.jid".host; |
| 12 local adhoc_handle_cmd = module:require "adhoc".handle_cmd; | 12 local adhoc_handle_cmd = module:require "adhoc".handle_cmd; |
| 13 local xmlns_cmd = "http://jabber.org/protocol/commands"; | 13 local xmlns_cmd = "http://jabber.org/protocol/commands"; |
| 14 local commands = {}; | 14 local commands = {}; |
| 15 | 15 |
| 16 module:add_feature(xmlns_cmd); | 16 module:add_feature(xmlns_cmd); |
| 19 local stanza, origin, reply, node = event.stanza, event.origin, event.reply, event.node; | 19 local stanza, origin, reply, node = event.stanza, event.origin, event.reply, event.node; |
| 20 if commands[node] then | 20 if commands[node] then |
| 21 local from = stanza.attr.from; | 21 local from = stanza.attr.from; |
| 22 local privileged = is_admin(from, stanza.attr.to); | 22 local privileged = is_admin(from, stanza.attr.to); |
| 23 local global_admin = is_admin(from); | 23 local global_admin = is_admin(from); |
| 24 local username, hostname = jid_split(from); | 24 local hostname = jid_host(from); |
| 25 local command = commands[node]; | 25 local command = commands[node]; |
| 26 if (command.permission == "admin" and privileged) | 26 if (command.permission == "admin" and privileged) |
| 27 or (command.permission == "global_admin" and global_admin) | 27 or (command.permission == "global_admin" and global_admin) |
| 28 or (command.permission == "local_user" and hostname == module.host) | 28 or (command.permission == "local_user" and hostname == module.host) |
| 29 or (command.permission == "user") then | 29 or (command.permission == "any") then |
| 30 reply:tag("identity", { name = command.name, | 30 reply:tag("identity", { name = command.name, |
| 31 category = "automation", type = "command-node" }):up(); | 31 category = "automation", type = "command-node" }):up(); |
| 32 reply:tag("feature", { var = xmlns_cmd }):up(); | 32 reply:tag("feature", { var = xmlns_cmd }):up(); |
| 33 reply:tag("feature", { var = "jabber:x:data" }):up(); | 33 reply:tag("feature", { var = "jabber:x:data" }):up(); |
| 34 event.exists = true; | 34 event.exists = true; |
| 50 end | 50 end |
| 51 | 51 |
| 52 local from = stanza.attr.from; | 52 local from = stanza.attr.from; |
| 53 local admin = is_admin(from, stanza.attr.to); | 53 local admin = is_admin(from, stanza.attr.to); |
| 54 local global_admin = is_admin(from); | 54 local global_admin = is_admin(from); |
| 55 local username, hostname = jid_split(from); | 55 local hostname = jid_host(from); |
| 56 for node, command in it.sorted_pairs(commands) do | 56 for node, command in it.sorted_pairs(commands) do |
| 57 if (command.permission == "admin" and admin) | 57 if (command.permission == "admin" and admin) |
| 58 or (command.permission == "global_admin" and global_admin) | 58 or (command.permission == "global_admin" and global_admin) |
| 59 or (command.permission == "local_user" and hostname == module.host) | 59 or (command.permission == "local_user" and hostname == module.host) |
| 60 or (command.permission == "user") then | 60 or (command.permission == "any") then |
| 61 reply:tag("item", { name = command.name, | 61 reply:tag("item", { name = command.name, |
| 62 node = node, jid = module:get_host() }); | 62 node = node, jid = module:get_host() }); |
| 63 reply:up(); | 63 reply:up(); |
| 64 end | 64 end |
| 65 end | 65 end |
| 72 local command = commands[node]; | 72 local command = commands[node]; |
| 73 if command then | 73 if command then |
| 74 local from = stanza.attr.from; | 74 local from = stanza.attr.from; |
| 75 local admin = is_admin(from, stanza.attr.to); | 75 local admin = is_admin(from, stanza.attr.to); |
| 76 local global_admin = is_admin(from); | 76 local global_admin = is_admin(from); |
| 77 local username, hostname = jid_split(from); | 77 local hostname = jid_host(from); |
| 78 if (command.permission == "admin" and not admin) | 78 if (command.permission == "admin" and not admin) |
| 79 or (command.permission == "global_admin" and not global_admin) | 79 or (command.permission == "global_admin" and not global_admin) |
| 80 or (command.permission == "local_user" and hostname ~= module.host) then | 80 or (command.permission == "local_user" and hostname ~= module.host) then |
| 81 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() | 81 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() |
| 82 :add_child(commands[node]:cmdtag("canceled") | 82 :add_child(commands[node]:cmdtag("canceled") |