annotate mod_adhoc/adhoc/mod_adhoc.lua @ 150:fd7f7ebf257e

mod_ircd: Fixed handling of empty <body/> elements.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 13 May 2010 14:45:10 +0500
parents 8111c8a9e1ad
children b3a68e71b8a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
1 -- Copyright (C) 2009 Thilo Cestonaro
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
2 --
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
3 -- This file is MIT/X11 licensed. Please see the
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
5 --
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
7 local st = require "util.stanza";
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
8 local is_admin = require "core.usermanager".is_admin;
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
9 local adhoc_handle_cmd = module:require "adhoc".handle_cmd;
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
10 local xmlns_cmd = "http://jabber.org/protocol/commands";
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
11 local xmlns_disco = "http://jabber.org/protocol/disco";
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
12 local commands = {};
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
13
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
14 module:add_feature(xmlns_cmd);
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
15
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
16 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event)
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
17 local origin, stanza = event.origin, event.stanza;
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
18 -- TODO: Is this correct, or should is_admin be changed?
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
19 local privileged = is_admin(stanza.attr.from)
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
20 or is_admin(stanza.attr.from, stanza.attr.to);
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
21 if stanza.attr.type == "get" and stanza.tags[1].attr.node
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
22 and stanza.tags[1].attr.node == xmlns_cmd then
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
23 reply = st.reply(stanza);
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
24 reply:tag("query", { xmlns = xmlns_disco.."#items",
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
25 node = xmlns_cmd });
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
26 for node, command in pairs(commands) do
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
27 if (command.permission == "admin" and privileged)
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
28 or (command.permission == "user") then
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
29 reply:tag("item", { name = command.name,
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
30 node = node, jid = module:get_host() });
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
31 reply:up();
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
32 end
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
33 end
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
34 origin.send(reply);
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
35 return true;
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
36 end
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
37 end, 500);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
38
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
39 module:hook("iq/host", function (event)
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
40 local origin, stanza = event.origin, event.stanza;
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
41 if stanza.attr.type == "set" and stanza.tags[1]
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
42 and stanza.tags[1].name == "command" then
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
43 local node = stanza.tags[1].attr.node
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
44 -- TODO: Is this correct, or should is_admin be changed?
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
45 local privileged = is_admin(event.stanza.attr.from)
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
46 or is_admin(stanza.attr.from, stanza.attr.to);
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
47 if commands[node] then
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
48 if commands[node].permission == "admin"
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
49 and not privileged then
93
611d16867410 mod_adhoc: Check for global and host admins
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
50 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up()
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
51 :add_child(commands[node]:cmdtag("canceled")
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
52 :tag("note", {type="error"}):text("You don't have permission to execute this command")));
93
611d16867410 mod_adhoc: Check for global and host admins
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
53 return true
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
54 end
93
611d16867410 mod_adhoc: Check for global and host admins
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
55 -- User has permission now execute the command
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
56 return adhoc_handle_cmd(commands[node], origin, stanza);
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
57 end
93
611d16867410 mod_adhoc: Check for global and host admins
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
58 end
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
59 end, 500);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
60
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
61 module:hook("item-added/adhoc", function (event)
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
62 commands[event.item.node] = event.item;
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
63 end, 500);
9
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
64
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
65 module:hook("item-removed/adhoc", function (event)
125
8111c8a9e1ad mod_adhoc: Use hashtable instead of array, coding style
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
66 commands[event.item.node] = nil;
9
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
67 end, 500);