annotate mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 49:59f490390528

mod_adhoc, mod_adhoc_cmd_admin: Check permissions in one place for all commands
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 17 Oct 2009 01:37:25 +0200
parents 7fbaf590dc12
children e839b4453387
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Copyright (C) 2009 Florian Zeitz
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 --
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 -- This file is MIT/X11 licensed. Please see the
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 --
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
7 local _G = _G;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
8
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
9 local prosody = _G.prosody;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
10 local hosts = prosody.hosts;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
11
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 local usermanager_user_exists = require "core.usermanager".user_exists;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 local usermanager_create_user = require "core.usermanager".create_user;
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
14 local is_admin = require "core.usermanager".is_admin;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
16 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
17 local dataforms_new = require "util.dataforms".new;
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
18 local adhoc_new = module:require "adhoc".new;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 local sessions = {};
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21
35
3c49411d4aa3 mod_adhoc_cmd_admin: Fixed style, some typos, and got down to <100LOC. Perhaps we need util.adhoc?
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
22 local add_user_layout = dataforms_new{
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 40
diff changeset
23 title = "Adding a User";
34
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
24 instructions = "Fill out this form to add a user.";
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
25
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
26 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
27 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
28 { name = "password", type = "text-private", label = "The password for this account" };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
29 { name = "password-verify", type = "text-private", label = "Retype password" };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
30 };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
31
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
32 local get_online_users_layout = dataforms_new{
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
33 title = "Getting List of Online Users";
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
34 instructions = "How many users should be returned at most?";
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
35
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
36 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
37 { name = "max_items", type = "list-single", label = "Maximum number of users",
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
38 value = { "25", "50", "75", "100", "150", "200", "all" } };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
39 };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
40
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
41 function add_user_command_handler(item, origin, stanza)
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 if stanza.tags[1].attr.action == "cancel" then
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
44 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 end
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
48 form = stanza.tags[1]:child_with_ns("jabber:x:data");
34
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
49 local fields = add_user_layout:data(form);
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50 local username, host, resource = jid.split(fields.accountjid);
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51 if (fields.password == fields["password-verify"]) and username and host and host == stanza.attr.to then
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52 if usermanager_user_exists(username, host) then
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 origin.send(st.error_reply(stanza, "cancel", "conflict", "Account already exists"):up()
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
54 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
55 :tag("note", {type="error"}):text("Account already exists")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
56 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
59 if usermanager_create_user(username, fields.password, host) then
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
60 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
61 :tag("note", {type="info"}):text("Account successfully created")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
62 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63 module:log("debug", "Created new account " .. username.."@"..host);
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
64 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
65 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 origin.send(st.error_reply(stanza, "wait", "internal-server-error",
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
67 "Failed to write data to disk"):up()
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
68 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
69 :tag("note", {type="error"}):text("Failed to write data to disk")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
72 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75 module:log("debug", fields.accountjid .. " " .. fields.password .. " " .. fields["password-verify"]);
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
76 origin.send(st.error_reply(stanza, "cancel", "conflict",
35
3c49411d4aa3 mod_adhoc_cmd_admin: Fixed style, some typos, and got down to <100LOC. Perhaps we need util.adhoc?
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
77 "Invalid data.\nPassword mismatch, or empty username"):up()
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
78 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
79 :tag("note", {type="error"}):text("Invalid data.\nPassword mismatch, or empty username")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
82 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
83 else
33
f3225c55288f mod_adhoc_cmd_admin: More utils.dataforms sugar
Florian Zeitz <florob@babelmonkeys.de>
parents: 32
diff changeset
84 local sessionid=uuid.generate();
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 sessions[sessionid] = "executing";
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
86 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(add_user_layout:form())));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
89 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
91 function get_online_users_command_handler(item, origin, stanza)
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
92 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
93 if stanza.tags[1].attr.action == "cancel" then
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
94 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
95 sessions[stanza.tags[1].attr.sessionid] = nil;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
96 return true;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
97 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
98
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
99 form = stanza.tags[1]:child_with_ns("jabber:x:data");
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
100 local fields = add_user_layout:data(form);
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
101
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
102 local max_items = nil
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
103 if fields.max_items ~= "all" then
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
104 max_items = tonumber(fields.max_items);
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
105 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
106 local count = 0;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
107 local field = st.stanza("field", {label="The list of all online users", var="onlineuserjids", type="text-multi"});
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
108 for username, user in pairs(hosts[stanza.attr.to].sessions or {}) do
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
109 if (max_items ~= nil) and (count >= max_items) then
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
110 break;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
111 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
112 field:tag("value"):text(username.."@"..stanza.attr.to):up();
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
113 count = count + 1;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
114 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
115 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
116 :tag("x", {xmlns="jabber:x:data", type="result"})
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
117 :tag("field", {type="hidden", var="FORM_TYPE"})
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
118 :tag("value"):text("http://jabber.org/protocol/admin"):up():up()
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
119 :add_child(field)));
48
7fbaf590dc12 mod_adhoc_cmd_admin: Fix session leak
Florian Zeitz <florob@babelmonkeys.de>
parents: 44
diff changeset
120 sessions[stanza.tags[1].attr.sessionid] = nil;
7fbaf590dc12 mod_adhoc_cmd_admin: Fix session leak
Florian Zeitz <florob@babelmonkeys.de>
parents: 44
diff changeset
121 return true;
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
122 else
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
123 local sessionid=uuid.generate();
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
124 sessions[sessionid] = "executing";
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
125 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(get_online_users_layout:form())));
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
126 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
127
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
128 return true;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
129 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
130
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 40
diff changeset
131 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 40
diff changeset
132 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 function module.unload()
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
135 module:remove_item("adhoc", add_user_desc);
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
136 module:remove_item("adhoc", get_online_users_desc);
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
139 module:add_item("adhoc", add_user_desc);
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
140 module:add_item("adhoc", get_online_users_desc);