annotate mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 123:c04443ea114c

mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 22 Jan 2010 19:05:28 +0100
parents a9898f13c89e
children 843cadf36306
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
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
12 local t_concat = table.concat;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
13
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local usermanager_user_exists = require "core.usermanager".user_exists;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
15 local usermanager_get_password = require "core.usermanager".get_password;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 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
17 local is_admin = require "core.usermanager".is_admin;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18
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
19 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
20 local dataforms_new = require "util.dataforms".new;
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
21 module:log("debug", module:get_name());
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
22 local adhoc_new = module:require "adhoc".new;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 local sessions = {};
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25
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
26 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
27 title = "Adding a User";
34
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
28 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
29
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
30 { 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
31 { 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
32 { 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
33 { 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
34 };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
35
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
36 local change_user_password_layout = dataforms_new{
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
37 title = "Changing a User Password";
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
38 instructions = "Fill out this form to change a user's password.";
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
39
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
40 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
41 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for this account" };
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
42 { name = "password", type = "text-private", required = true, label = "The password for this account" };
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
43 };
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
44
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
45 local delete_user_layout = dataforms_new{
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
46 title = "Deleting a User";
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
47 instructions = "Fill out this form to delete a user.";
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
48
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
49 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
50 { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) to delete" };
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
51 };
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
52
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
53 local get_user_password_layout = dataforms_new{
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
54 title = "Getting User's Password";
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
55 instructions = "Fill out this form to get a user's password.";
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
56
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
57 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
58 { name = "accountjid", type = "jid-single", label = "The Jabber ID for which to retrieve the password" };
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
59 };
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
60
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
61 local get_user_password_result_layout = dataforms_new{
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
62 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
63 { name = "accountjid", type = "jid-single", label = "JID" };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
64 { name = "password", type = "text-single", label = "Password" };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
65 };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
66
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
67 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
68 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
69 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
70
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
71 { 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
72 { 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
73 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
74 };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
75
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
76 local get_online_users_result_layout = dataforms_new{
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
77 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
78 { name = "onlineuserjids", type = "text-multi", label = "The list of all online users" };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
79 };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
80
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
81 local announce_layout = dataforms_new{
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
82 title = "Making an Announcement";
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
83 instructions = "Fill out this form to make an announcement to all\nactive users of this service.";
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
84
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
85 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
86 { name = "subject", type = "text-single", label = "Subject" };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
87 { name = "announcement", type = "text-multi", required = true, label = "Announcement" };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
88 };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
89
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
90 function add_user_command_handler(self, data, sessid)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
91 if sessid and sessions[sessid] then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
92 if data.action == "cancel" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
93 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
94 return { status = "canceled" }, sessid;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
96 local fields = add_user_layout:data(data.form);
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97 local username, host, resource = jid.split(fields.accountjid);
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
98 if (fields["password"] == fields["password-verify"]) and username and host and host == data.to then
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 if usermanager_user_exists(username, host) then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
100 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
101 return { status = "error", error = { type = "cancel", condition = "conflict", message = "Account already exists" } }, sessid;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 if usermanager_create_user(username, fields.password, host) then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
104 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
105 module:log("info", "Created new account " .. username.."@"..host);
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
106 return { status = "completed", info = "Account successfully created" }, sessid;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 else
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
108 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
109 return { status = "error", error = { type = "wait", condition = "internal-server-error",
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
110 message = "Failed to write data to disk" } }, sessid;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 module:log("debug", fields.accountjid .. " " .. fields.password .. " " .. fields["password-verify"]);
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
115 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
116 return { status = "error", error = { type = "cancel", condition = "conflict",
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
117 message = "Invalid data.\nPassword mismatch, or empty username" } }, sessid;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 else
33
f3225c55288f mod_adhoc_cmd_admin: More utils.dataforms sugar
Florian Zeitz <florob@babelmonkeys.de>
parents: 32
diff changeset
120 local sessionid=uuid.generate();
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121 sessions[sessionid] = "executing";
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
122 return { status = "executing", form = add_user_layout }, sessionid;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
126 function change_user_password_command_handler(self, data, sessid)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
127 if sessid and sessions[sessid] then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
128 if data.action == "cancel" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
129 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
130 return { status = "canceled" }, sessid;
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
131 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
132 local fields = change_user_password_layout:data(data.form);
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
133 local username, host, resource = jid.split(fields.accountjid);
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
134 if usermanager_user_exists(username, host) and usermanager_create_user(username, fields.password, host) then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
135 return { status = "completed", info = "Password successfully changed" }, sessid;
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
136 else
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
137 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
138 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } }, sessid;
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
139 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
140 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
141 return { status = "canceled" }, sessid;
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
142 else
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
143 local sessionid=uuid.generate();
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
144 sessions[sessionid] = "executing";
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
145 return { status = "executing", form = change_user_password_layout }, sessionid;
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
146 end
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
147 end
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
148
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
149 function delete_user_command_handler(self, data, sessid)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
150 if sessid and sessions[sessid] then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
151 if data.action == "cancel" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
152 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
153 return { status = "canceled" }, sessid;
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
154 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
155 local fields = delete_user_layout:data(data.form);
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
156 local failed = {};
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
157 local succeeded = {};
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
158 for _, aJID in ipairs(fields.accountjids) do
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
159 local username, host, resource = jid.split(aJID);
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
160 if usermanager_user_exists(username, host) and usermanager_create_user(username, nil, host) then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
161 module:log("debug", "User " .. aJID .. " has been deleted");
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
162 succeeded[#succeeded+1] = aJID;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
163 else
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
164 module:log("debug", "Tried to delete non-existant user "..aJID);
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
165 failed[#failed+1] = aJID;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
166 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
167 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
168 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
169 return {status = "completed", info = (#succeeded ~= 0 and
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
170 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "")..
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
171 (#failed ~= 0 and
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
172 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") }, sessid;
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
173 else
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
174 local sessionid=uuid.generate();
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
175 sessions[sessionid] = "executing";
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
176 return { status = "executing", form = delete_user_layout }, sessionid;
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
177 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
178 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
179
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
180 function get_user_password_handler(self, data, sessid)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
181 if sessid and sessions[sessid] then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
182 if data.action == "cancel" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
183 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
184 return { status = "canceled" }, sessid;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
185 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
186 local fields = get_user_password_layout:data(data.form);
97
e172f02726d9 mod_adhoc_cmd_admin: Fix global access
Florian Zeitz <florob@babelmonkeys.de>
parents: 92
diff changeset
187 local user, host, resource = jid.split(fields.accountjid);
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
188 local accountjid = "";
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
189 local password = "";
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
190 if usermanager_user_exists(user, host) then
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
191 accountjid = fields.accountjid;
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
192 password = usermanager_get_password(user, host);
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
193 else
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
194 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
195 return { status = "error", error = { type = "cancel", condition = "item-not-found", message = "User does not exist" } }, sessid;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
196 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
197 sessions[sessid] = nil;
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
198 return { status = "completed", result = { layout = get_user_password_result_layout, data = {accountjid = accountjid, password = password} } }, sessid;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
199 else
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
200 local sessionid=uuid.generate();
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
201 sessions[sessionid] = "executing";
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
202 return { status = "executing", form = get_user_password_layout }, sessionid;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
203 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
204 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
205
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
206 function get_online_users_command_handler(self, data, sessid)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
207 if sessid and sessions[sessid] then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
208 if data.action == "cancel" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
209 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
210 return { status = "canceled" }, sessid;
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
211 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
212
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
213 local fields = add_user_layout:data(data.form);
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
214
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
215 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
216 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
217 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
218 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
219 local count = 0;
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
220 local users = nil;
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
221 for username, user in pairs(hosts[data.to].sessions or {}) do
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
222 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
223 break;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
224 end
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
225 users = ((users and users.."\n") or "")..(username.."@"..data.to);
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
226 count = count + 1;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
227 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
228 sessions[sessid] = nil;
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
229 return { status = "completed", result = {layout = get_online_users_result_layout, data = {onlineuserjids=users}} }, sessid;
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
230 else
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
231 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
232 sessions[sessionid] = "executing";
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
233 return { status = "executing", form = get_online_users_layout }, sessionid;
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
234 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
235 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
236
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
237 function announce_handler(self, data, sessid)
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
238 if sessid and sessions[sessid] then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
239 if data.action == "cancel" then
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
240 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
241 return { status = "canceled" }, sessid;
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
242 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
243
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
244 local fields = announce_layout:data(data.form);
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
245
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
246 module:log("info", "Sending server announcement to all online users");
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
247 local host_session = hosts[data.to];
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
248 local message = st.message({type = "headline", from = data.to}, fields.announcement):up()
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
249 :tag("subject"):text(fields.subject or "Announcement");
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
250
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
251 local c = 0;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
252 for user in pairs(host_session.sessions) do
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
253 c = c + 1;
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
254 message.attr.to = user.."@"..data.to;
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
255 core_post_stanza(host_session, message);
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
256 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
257
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
258 module:log("info", "Announcement sent to %d online users", c);
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
259 sessions[sessid] = nil;
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
260 return { status = "completed", info = "Announcement sent." }, sessid;
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
261 else
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
262 local sessionid=uuid.generate();
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
263 sessions[sessionid] = "executing";
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
264 return { status = "executing", form = announce_layout }, sessionid;
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
265 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
266
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
267 return true;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
268 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
269
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
270 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
271 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
272 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
273 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
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
274 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");
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
275 local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin");
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
276
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
277 module:add_item("adhoc", add_user_desc);
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
278 module:add_item("adhoc", change_user_password_desc);
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
279 module:add_item("adhoc", delete_user_desc);
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
280 module:add_item("adhoc", get_user_password_desc);
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
281 module:add_item("adhoc", get_online_users_desc);
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
282 module:add_item("adhoc", announce_desc);