Annotate

mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 600:03be4622454f

mod_stanza_counter_http: de-revert to use configmanager instead of module mm for the cleanup function also give it an unique name (mismatch possible "??")
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 09 Feb 2012 00:52:18 +0000
parent 251:d36160f4961f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
1 -- Copyright (C) 2009-2010 Florian Zeitz
29
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;
145
890140ade4e5 mod_adhoc_cmd_admin: Use new set_password function if available
Florian Zeitz <florob@babelmonkeys.de>
parents: 144
diff changeset
15 local usermanager_create_user = require "core.usermanager".create_user;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
16 local usermanager_get_password = require "core.usermanager".get_password;
145
890140ade4e5 mod_adhoc_cmd_admin: Use new set_password function if available
Florian Zeitz <florob@babelmonkeys.de>
parents: 144
diff changeset
17 local usermanager_set_password = require "core.usermanager".set_password or
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
18 function (username, password, host) return usermanager_create_user(username, password, host) 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
19 local is_admin = require "core.usermanager".is_admin;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
21 local rm_load_roster = require "core.rostermanager".load_roster;
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
22
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
23 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
24 local timer_add_task = require "util.timer".add_task;
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
25 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
26 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
27 local adhoc_new = module:require "adhoc".new;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28
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
29 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
30 title = "Adding a User";
34
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
31 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
32
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
33 { 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
34 { 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
35 { 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
36 { 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
37 };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
38
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
39 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
40 title = "Changing a User Password";
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
41 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
42
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
43 { 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
44 { 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
45 { 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
46 };
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
47
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
48 local delete_user_layout = dataforms_new{
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
49 title = "Deleting a User";
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
50 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
51
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
52 { 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
53 { 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
54 };
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
55
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
56 local end_user_session_layout = dataforms_new{
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
57 title = "Ending a User Session";
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
58 instructions = "Fill out this form to end a user's session.";
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
59
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
60 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
61 { name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions" };
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
62 };
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
63
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
64 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
65 title = "Getting User's Password";
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
66 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
67
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
68 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
69 { name = "accountjid", type = "jid-single", required = true, 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
70 };
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
71
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
72 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
73 { 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
74 { 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
75 { 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
76 };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
77
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
78 local get_user_roster_layout = dataforms_new{
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
79 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
80 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the roster" };
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
81 };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
82
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
83 local get_user_roster_result_layout = dataforms_new{
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
84 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
85 { name = "accountjid", type = "jid-single", label = "This is the roster for" };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
86 { name = "roster", type = "text-multi", label = "Roster XML" };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
87 };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
88
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
89 local get_user_stats_layout = dataforms_new{
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
90 title = "Get User Statistics";
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
91 instructions = "Fill out this form to gather user statistics.";
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
92
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
93 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
94 { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for statistics" };
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
95 };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
96
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
97 local get_user_stats_result_layout = dataforms_new{
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
98 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
99 { name = "ipaddresses", type = "text-multi", label = "IP Addresses" };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
100 { name = "rostersize", type = "text-single", label = "Roster size" };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
101 { name = "onlineresources", type = "text-multi", label = "Online Resources" };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
102 };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
103
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
104 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
105 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
106 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
107
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
108 { 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
109 { 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
110 value = { "25", "50", "75", "100", "150", "200", "all" } };
227
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
111 { name = "details", type = "boolean", label = "Show details" };
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
112 };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
113
123
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
114 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
115 { 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
116 { 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
117 };
c04443ea114c mod_adhoc, mod_adhoc_cmd_admin: use util.datforms for type="result" forms
Florian Zeitz <florob@babelmonkeys.de>
parents: 121
diff changeset
118
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
119 local announce_layout = dataforms_new{
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
120 title = "Making an Announcement";
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
121 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
122
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
123 { 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
124 { name = "subject", type = "text-single", label = "Subject" };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
125 { 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
126 };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
127
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
128 local shut_down_service_layout = dataforms_new{
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
129 title = "Shutting Down the Service";
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
130 instructions = "Fill out this form to shut down the service.";
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
131
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
132 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
133 { name = "delay", type = "list-single", label = "Time delay before shutting down",
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
134 value = { {label = "30 seconds", value = "30"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
135 {label = "60 seconds", value = "60"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
136 {label = "90 seconds", value = "90"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
137 {label = "2 minutes", value = "120"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
138 {label = "3 minutes", value = "180"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
139 {label = "4 minutes", value = "240"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
140 {label = "5 minutes", value = "300"},
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
141 };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
142 };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
143 { name = "announcement", type = "text-multi", label = "Announcement" };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
144 };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
145
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
146 function add_user_command_handler(self, data, state)
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
147 if state then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
148 if data.action == "cancel" then
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
149 return { status = "canceled" };
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
151 local fields = add_user_layout:data(data.form);
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
152 if not fields.accountjid then
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
153 return { status = "completed", error = { message = "You need to specify a JID." } };
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
154 end
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
155 local username, host, resource = jid.split(fields.accountjid);
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
156 if data.to ~= host then
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
157 return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. data.to}};
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
158 end
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
159 if (fields["password"] == fields["password-verify"]) and username and host then
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
160 if usermanager_user_exists(username, host) then
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
161 return { status = "completed", error = { message = "Account already exists" } };
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
162 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
163 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
164 module:log("info", "Created new account " .. username.."@"..host);
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
165 return { status = "completed", info = "Account successfully created" };
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
166 else
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
167 return { status = "completed", error = { message = "Failed to write data to disk" } };
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
168 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
169 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
170 else
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
171 module:log("debug", (fields.accountjid or "<nil>") .. " " .. (fields.password or "<nil>") .. " "
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
172 .. (fields["password-verify"] or "<nil>"));
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
173 return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } };
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
174 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
175 else
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
176 return { status = "executing", form = add_user_layout }, "executing";
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
177 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
178 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
180 function change_user_password_command_handler(self, data, state)
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
181 if state then
121
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
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
183 return { status = "canceled" };
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
184 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
185 local fields = change_user_password_layout:data(data.form);
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
186 if not fields.accountjid or fields.accountjid == "" or not fields.password then
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
187 return { status = "completed", error = { message = "Please specify username and password" } };
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
188 end
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
189 local username, host, resource = jid.split(fields.accountjid);
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
190 if data.to ~= host then
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
191 return { status = "completed", error = { message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. data.to}};
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
192 end
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
193 if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host) then
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
194 return { status = "completed", info = "Password successfully changed" };
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
195 else
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
196 return { status = "completed", error = { message = "User does not exist" } };
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
197 end
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
198 else
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
199 return { status = "executing", form = change_user_password_layout }, "executing";
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
200 end
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
201 end
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
202
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
203 function disconnect_user(match_jid)
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
204 local node, hostname, givenResource = jid.split(match_jid);
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
205 local host = hosts[hostname];
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
206 local sessions = host.sessions[node] and host.sessions[node].sessions;
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
207 for resource, session in pairs(sessions or {}) do
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
208 if not givenResource or (resource == givenResource) then
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
209 module:log("debug", "Disconnecting "..node.."@"..hostname.."/"..resource);
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
210 session:close();
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
211 end
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
212 end
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
213 return true;
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
214 end
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
215
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
216 function delete_user_command_handler(self, data, state)
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
217 if state then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
218 if data.action == "cancel" then
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
219 return { status = "canceled" };
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
220 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
221 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
222 local failed = {};
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
223 local succeeded = {};
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
224 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
225 local username, host, resource = jid.split(aJID);
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
226 if (host == data.to) and usermanager_user_exists(username, host) and disconnect_user(aJID) 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
227 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
228 succeeded[#succeeded+1] = aJID;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
229 else
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
230 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
231 failed[#failed+1] = aJID;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
232 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
233 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
234 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
235 "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
236 (#failed ~= 0 and
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
237 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") };
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
238 else
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
239 return { status = "executing", form = delete_user_layout }, "executing";
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
240 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
241 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
242
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
243 function end_user_session_handler(self, data, state)
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
244 if state then
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
245 if data.action == "cancel" then
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
246 return { status = "canceled" };
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
247 end
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
248
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
249 local fields = end_user_session_layout:data(data.form);
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
250 local failed = {};
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
251 local succeeded = {};
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
252 for _, aJID in ipairs(fields.accountjids) do
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
253 local username, host, resource = jid.split(aJID);
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
254 if (host == data.to) and usermanager_user_exists(username, host) and disconnect_user(aJID) then
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
255 succeeded[#succeeded+1] = aJID;
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
256 else
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
257 failed[#failed+1] = aJID;
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
258 end
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
259 end
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
260 return {status = "completed", info = (#succeeded ~= 0 and
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
261 "The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "")..
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
262 (#failed ~= 0 and
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
263 "The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
264 else
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
265 return { status = "executing", form = end_user_session_layout }, "executing";
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
266 end
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
267 end
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
268
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
269 function get_user_password_handler(self, data, state)
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
270 if state then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
271 if data.action == "cancel" then
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
272 return { status = "canceled" };
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
273 end
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
274 local fields = get_user_password_layout:data(data.form);
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
275 if not fields.accountjid then
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
276 return { status = "completed", error = { message = "Please specify a JID." } };
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
277 end
97
e172f02726d9 mod_adhoc_cmd_admin: Fix global access
Florian Zeitz <florob@babelmonkeys.de>
parents: 92
diff changeset
278 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
279 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
280 local password = "";
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
281 if host ~= data.to then
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
282 return { status = "completed", error = { message = "Tried to get password for a user on " .. host .. " but command was sent to " .. data.to } };
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
283 elseif 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
284 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
285 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
286 else
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
287 return { status = "completed", error = { message = "User does not exist" } };
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
288 end
250
67f03b7786af mod_adhoc: Fix dataform creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 248
diff changeset
289 return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } };
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
290 else
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
291 return { status = "executing", form = get_user_password_layout }, "executing";
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
292 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
293 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
294
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
295 function get_user_roster_handler(self, data, state)
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
296 if state then
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
297 if data.action == "cancel" then
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
298 return { status = "canceled" };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
299 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
300
251
d36160f4961f mod_adhoc_cmd_admin: Use correct dataform layout
Florian Zeitz <florob@babelmonkeys.de>
parents: 250
diff changeset
301 local fields = get_user_roster_layout:data(data.form);
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
302
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
303 if not fields.accountjid then
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
304 return { status = "completed", error = { message = "Please specify a JID" } };
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
305 end
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
306
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
307 local user, host, resource = jid.split(fields.accountjid);
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
308 if host ~= data.to then
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
309 return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. data.to } };
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
310 elseif not usermanager_user_exists(user, host) then
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
311 return { status = "completed", error = { message = "User does not exist" } };
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
312 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
313 local roster = rm_load_roster(user, host);
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
314
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
315 local query = st.stanza("query", { xmlns = "jabber:iq:roster" });
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
316 for jid in pairs(roster) do
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
317 if jid ~= "pending" and jid then
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
318 query:tag("item", {
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
319 jid = jid,
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
320 subscription = roster[jid].subscription,
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
321 ask = roster[jid].ask,
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
322 name = roster[jid].name,
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
323 });
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
324 for group in pairs(roster[jid].groups) do
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
325 query:tag("group"):text(group):up();
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
326 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
327 query:up();
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
328 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
329 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
330
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
331 local query_text = query:__tostring(); -- TODO: Use upcoming pretty_print() function
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
332 query_text = query_text:gsub("><", ">\n<");
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
333
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
334 local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result");
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
335 result:add_child(query);
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
336 return { status = "completed", other = result };
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
337 else
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
338 return { status = "executing", form = get_user_roster_layout }, "executing";
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
339 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
340 end
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
341
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
342 function get_user_stats_handler(self, data, state)
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
343 if state then
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
344 if data.action == "cancel" then
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
345 return { status = "canceled" };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
346 end
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
347
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
348 local fields = get_user_stats_layout:data(data.form);
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
349
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
350 if not fields.accountjid then
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
351 return { status = "completed", error = { message = "Please specify a JID." } };
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
352 end
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
353
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
354 local user, host, resource = jid.split(fields.accountjid);
171
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
355 if host ~= data.to then
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
356 return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. data.to } };
d15c7d86db11 mod_adhoc_cmd_admin: Check whether action is to be performed on the host the command was sent to.
Florian Zeitz <florob@babelmonkeys.de>
parents: 169
diff changeset
357 elseif not usermanager_user_exists(user, host) then
169
b3a68e71b8a1 mod_adhoc, mod_adhoc_cmd_admin: Handle errors according to XEP
Florian Zeitz < florob@babelmonkeys.de>
parents: 155
diff changeset
358 return { status = "completed", error = { message = "User does not exist" } };
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
359 end
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
360 local roster = rm_load_roster(user, host);
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
361 local rostersize = 0;
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
362 local IPs = "";
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
363 local resources = "";
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
364 for jid in pairs(roster) do
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
365 if jid ~= "pending" and jid then
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
366 rostersize = rostersize + 1;
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
367 end
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
368 end
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
369 for resource, session in pairs((hosts[host].sessions[user] and hosts[host].sessions[user].sessions) or {}) do
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
370 resources = resources .. "\n" .. resource;
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
371 IPs = IPs .. "\n" .. session.ip;
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
372 end
250
67f03b7786af mod_adhoc: Fix dataform creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 248
diff changeset
373 return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = tostring(rostersize),
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
374 onlineresources = resources}} };
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
375 else
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
376 return { status = "executing", form = get_user_stats_layout }, "executing";
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
377 end
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
378 end
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
379
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
380 function get_online_users_command_handler(self, data, state)
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
381 if state then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
382 if data.action == "cancel" then
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
383 return { status = "canceled" };
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
384 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
385
227
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
386 local fields = get_online_users_layout:data(data.form);
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
387
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
388 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
389 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
390 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
391 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
392 local count = 0;
227
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
393 local users = {};
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
394 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
395 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
396 break;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
397 end
227
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
398 users[#users+1] = 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
399 count = count + 1;
227
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
400 if fields.details then
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
401 for resource, session in pairs(user.sessions or {}) do
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
402 local status, priority = "unavailable", tostring(session.priority or "-");
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
403 if session.presence then
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
404 status = session.presence:child_with_name("show");
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
405 if status then
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
406 status = status:get_text() or "[invalid!]";
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
407 else
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
408 status = "available";
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
409 end
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
410 end
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
411 users[#users+1] = " - "..resource..": "..status.."("..priority..")";
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
412 end
648c24de9040 mod_adhoc_cmd_admin: Add suport for showing more detail
Florian Zeitz <florob@babelmonkeys.de>
parents: 171
diff changeset
413 end
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
414 end
250
67f03b7786af mod_adhoc: Fix dataform creation
Florian Zeitz <florob@babelmonkeys.de>
parents: 248
diff changeset
415 return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
416 else
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
417 return { status = "executing", form = get_online_users_layout }, "executing";
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
418 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
419 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
420
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
421 function send_to_online(message, server)
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
422 if server then
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
423 sessions = { [server] = hosts[server] };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
424 else
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
425 sessions = hosts;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
426 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
427
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
428 local c = 0;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
429 for domain, session in pairs(sessions) do
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
430 for user in pairs(session.sessions or {}) do
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
431 c = c + 1;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
432 message.attr.from = domain;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
433 message.attr.to = user.."@"..domain;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
434 core_post_stanza(session, message);
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
435 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
436 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
437
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
438 return c;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
439 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
440
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
441 function announce_handler(self, data, state)
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
442 if state then
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
443 if data.action == "cancel" then
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
444 return { status = "canceled" };
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
445 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
446
121
a9898f13c89e mod_adhoc: Major refactoring. Actuall data exchange happens here now
Florian Zeitz <florob@babelmonkeys.de>
parents: 110
diff changeset
447 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
448
248
db1b4c6089b6 mod_adhoc_cmd_admin: Check if announcement fields are filled (Thanks Zash)
Florian Zeitz <florob@babelmonkeys.de>
parents: 242
diff changeset
449 if (not fields.announcement) or (#fields.announcement == 0) then
242
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
450 return { status = "completed", error = { message = "Please specify some announcement text." } };
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
451 end
161067865850 mod_adhoc_cmd_admin: Be more tollerant towards client/user errors.
Florian Zeitz <florob@babelmonkeys.de>
parents: 227
diff changeset
452
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
453 module:log("info", "Sending server announcement to all online users");
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
454 local message = st.message({type = "headline"}, fields.announcement):up()
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
455 :tag("subject"):text(fields.subject or "Announcement");
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
456
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
457 local count = send_to_online(message, data.to);
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
458
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
459 module:log("info", "Announcement sent to %d online users", count);
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
460 return { status = "completed", info = "Announcement sent." };
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
461 else
124
843cadf36306 mod_adhoc*: Move state handling to mod_adhoc itself
Florian Zeitz <florob@babelmonkeys.de>
parents: 123
diff changeset
462 return { status = "executing", form = announce_layout }, "executing";
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
463 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
464
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
465 return true;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
466 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
467
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
468 function shut_down_service_handler(self, data, state)
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
469 if state then
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
470 if data.action == "cancel" then
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
471 return { status = "canceled" };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
472 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
473
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
474 local fields = shut_down_service_layout:data(data.form);
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
475
248
db1b4c6089b6 mod_adhoc_cmd_admin: Check if announcement fields are filled (Thanks Zash)
Florian Zeitz <florob@babelmonkeys.de>
parents: 242
diff changeset
476 if fields.announcement and #fields.announcement > 0 then
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
477 local message = st.message({type = "headline"}, fields.announcement):up()
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
478 :tag("subject"):text("Server is shutting down");
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
479 send_to_online(message);
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
480 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
481
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
482 timer_add_task(tonumber(fields.delay or "5"), prosody.shutdown);
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
483
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
484 return { status = "completed", info = "Server is about to shut down" };
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
485 else
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
486 return { status = "executing", form = shut_down_service_layout }, "executing";
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
487 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
488
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
489 return true;
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
490 end
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
491
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
492 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
493 local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin");
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
494 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
495 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
496 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
497 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
498 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
499 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_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
500 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");
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
501 local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "admin");
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
502
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
503 module:add_item("adhoc", add_user_desc);
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
504 module:add_item("adhoc", announce_desc);
110
e02281edc273 mod_adhoc_cmd_admin: Add Change User Password command
Florian Zeitz <florob@babelmonkeys.de>
parents: 109
diff changeset
505 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
506 module:add_item("adhoc", delete_user_desc);
128
bdd1641c159d mod_adhoc_cmd_admin: Add "End User Session" command. Also end sessions before deleting a user
Florian Zeitz <florob@babelmonkeys.de>
parents: 124
diff changeset
507 module:add_item("adhoc", end_user_session_desc);
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
508 module:add_item("adhoc", get_user_password_desc);
144
b4f9518d5a00 mod_adhoc_cmd_admin: "Get User Roster" command (with not very good™ XML formatting for now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 133
diff changeset
509 module:add_item("adhoc", get_user_roster_desc);
155
7a037cb5ab9e mod_adhoc_cmd_admin: Add "Get User Statistics" command
Florian Zeitz < florob@babelmonkeys.de>
parents: 145
diff changeset
510 module:add_item("adhoc", get_user_stats_desc);
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
511 module:add_item("adhoc", get_online_users_desc);
133
8945153321a1 mod_adhoc_cmd_admin: Add "Shut Down Service" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 128
diff changeset
512 module:add_item("adhoc", shut_down_service_desc);