annotate mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 99:2d03350613c4

mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
author Waqas Hussain <waqas20@gmail.com>
date Thu, 26 Nov 2009 20:23:20 +0500
parents e172f02726d9
children 9b63fd1196c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Copyright (C) 2009 Florian Zeitz
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 --
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 -- This file is MIT/X11 licensed. Please see the
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 --
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
7 local _G = _G;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
8
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
9 local prosody = _G.prosody;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
10 local hosts = prosody.hosts;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
11
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
12 local t_concat = table.concat;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
13
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 local usermanager_user_exists = require "core.usermanager".user_exists;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
15 local usermanager_get_password = require "core.usermanager".get_password;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 local usermanager_create_user = require "core.usermanager".create_user;
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
17 local is_admin = require "core.usermanager".is_admin;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
19 local st, jid, uuid = require "util.stanza", require "util.jid", require "util.uuid";
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
20 local dataforms_new = require "util.dataforms".new;
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
21 local adhoc_new = module:require "adhoc".new;
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 local sessions = {};
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24
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
25 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
26 title = "Adding a User";
34
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
27 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
28
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
29 { 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
30 { 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
31 { 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
32 { 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
33 };
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
34
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
35 local delete_user_layout = dataforms_new{
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
36 title = "Deleting a User";
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
37 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
38
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
39 { 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
40 { 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
41 };
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
42
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
43 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
44 title = "Getting User's Password";
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
45 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
46
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
47 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
48 { name = "accountjid", type = "jid-single", label = "The Jabber ID for which to retrieve the password" };
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
49 };
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
50
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
51 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
52 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
53 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
54
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
55 { 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
56 { 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
57 value = { "25", "50", "75", "100", "150", "200", "all" } };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
58 };
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
59
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
60 local announce_layout = dataforms_new{
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
61 title = "Making an Announcement";
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
62 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
63
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
64 { 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
65 { name = "subject", type = "text-single", label = "Subject" };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
66 { 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
67 };
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
68
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 function add_user_command_handler(item, origin, stanza)
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71 if stanza.tags[1].attr.action == "cancel" then
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
72 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75 end
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
76 local form = stanza.tags[1]:child_with_ns("jabber:x:data");
34
fc374b724270 mod_adhoc_cmd_admin: Define form layout only once.
Florian Zeitz <florob@babelmonkeys.de>
parents: 33
diff changeset
77 local fields = add_user_layout:data(form);
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 local username, host, resource = jid.split(fields.accountjid);
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
79 if (fields["password"] == fields["password-verify"]) and username and host and host == stanza.attr.to then
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 if usermanager_user_exists(username, host) then
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81 origin.send(st.error_reply(stanza, "cancel", "conflict", "Account already exists"):up()
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
82 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
83 :tag("note", {type="error"}):text("Account already exists")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 if usermanager_create_user(username, fields.password, host) then
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
88 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
89 :tag("note", {type="info"}):text("Account successfully created")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91 module:log("debug", "Created new account " .. username.."@"..host);
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
93 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 origin.send(st.error_reply(stanza, "wait", "internal-server-error",
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 "Failed to write data to disk"):up()
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
96 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
97 :tag("note", {type="error"}):text("Failed to write data to disk")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
100 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 else
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 module:log("debug", fields.accountjid .. " " .. fields.password .. " " .. fields["password-verify"]);
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 origin.send(st.error_reply(stanza, "cancel", "conflict",
35
3c49411d4aa3 mod_adhoc_cmd_admin: Fixed style, some typos, and got down to <100LOC. Perhaps we need util.adhoc?
Matthew Wild <mwild1@gmail.com>
parents: 34
diff changeset
105 "Invalid data.\nPassword mismatch, or empty username"):up()
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
106 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
107 :tag("note", {type="error"}):text("Invalid data.\nPassword mismatch, or empty username")));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 sessions[stanza.tags[1].attr.sessionid] = nil;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 else
33
f3225c55288f mod_adhoc_cmd_admin: More utils.dataforms sugar
Florian Zeitz <florob@babelmonkeys.de>
parents: 32
diff changeset
112 local sessionid=uuid.generate();
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 sessions[sessionid] = "executing";
36
58d326d86a9a mod_adhoc: add adhoc.lib.lua to ease implementing new commands (as a consequence mod_adhoc is a directory now)
Florian Zeitz <florob@babelmonkeys.de>
parents: 35
diff changeset
114 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(add_user_layout:form())));
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 return true;
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
119 function delete_user_command_handler(item, origin, stanza)
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
120 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
121 if stanza.tags[1].attr.action == "cancel" then
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
122 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
123 sessions[stanza.tags[1].attr.sessionid] = nil;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
124 return true;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
125 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
126 local form = stanza.tags[1]:child_with_ns("jabber:x:data");
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
127 local fields = delete_user_layout:data(form);
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
128 local failed = {};
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
129 local succeeded = {};
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
130 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
131 local username, host, resource = jid.split(aJID);
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
132 if usermanager_user_exists(username, host) and usermanager_create_user(username, nil, host) then
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
133 module:log("debug", "User" .. aJID .. "has been deleted");
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
134 succeeded[#succeeded+1] = aJID;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
135 else
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
136 module:log("debug", "Tried to delete not existing user "..aJID);
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
137 failed[#failed+1] = aJID;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
138 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
139 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
140 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
141 :tag("note", {type="info"})
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
142 :text((#succeeded ~= 0 and "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "")
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
143 ..(#failed ~= 0 and "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or ""))));
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
144 sessions[stanza.tags[1].attr.sessionid] = nil;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
145 return true;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
146 else
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
147 local sessionid=uuid.generate();
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
148 sessions[sessionid] = "executing";
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
149 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(delete_user_layout:form())));
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
150 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
151 return true;
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
152 end
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
153
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
154 function get_user_password_handler(item, origin, stanza)
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
155 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
156 if stanza.tags[1].attr.action == "cancel" then
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
157 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
158 sessions[stanza.tags[1].attr.sessionid] = nil;
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
159 return true;
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
160 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
161 local form = stanza.tags[1]:child_with_ns("jabber:x:data");
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
162 local fields = get_user_password_layout:data(form);
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
163 local accountjid = st.stanza("field", {var="accountjid", label = "JID", type="jid-single"});
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
164 local password = st.stanza("field", {var="password", label = "Password", type="text-single"});
97
e172f02726d9 mod_adhoc_cmd_admin: Fix global access
Florian Zeitz <florob@babelmonkeys.de>
parents: 92
diff changeset
165 local user, host, resource = jid.split(fields.accountjid);
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
166 if usermanager_user_exists(user, host) then
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
167 accountjid:tag("value"):text(fields.accountjid):up();
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
168 password:tag("value"):text(usermanager_get_password(user, host)):up();
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
169 else
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
170 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "User does not exist")
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
171 :add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
172 :tag("note", {type="error"}):text("User does not exist")));
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
173 sessions[stanza.tags[1].attr.sessionid] = nil;
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
174 return true;
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
175 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
176 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
177 :tag("x", {xmlns="jabber:x:data", type="result"})
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
178 :tag("field", {type="hidden", var="FORM_TYPE"})
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
179 :tag("value"):text("http://jabber.org/protocol/admin"):up():up()
92
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
180 :add_child(accountjid)
7dad958aad15 mod_adhoc_cmd_admin: Change to upcoming XEP version
Florian Zeitz <florob@babelmonkeys.de>
parents: 91
diff changeset
181 :add_child(password)));
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
182 sessions[stanza.tags[1].attr.sessionid] = nil;
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
183 return true;
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
184 else
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
185 local sessionid=uuid.generate();
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
186 sessions[sessionid] = "executing";
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
187 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(get_user_password_layout:form())));
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
188 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
189 return true;
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
190 end
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
191
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
192 function get_online_users_command_handler(item, origin, stanza)
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
193 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
194 if stanza.tags[1].attr.action == "cancel" then
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
195 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
196 sessions[stanza.tags[1].attr.sessionid] = nil;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
197 return true;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
198 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
199
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
200 local form = stanza.tags[1]:child_with_ns("jabber:x:data");
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
201 local fields = add_user_layout:data(form);
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
202
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
203 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
204 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
205 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
206 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
207 local count = 0;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
208 local field = st.stanza("field", {label="The list of all online users", var="onlineuserjids", type="text-multi"});
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
209 for username, user in pairs(hosts[stanza.attr.to].sessions or {}) do
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
210 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
211 break;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
212 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
213 field:tag("value"):text(username.."@"..stanza.attr.to):up();
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
214 count = count + 1;
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
215 end
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
216 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
217 :tag("x", {xmlns="jabber:x:data", type="result"})
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
218 :tag("field", {type="hidden", var="FORM_TYPE"})
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
219 :tag("value"):text("http://jabber.org/protocol/admin"):up():up()
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
220 :add_child(field)));
48
7fbaf590dc12 mod_adhoc_cmd_admin: Fix session leak
Florian Zeitz <florob@babelmonkeys.de>
parents: 44
diff changeset
221 sessions[stanza.tags[1].attr.sessionid] = nil;
7fbaf590dc12 mod_adhoc_cmd_admin: Fix session leak
Florian Zeitz <florob@babelmonkeys.de>
parents: 44
diff changeset
222 return true;
44
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
223 else
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
224 local sessionid=uuid.generate();
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
225 sessions[sessionid] = "executing";
00f96207693a mod_adhoc_cmd_admin: Possibility to limit number of received answers
Florian Zeitz <florob@babelmonkeys.de>
parents: 43
diff changeset
226 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(get_online_users_layout:form())));
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
227 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
228
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
229 return true;
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
230 end
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
231
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
232 function announce_handler(item, origin, stanza)
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
233 if stanza.tags[1].attr.sessionid and sessions[stanza.tags[1].attr.sessionid] then
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
234 if stanza.tags[1].attr.action == "cancel" then
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
235 origin.send(st.reply(stanza):add_child(item:cmdtag("canceled", stanza.tags[1].attr.sessionid)));
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
236 sessions[stanza.tags[1].attr.sessionid] = nil;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
237 return true;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
238 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
239
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
240 local form = stanza.tags[1]:child_with_ns("jabber:x:data");
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
241 local fields = add_user_layout:data(form);
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
242
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
243 module:log("info", "Sending server announcement to all online users");
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
244 local host_session = hosts[stanza.attr.to];
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
245 local message = st.message({type = "headline", from = stanza.attr.to}, fields.announcement):up()
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
246 :tag("subject"):text(fields.subject or "Announcement");
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
247
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
248 local c = 0;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
249 for user in pairs(host_session.sessions) do
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
250 c = c + 1;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
251 message.attr.to = user.."@"..stanza.attr.to;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
252 core_post_stanza(host_session, message);
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
253 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
254
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
255 module:log("info", "Announcement sent to %d online users", c);
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
256
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
257 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", stanza.tags[1].attr.sessionid)
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
258 :tag("note"):text("Announcement sent.")));
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
259 sessions[stanza.tags[1].attr.sessionid] = nil;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
260 return true;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
261 else
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
262 local sessionid=uuid.generate();
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
263 sessions[sessionid] = "executing";
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
264 origin.send(st.reply(stanza):add_child(item:cmdtag("executing", sessionid):add_child(announce_layout:form())));
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
265 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
266
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
267 return true;
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
268 end
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
269
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 40
diff changeset
270 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
271 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
272 local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
43
adc9eff8adb2 mod_adhoc, mod_adhoc_cmd_admin: Show only commands they may execute to the user
Florian Zeitz <florob@babelmonkeys.de>
parents: 40
diff changeset
273 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users", get_online_users_command_handler, "admin");
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
274 local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin");
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
275
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
276 function module.unload()
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
277 module:remove_item("adhoc", add_user_desc);
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
278 module:remove_item("adhoc", delete_user_desc);
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
279 module:remove_item("adhoc", get_user_password_desc);
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
280 module:remove_item("adhoc", get_online_users_desc);
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
281 module:remove_item("adhoc", announce_desc);
29
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
282 end
b384999b047f mod_adhoc_cmd_admin: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
283
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
284 module:add_item("adhoc", add_user_desc);
84
b47216512a1d mod_adhoc_cmd_admin: Implement "Delete User" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 67
diff changeset
285 module:add_item("adhoc", delete_user_desc);
91
63bf00fd8f6e mod_adhoc_cmd_admin: Implement Get User Password
Florian Zeitz <florob@babelmonkeys.de>
parents: 84
diff changeset
286 module:add_item("adhoc", get_user_password_desc);
40
4c4daa1f8ae7 mod_adhoc_cmd_admin: Add Get List of Online Users command
Florian Zeitz <florob@babelmonkeys.de>
parents: 36
diff changeset
287 module:add_item("adhoc", get_online_users_desc);
67
e839b4453387 mod_adhoc_cmd_admin: Add announce command
Florian Zeitz <florob@babelmonkeys.de>
parents: 49
diff changeset
288 module:add_item("adhoc", announce_desc);