plugins/mod_admin_adhoc.lua
author Matthew Wild <mwild1@gmail.com>
Sun, 17 Mar 2024 10:10:24 +0000
changeset 13464 a688947fab1e
parent 12981 74b9e05af71e
permissions -rw-r--r--
mod_bosh: Set base_type on session This fixes a traceback with mod_saslauth. Ideally we move this to util.session at some point, though.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4292
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
     1
-- Copyright (C) 2009-2011 Florian Zeitz
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     2
--
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     3
-- This file is MIT/X11 licensed. Please see the
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     4
-- COPYING file in the source package for more information.
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     5
--
9404
6329c07452b7 mod_admin_adhoc: Ignore shadowed 'err' variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9403
diff changeset
     6
-- luacheck: ignore 212/self 212/data 212/state 412/err 422/err
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     7
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     8
local _G = _G;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     9
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    10
local prosody = _G.prosody;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    11
local hosts = prosody.hosts;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    12
local t_concat = table.concat;
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
    13
local t_sort = table.sort;
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    14
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    15
local module_host = module:get_host();
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    16
12981
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    17
local keys = require "prosody.util.iterators".keys;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    18
local usermanager_user_exists = require "prosody.core.usermanager".user_exists;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    19
local usermanager_create_user = require "prosody.core.usermanager".create_user;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    20
local usermanager_delete_user = require "prosody.core.usermanager".delete_user;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    21
local usermanager_disable_user = require "prosody.core.usermanager".disable_user;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    22
local usermanager_enable_user = require "prosody.core.usermanager".enable_user;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    23
local usermanager_set_password = require "prosody.core.usermanager".set_password;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    24
local hostmanager_activate = require "prosody.core.hostmanager".activate;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    25
local hostmanager_deactivate = require "prosody.core.hostmanager".deactivate;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    26
local rm_load_roster = require "prosody.core.rostermanager".load_roster;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    27
local st, jid = require "prosody.util.stanza", require "prosody.util.jid";
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    28
local timer_add_task = require "prosody.util.timer".add_task;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    29
local dataforms_new = require "prosody.util.dataforms".new;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    30
local array = require "prosody.util.array";
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    31
local modulemanager = require "prosody.core.modulemanager";
5013
ab693eea0869 mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table.
Kim Alvefur <zash@zash.se>
parents: 4993
diff changeset
    32
local core_post_stanza = prosody.core_post_stanza;
12981
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    33
local adhoc_simple = require "prosody.util.adhoc".new_simple_form;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    34
local adhoc_initial = require "prosody.util.adhoc".new_initial_data_form;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12914
diff changeset
    35
local set = require"prosody.util.set";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    36
4780
4b8f2b91826c mod_admin_adhoc: Small style fix
Matthew Wild <mwild1@gmail.com>
parents: 4595
diff changeset
    37
module:depends("adhoc");
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    38
local adhoc_new = module:require "adhoc".new;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    39
4932
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    40
local function generate_error_message(errors)
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    41
	local errmsg = {};
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    42
	for name, err in pairs(errors) do
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    43
		errmsg[#errmsg + 1] = name .. ": " .. err;
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    44
	end
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    45
	return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    46
end
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
    47
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    48
-- Adding a new user
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    49
local add_user_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    50
	title = "Adding a User";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    51
	instructions = "Fill out this form to add a user.";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    52
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    53
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    54
	{ name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for the account to be added" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    55
	{ name = "password", type = "text-private", label = "The password for this account" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    56
	{ name = "password-verify", type = "text-private", label = "Retype password" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    57
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    58
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
    59
local add_user_command_handler = adhoc_simple(add_user_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    60
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    61
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    62
	end
10547
46b456ed12bd mod_admin_adhoc: Remove unused JID resource variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10402
diff changeset
    63
	local username, host = jid.split(fields.accountjid);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    64
	if module_host ~= host then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    65
		return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. module_host}};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    66
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    67
	if (fields["password"] == fields["password-verify"]) and username and host then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    68
		if usermanager_user_exists(username, host) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    69
			return { status = "completed", error = { message = "Account already exists" } };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    70
		else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    71
			if usermanager_create_user(username, fields.password, host) then
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
    72
				module:log("info", "Created new account %s@%s by %s", username, host, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    73
				return { status = "completed", info = "Account successfully created" };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    74
			else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    75
				return { status = "completed", error = { message = "Failed to write data to disk" } };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    76
			end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    77
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    78
	else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    79
		module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or "<nil>");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    80
		return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    81
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    82
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    83
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    84
-- Changing a user's password
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    85
local change_user_password_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    86
	title = "Changing a User Password";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    87
	instructions = "Fill out this form to change a user's password.";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    88
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    89
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    90
	{ name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for this account" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    91
	{ name = "password", type = "text-private", required = true, label = "The password for this account" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    92
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    93
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
    94
local change_user_password_command_handler = adhoc_simple(change_user_password_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    95
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    96
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    97
	end
10547
46b456ed12bd mod_admin_adhoc: Remove unused JID resource variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10402
diff changeset
    98
	local username, host = jid.split(fields.accountjid);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
    99
	if module_host ~= host then
8772
e809074cdc09 mod_admin_adhoc: Split a long line (improves readability) [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8731
diff changeset
   100
		return {
e809074cdc09 mod_admin_adhoc: Split a long line (improves readability) [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8731
diff changeset
   101
			status = "completed",
e809074cdc09 mod_admin_adhoc: Split a long line (improves readability) [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8731
diff changeset
   102
			error = {
e809074cdc09 mod_admin_adhoc: Split a long line (improves readability) [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8731
diff changeset
   103
				message = "Trying to change the password of a user on " .. host .. " but command was sent to " .. module_host
e809074cdc09 mod_admin_adhoc: Split a long line (improves readability) [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8731
diff changeset
   104
			}
e809074cdc09 mod_admin_adhoc: Split a long line (improves readability) [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8731
diff changeset
   105
		};
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   106
	end
8195
4354f556c5db core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents: 7048
diff changeset
   107
	if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host, nil) then
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   108
		module:log("info", "Password of account %s@%s changed by %s", username, host, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   109
		return { status = "completed", info = "Password successfully changed" };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   110
	else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   111
		return { status = "completed", error = { message = "User does not exist" } };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   112
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   113
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   114
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   115
-- Reloading the config
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   116
local function config_reload_handler(self, data, state)
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   117
	module:log("info", "%s reloads the config", jid.bare(data.from));
4292
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   118
	local ok, err = prosody.reload_config();
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   119
	if ok then
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   120
		return { status = "completed", info = "Configuration reloaded (modules may need to be reloaded for this to have an effect)" };
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   121
	else
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   122
		return { status = "completed", error = { message = "Failed to reload config: " .. tostring(err) } };
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   123
	end
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   124
end
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   125
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   126
-- Deleting a user's account
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   127
local delete_user_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   128
	title = "Deleting a User";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   129
	instructions = "Fill out this form to delete a user.";
4292
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   130
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   131
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
6465
fcff8fa495d4 mod_admin_adhoc: Add required to field in user deletion form too
Kim Alvefur <zash@zash.se>
parents: 6464
diff changeset
   132
	{ name = "accountjids", type = "jid-multi", required = true, label = "The Jabber ID(s) to delete" };
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   133
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   134
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   135
local delete_user_command_handler = adhoc_simple(delete_user_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   136
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   137
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   138
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   139
	local failed = {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   140
	local succeeded = {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   141
	for _, aJID in ipairs(fields.accountjids) do
10547
46b456ed12bd mod_admin_adhoc: Remove unused JID resource variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10402
diff changeset
   142
		local username, host = jid.split(aJID);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   143
		if (host == module_host) and  usermanager_user_exists(username, host) and usermanager_delete_user(username, host) then
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   144
			module:log("info", "User %s has been deleted by %s", aJID, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   145
			succeeded[#succeeded+1] = aJID;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   146
		else
11731
f3aee8a825cc Fix various spelling errors (thanks codespell)
Kim Alvefur <zash@zash.se>
parents: 11637
diff changeset
   147
			module:log("debug", "Tried to delete non-existent user %s", aJID);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   148
			failed[#failed+1] = aJID;
4932
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
   149
		end
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   150
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   151
	return {status = "completed", info = (#succeeded ~= 0 and
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   152
			"The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "")..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   153
			(#failed ~= 0 and
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   154
			"The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   155
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   156
12914
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   157
local disable_user_layout = dataforms_new{
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   158
	title = "Disabling a User";
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   159
	instructions = "Fill out this form to disable a user.";
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   160
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   161
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   162
	{ name = "accountjids", type = "jid-multi", required = true, label = "The Jabber ID(s) to disable" };
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   163
};
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   164
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   165
local disable_user_command_handler = adhoc_simple(disable_user_layout, function(fields, err, data)
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   166
	if err then
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   167
		return generate_error_message(err);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   168
	end
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   169
	local failed = {};
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   170
	local succeeded = {};
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   171
	for _, aJID in ipairs(fields.accountjids) do
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   172
		local username, host = jid.split(aJID);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   173
		if (host == module_host) and  usermanager_user_exists(username, host) and usermanager_disable_user(username, host) then
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   174
			module:log("info", "User %s has been disabled by %s", aJID, jid.bare(data.from));
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   175
			succeeded[#succeeded+1] = aJID;
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   176
		else
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   177
			module:log("debug", "Tried to disable non-existent user %s", aJID);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   178
			failed[#failed+1] = aJID;
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   179
		end
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   180
	end
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   181
	return {status = "completed", info = (#succeeded ~= 0 and
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   182
			"The following accounts were successfully disabled:\n"..t_concat(succeeded, "\n").."\n" or "")..
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   183
			(#failed ~= 0 and
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   184
			"The following accounts could not be disabled:\n"..t_concat(failed, "\n") or "") };
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   185
end);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   186
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   187
local enable_user_layout = dataforms_new{
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   188
	title = "Re-Enable a User";
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   189
	instructions = "Fill out this form to enable a user.";
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   190
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   191
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   192
	{ name = "accountjids", type = "jid-multi", required = true, label = "The Jabber ID(s) to re-enable" };
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   193
};
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   194
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   195
local enable_user_command_handler = adhoc_simple(enable_user_layout, function(fields, err, data)
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   196
	if err then
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   197
		return generate_error_message(err);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   198
	end
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   199
	local failed = {};
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   200
	local succeeded = {};
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   201
	for _, aJID in ipairs(fields.accountjids) do
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   202
		local username, host = jid.split(aJID);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   203
		if (host == module_host) and  usermanager_user_exists(username, host) and usermanager_enable_user(username, host) then
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   204
			module:log("info", "User %s has been enabled by %s", aJID, jid.bare(data.from));
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   205
			succeeded[#succeeded+1] = aJID;
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   206
		else
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   207
			module:log("debug", "Tried to enable non-existent user %s", aJID);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   208
			failed[#failed+1] = aJID;
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   209
		end
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   210
	end
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   211
	return {status = "completed", info = (#succeeded ~= 0 and
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   212
			"The following accounts were successfully enabled:\n"..t_concat(succeeded, "\n").."\n" or "")..
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   213
			(#failed ~= 0 and
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   214
			"The following accounts could not be enabled:\n"..t_concat(failed, "\n") or "") };
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   215
end);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   216
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   217
-- Ending a user's session
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   218
local function disconnect_user(match_jid)
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   219
	local node, hostname, givenResource = jid.split(match_jid);
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   220
	local host = hosts[hostname];
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   221
	local sessions = host.sessions[node] and host.sessions[node].sessions;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   222
	for resource, session in pairs(sessions or {}) do
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   223
		if not givenResource or (resource == givenResource) then
4993
5243b74a4cbb Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents: 4956
diff changeset
   224
			module:log("debug", "Disconnecting %s@%s/%s", node, hostname, resource);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   225
			session:close();
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   226
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   227
	end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   228
	return true;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   229
end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   230
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   231
local end_user_session_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   232
	title = "Ending a User Session";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   233
	instructions = "Fill out this form to end a user's session.";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   234
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   235
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
6464
6b38bfaafe0c mod_admin_adhoc: Mark 'accountjids' field as required in 'end user sessions' command (thanks Lloyd)
Kim Alvefur <zash@zash.se>
parents: 5721
diff changeset
   236
	{ name = "accountjids", type = "jid-multi", label = "The Jabber ID(s) for which to end sessions", required = true };
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   237
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   238
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   239
local end_user_session_handler = adhoc_simple(end_user_session_layout, function(fields, err)
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   240
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   241
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   242
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   243
	local failed = {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   244
	local succeeded = {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   245
	for _, aJID in ipairs(fields.accountjids) do
10547
46b456ed12bd mod_admin_adhoc: Remove unused JID resource variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10402
diff changeset
   246
		local username, host = jid.split(aJID);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   247
		if (host == module_host) and  usermanager_user_exists(username, host) and disconnect_user(aJID) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   248
			succeeded[#succeeded+1] = aJID;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   249
		else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   250
			failed[#failed+1] = aJID;
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   251
		end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   252
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   253
	return {status = "completed", info = (#succeeded ~= 0 and
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   254
		"The following accounts were successfully disconnected:\n"..t_concat(succeeded, "\n").."\n" or "")..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   255
		(#failed ~= 0 and
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   256
		"The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   257
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   258
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   259
-- Getting a user's roster
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   260
local get_user_roster_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   261
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   262
	{ name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the roster" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   263
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   264
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   265
local get_user_roster_result_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   266
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   267
	{ name = "accountjid", type = "jid-single", label = "This is the roster for" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   268
	{ name = "roster", type = "text-multi", label = "Roster XML" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   269
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   270
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   271
local get_user_roster_handler = adhoc_simple(get_user_roster_layout, function(fields, err)
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   272
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   273
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   274
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   275
10547
46b456ed12bd mod_admin_adhoc: Remove unused JID resource variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10402
diff changeset
   276
	local user, host = jid.split(fields.accountjid);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   277
	if host ~= module_host then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   278
		return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. module_host } };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   279
	elseif not usermanager_user_exists(user, host) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   280
		return { status = "completed", error = { message = "User does not exist" } };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   281
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   282
	local roster = rm_load_roster(user, host);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   283
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   284
	local query = st.stanza("query", { xmlns = "jabber:iq:roster" });
8774
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   285
	for contact_jid in pairs(roster) do
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   286
		if contact_jid then
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   287
			query:tag("item", {
8774
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   288
				jid = contact_jid,
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   289
				subscription = roster[contact_jid].subscription,
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   290
				ask = roster[contact_jid].ask,
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   291
				name = roster[contact_jid].name,
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   292
			});
8774
82bdeb8009ce mod_admin_adhoc: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8773
diff changeset
   293
			for group in pairs(roster[contact_jid].groups) do
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   294
				query:tag("group"):text(group):up();
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   295
			end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   296
			query:up();
4932
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
   297
		end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   298
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   299
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   300
	local query_text = tostring(query):gsub("><", ">\n<");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   301
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   302
	local result = get_user_roster_result_layout:form({ accountjid = user.."@"..host, roster = query_text }, "result");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   303
	result:add_child(query);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   304
	return { status = "completed", other = result };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   305
end);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   306
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   307
-- Getting user statistics
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   308
local get_user_stats_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   309
	title = "Get User Statistics";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   310
	instructions = "Fill out this form to gather user statistics.";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   311
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   312
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   313
	{ name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for statistics" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   314
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   315
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   316
local get_user_stats_result_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   317
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   318
	{ name = "ipaddresses", type = "text-multi", label = "IP Addresses" };
11876
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   319
	{ name = "rostersize", type = "text-single", label = "Roster size", datatype = "xs:integer" };
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   320
	{ name = "onlineresources", type = "text-multi", label = "Online Resources" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   321
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   322
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   323
local get_user_stats_handler = adhoc_simple(get_user_stats_layout, function(fields, err)
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   324
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   325
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   326
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   327
9402
ec60e74fd9bb mod_admin_adhoc: Remove unused loop variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9089
diff changeset
   328
	local user, host = jid.split(fields.accountjid);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   329
	if host ~= module_host then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   330
		return { status = "completed", error = { message = "Tried to get stats for a user on " .. host .. " but command was sent to " .. module_host } };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   331
	elseif not usermanager_user_exists(user, host) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   332
		return { status = "completed", error = { message = "User does not exist" } };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   333
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   334
	local roster = rm_load_roster(user, host);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   335
	local rostersize = 0;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   336
	local IPs = "";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   337
	local resources = "";
8775
375f2e663cea mod_admin_adhoc: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8774
diff changeset
   338
	for contact_jid in pairs(roster) do
375f2e663cea mod_admin_adhoc: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8774
diff changeset
   339
		if contact_jid then
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   340
			rostersize = rostersize + 1;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   341
		end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   342
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   343
	for resource, session in pairs((hosts[host].sessions[user] and hosts[host].sessions[user].sessions) or {}) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   344
		resources = resources .. "\n" .. resource;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   345
		IPs = IPs .. "\n" .. session.ip;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   346
	end
11876
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   347
	return { status = "completed", result = {layout = get_user_stats_result_layout, values = {ipaddresses = IPs, rostersize = rostersize,
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   348
		onlineresources = resources}} };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   349
end);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   350
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   351
-- Getting a list of online users
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   352
local get_online_users_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   353
	title = "Getting List of Online Users";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   354
	instructions = "How many users should be returned at most?";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   355
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   356
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   357
	{ name = "max_items", type = "list-single", label = "Maximum number of users",
9088
9bd38bbf8623 mod_admin_adhoc: Keep options for list-single in 'options' field where they belong
Kim Alvefur <zash@zash.se>
parents: 8776
diff changeset
   358
		options = { "25", "50", "75", "100", "150", "200", "all" } };
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   359
	{ name = "details", type = "boolean", label = "Show details" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   360
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   361
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   362
local get_online_users_result_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   363
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   364
	{ name = "onlineuserjids", type = "text-multi", label = "The list of all online users" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   365
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   366
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   367
local get_online_users_command_handler = adhoc_simple(get_online_users_layout, function(fields, err)
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   368
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   369
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   370
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   371
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   372
	local max_items = nil
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   373
	if fields.max_items ~= "all" then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   374
		max_items = tonumber(fields.max_items);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   375
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   376
	local count = 0;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   377
	local users = {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   378
	for username, user in pairs(hosts[module_host].sessions or {}) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   379
		if (max_items ~= nil) and (count >= max_items) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   380
			break;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   381
		end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   382
		users[#users+1] = username.."@"..module_host;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   383
		count = count + 1;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   384
		if fields.details then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   385
			for resource, session in pairs(user.sessions or {}) do
6460
ddcb29a35409 mod_admin_adhoc: Show IP in detailed version of online user listing
Florian Zeitz <florob@babelmonkeys.de>
parents: 5818
diff changeset
   386
				local status, priority, ip = "unavailable", tostring(session.priority or "-"), session.ip or "<unknown>";
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   387
				if session.presence then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   388
					status = session.presence:child_with_name("show");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   389
					if status then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   390
						status = status:get_text() or "[invalid!]";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   391
					else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   392
						status = "available";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   393
					end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   394
				end
6460
ddcb29a35409 mod_admin_adhoc: Show IP in detailed version of online user listing
Florian Zeitz <florob@babelmonkeys.de>
parents: 5818
diff changeset
   395
				users[#users+1] = " - "..resource..": "..status.."("..priority.."), IP: ["..ip.."]";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   396
			end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   397
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   398
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   399
	return { status = "completed", result = {layout = get_online_users_result_layout, values = {onlineuserjids=t_concat(users, "\n")}} };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   400
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   401
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   402
-- Getting a list of S2S connections (this host)
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   403
local list_s2s_this_result = dataforms_new {
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   404
	title = "List of S2S connections on this host";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   405
11876
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   406
	{ name = "FORM_TYPE"; type = "hidden"; value = "http://prosody.im/protocol/s2s#list" };
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   407
	{ name = "sessions"; type = "text-multi"; label = "Connections:" };
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   408
	{ name = "num_in"; type = "text-single"; label = "#incoming connections:"; datatype = "xs:integer" };
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   409
	{ name = "num_out"; type = "text-single"; label = "#outgoing connections:"; datatype = "xs:integer" };
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   410
};
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   411
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   412
local function session_flags(session, line)
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   413
	line = line or {};
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   414
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   415
	if session.id then
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   416
		line[#line+1] = "["..session.id.."]"
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   417
	else
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   418
		line[#line+1] = "["..session.type..(tostring(session):match("%x*$")).."]"
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   419
	end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   420
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   421
	local flags = {};
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   422
	if session.cert_identity_status == "valid" then
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   423
		flags[#flags+1] = "authenticated";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   424
	end
10402
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   425
	if session.dialback_key then
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   426
		flags[#flags+1] = "dialback";
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   427
	end
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   428
	if session.external_auth then
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   429
		flags[#flags+1] = "SASL";
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   430
	end
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   431
	if session.secure then
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   432
		flags[#flags+1] = "encrypted";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   433
	end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   434
	if session.compressed then
7047
8fcee3339463 mod_admin_adhoc: Remove extra ) that should not be there
Kim Alvefur <zash@zash.se>
parents: 6799
diff changeset
   435
		flags[#flags+1] = "compressed";
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   436
	end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   437
	if session.smacks then
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   438
		flags[#flags+1] = "sm";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   439
	end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   440
	if session.ip and session.ip:match(":") then
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   441
		flags[#flags+1] = "IPv6";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   442
	end
10402
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   443
	if session.incoming and session.outgoing then
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   444
		flags[#flags+1] = "bidi";
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   445
	elseif session.is_bidi or session.bidi_session then
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   446
		flags[#flags+1] = "bidi";
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   447
	end
fa50789d6ec7 mod_admin_adhoc: Add some flags to s2s listing command
Kim Alvefur <zash@zash.se>
parents: 9405
diff changeset
   448
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   449
	line[#line+1] = "("..t_concat(flags, ", ")..")";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   450
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   451
	return t_concat(line, " ");
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   452
end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   453
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   454
local function list_s2s_this_handler(self, data, state)
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   455
	local count_in, count_out = 0, 0;
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   456
	local s2s_list = {};
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   457
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   458
	local s2s_sessions = module:shared"/*/s2s/sessions";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   459
	for _, session in pairs(s2s_sessions) do
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   460
		local remotehost, localhost, direction;
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   461
		if session.direction == "outgoing" then
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   462
			direction = "->";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   463
			count_out = count_out + 1;
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   464
			remotehost, localhost = session.to_host or "?", session.from_host or "?";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   465
		else
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   466
			direction = "<-";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   467
			count_in = count_in + 1;
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   468
			remotehost, localhost = session.from_host or "?", session.to_host or "?";
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   469
		end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   470
		local sess_lines = { r = remotehost,
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   471
			session_flags(session, { "", direction, remotehost or "?" })};
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   472
7048
49e2456bf2ce mod_admin_adhoc: Show only connections to/from the host the command was run on
Kim Alvefur <zash@zash.se>
parents: 7047
diff changeset
   473
		if localhost == module_host then
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   474
			s2s_list[#s2s_list+1] = sess_lines;
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   475
		end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   476
	end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   477
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   478
	t_sort(s2s_list, function(a, b)
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   479
		return a.r < b.r;
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   480
	end);
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   481
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   482
	for i, sess_lines in ipairs(s2s_list) do
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   483
		s2s_list[i] = sess_lines[1];
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   484
	end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   485
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   486
	return { status = "completed", result = { layout = list_s2s_this_result; values = {
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   487
		sessions = t_concat(s2s_list, "\n"),
11876
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   488
		num_in = count_in,
ffff0d8a9c68 mod_admin_adhoc: Move number coercion into util.dataforms
Kim Alvefur <zash@zash.se>
parents: 11731
diff changeset
   489
		num_out = count_out
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   490
	} } };
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   491
end
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   492
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   493
-- Getting a list of loaded modules
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   494
local list_modules_result = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   495
	title = "List of loaded modules";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   496
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   497
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   498
	{ name = "modules", type = "text-multi", label = "The following modules are loaded:" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   499
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   500
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   501
local function list_modules_handler(self, data, state)
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   502
	local modules = array.collect(keys(hosts[module_host].modules)):sort():concat("\n");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   503
	return { status = "completed", result = { layout = list_modules_result; values = { modules = modules } } };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   504
end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   505
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   506
-- Loading a module
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   507
local load_module_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   508
	title = "Load module";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   509
	instructions = "Specify the module to be loaded";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   510
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   511
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#load" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   512
	{ name = "module", type = "text-single", required = true, label = "Module to be loaded:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   513
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   514
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   515
local load_module_handler = adhoc_simple(load_module_layout, function(fields, err)
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   516
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   517
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   518
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   519
	if modulemanager.is_loaded(module_host, fields.module) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   520
		return { status = "completed", info = "Module already loaded" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   521
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   522
	local ok, err = modulemanager.load(module_host, fields.module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   523
	if ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   524
		return { status = "completed", info = 'Module "'..fields.module..'" successfully loaded on host "'..module_host..'".' };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   525
	else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   526
		return { status = "completed", error = { message = 'Failed to load module "'..fields.module..'" on host "'..module_host..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   527
		'". Error was: "'..tostring(err or "<unspecified>")..'"' } };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   528
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   529
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   530
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   531
-- Globally loading a module
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   532
local globally_load_module_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   533
	title = "Globally load module";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   534
	instructions = "Specify the module to be loaded on all hosts";
4932
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
   535
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   536
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-load" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   537
	{ name = "module", type = "text-single", required = true, label = "Module to globally load:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   538
};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   539
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   540
local globally_load_module_handler = adhoc_simple(globally_load_module_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   541
	local ok_list, err_list = {}, {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   542
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   543
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   544
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   545
	end
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   546
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   547
	local ok, err = modulemanager.load(module_host, fields.module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   548
	if ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   549
		ok_list[#ok_list + 1] = module_host;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   550
	else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   551
		err_list[#err_list + 1] = module_host .. " (Error: " .. tostring(err) .. ")";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   552
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   553
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   554
	-- Is this a global module?
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   555
	if modulemanager.is_loaded("*", fields.module) and not modulemanager.is_loaded(module_host, fields.module) then
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   556
		module:log("info", "mod_%s loaded by %s", fields.module, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   557
		return { status = "completed", info = 'Global module '..fields.module..' loaded.' };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   558
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   559
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   560
	-- This is either a shared or "normal" module, load it on all other hosts
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   561
	for host_name, host in pairs(hosts) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   562
		if host_name ~= module_host and host.type == "local" then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   563
			local ok, err = modulemanager.load(host_name, fields.module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   564
			if ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   565
				ok_list[#ok_list + 1] = host_name;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   566
			else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   567
				err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   568
			end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   569
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   570
	end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   571
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   572
	module:log("info", "mod_%s loaded by %s", fields.module, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   573
	local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully loaded onto the hosts:\n"..t_concat(ok_list, "\n")) or "")
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   574
		.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   575
		(#err_list > 0 and ("Failed to load the module "..fields.module.." onto the hosts:\n"..t_concat(err_list, "\n")) or "");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   576
	return { status = "completed", info = info };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   577
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   578
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   579
-- Reloading modules
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   580
local reload_modules_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   581
	title = "Reload modules";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   582
	instructions = "Select the modules to be reloaded";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   583
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   584
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#reload" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   585
	{ name = "modules", type = "list-multi", required = true, label = "Modules to be reloaded:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   586
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   587
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   588
local reload_modules_handler = adhoc_initial(reload_modules_layout, function()
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   589
	return { modules = array.collect(keys(hosts[module_host].modules)):sort() };
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   590
end, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   591
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   592
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   593
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   594
	local ok_list, err_list = {}, {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   595
	for _, module in ipairs(fields.modules) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   596
		local ok, err = modulemanager.reload(module_host, module);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   597
		if ok then
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   598
			ok_list[#ok_list + 1] = module;
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   599
		else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   600
			err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   601
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   602
	end
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   603
	module:log("info", "mod_%s reloaded by %s", fields.module, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   604
	local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..module_host..":\n"..t_concat(ok_list, "\n")) or "")
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   605
		.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   606
		(#err_list > 0 and ("Failed to reload the following modules on host "..module_host..":\n"..t_concat(err_list, "\n")) or "");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   607
	return { status = "completed", info = info };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   608
end);
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   609
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   610
-- Globally reloading a module
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   611
local globally_reload_module_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   612
	title = "Globally reload module";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   613
	instructions = "Specify the module to reload on all hosts";
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   614
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   615
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-reload" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   616
	{ name = "module", type = "list-single", required = true, label = "Module to globally reload:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   617
};
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   618
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   619
local globally_reload_module_handler = adhoc_initial(globally_reload_module_layout, function()
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   620
	local loaded_modules = array(keys(modulemanager.get_modules("*")));
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   621
	for _, host in pairs(hosts) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   622
		loaded_modules:append(array(keys(host.modules)));
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   623
	end
5818
5733a277237a mod_admin_adhoc: As the only user of set:items(), update... it's now an iterator, and the extra keys() iterator is now unnecessary
Matthew Wild <mwild1@gmail.com>
parents: 5721
diff changeset
   624
	loaded_modules = array(set.new(loaded_modules):items()):sort();
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   625
	return { module = loaded_modules };
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   626
end, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   627
	local is_global = false;
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   628
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   629
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   630
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   631
	end
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   632
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   633
	if modulemanager.is_loaded("*", fields.module) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   634
		local ok, err = modulemanager.reload("*", fields.module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   635
		if not ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   636
			return { status = "completed", info = 'Global module '..fields.module..' failed to reload: '..err };
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   637
		end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   638
		is_global = true;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   639
	end
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   640
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   641
	local ok_list, err_list = {}, {};
9402
ec60e74fd9bb mod_admin_adhoc: Remove unused loop variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9089
diff changeset
   642
	for host_name in pairs(hosts) do
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   643
		if modulemanager.is_loaded(host_name, fields.module)  then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   644
			local ok, err = modulemanager.reload(host_name, fields.module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   645
			if ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   646
				ok_list[#ok_list + 1] = host_name;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   647
			else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   648
				err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   649
			end
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   650
		end
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   651
	end
5327
b0c36b043f00 mod_admin_adhoc: Implement global module reloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5326
diff changeset
   652
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   653
	if #ok_list == 0 and #err_list == 0 then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   654
		if is_global then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   655
			return { status = "completed", info = 'Successfully reloaded global module '..fields.module };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   656
		else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   657
			return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
5327
b0c36b043f00 mod_admin_adhoc: Implement global module reloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5326
diff changeset
   658
		end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   659
	end
5327
b0c36b043f00 mod_admin_adhoc: Implement global module reloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5326
diff changeset
   660
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   661
	module:log("info", "mod_%s reloaded by %s", fields.module, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   662
	local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully reloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   663
		.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   664
		(#err_list > 0 and ("Failed to reload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   665
	return { status = "completed", info = info };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   666
end);
5327
b0c36b043f00 mod_admin_adhoc: Implement global module reloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5326
diff changeset
   667
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   668
local function send_to_online(message, server)
6799
87ec4e783ebd mod_admin_adhoc: Declare local variable, don't set a global [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6798
diff changeset
   669
	local sessions;
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   670
	if server then
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   671
		sessions = { [server] = hosts[server] };
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   672
	else
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   673
		sessions = hosts;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   674
	end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   675
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   676
	local c = 0;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   677
	for domain, session in pairs(sessions) do
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   678
		for user in pairs(session.sessions or {}) do
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   679
			c = c + 1;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   680
			message.attr.from = domain;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   681
			message.attr.to = user.."@"..domain;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   682
			core_post_stanza(session, message);
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   683
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   684
	end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   685
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   686
	return c;
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   687
end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   688
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   689
-- Shutting down the service
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   690
local shut_down_service_layout = dataforms_new{
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   691
	title = "Shutting Down the Service";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   692
	instructions = "Fill out this form to shut down the service.";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   693
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   694
	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   695
	{ name = "delay", type = "list-single", label = "Time delay before shutting down",
9088
9bd38bbf8623 mod_admin_adhoc: Keep options for list-single in 'options' field where they belong
Kim Alvefur <zash@zash.se>
parents: 8776
diff changeset
   696
		value = "5",
9bd38bbf8623 mod_admin_adhoc: Keep options for list-single in 'options' field where they belong
Kim Alvefur <zash@zash.se>
parents: 8776
diff changeset
   697
		options = {
9089
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   698
			{label =  "5 seconds", value = "5"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   699
			{label = "30 seconds", value = "30"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   700
			{label = "60 seconds", value = "60"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   701
			{label = "90 seconds", value = "90"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   702
			{label = "2 minutes", value = "120"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   703
			{label = "3 minutes", value = "180"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   704
			{label = "4 minutes", value = "240"},
74b4be5afb74 mod_admin_adhoc: Normalize indentation
Kim Alvefur <zash@zash.se>
parents: 9088
diff changeset
   705
			{label = "5 minutes", value = "300"},
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   706
		};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   707
	};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   708
	{ name = "announcement", type = "text-multi", label = "Announcement" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   709
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   710
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   711
local shut_down_service_handler = adhoc_simple(shut_down_service_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   712
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   713
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   714
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   715
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   716
	module:log("info", "Server being shut down by %s", jid.bare(data.from));
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   717
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   718
	if fields.announcement and #fields.announcement > 0 then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   719
		local message = st.message({type = "headline"}, fields.announcement):up()
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   720
			:tag("subject"):text("Server is shutting down");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   721
		send_to_online(message);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   722
	end
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   723
9403
9ef746c2a644 mod_admin_adhoc: Remove unused argument [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9402
diff changeset
   724
	timer_add_task(tonumber(fields.delay or "5"), function() prosody.shutdown("Shutdown by adhoc command") end);
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   725
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   726
	return { status = "completed", info = "Server is about to shut down" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   727
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   728
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   729
-- Unloading modules
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   730
local unload_modules_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   731
	title = "Unload modules";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   732
	instructions = "Select the modules to be unloaded";
4932
212e81ac6ebb mod_admin_web: Use util.dataforms' own error checking
Florian Zeitz <florob@babelmonkeys.de>
parents: 4926
diff changeset
   733
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   734
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#unload" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   735
	{ name = "modules", type = "list-multi", required = true, label = "Modules to be unloaded:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   736
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   737
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   738
local unload_modules_handler = adhoc_initial(unload_modules_layout, function()
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   739
	return { modules = array.collect(keys(hosts[module_host].modules)):sort() };
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   740
end, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   741
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   742
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   743
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   744
	local ok_list, err_list = {}, {};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   745
	for _, module in ipairs(fields.modules) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   746
		local ok, err = modulemanager.unload(module_host, module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   747
		if ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   748
			ok_list[#ok_list + 1] = module;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   749
		else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   750
			err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   751
		end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   752
	end
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   753
	module:log("info", "mod_%s unloaded by %s", fields.module, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   754
	local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..module_host..":\n"..t_concat(ok_list, "\n")) or "")
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   755
		.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   756
		(#err_list > 0 and ("Failed to unload the following modules on host "..module_host..":\n"..t_concat(err_list, "\n")) or "");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   757
	return { status = "completed", info = info };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   758
end);
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   759
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   760
-- Globally unloading a module
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   761
local globally_unload_module_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   762
	title = "Globally unload module";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   763
	instructions = "Specify a module to unload on all hosts";
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   764
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   765
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#global-unload" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   766
	{ name = "module", type = "list-single", required = true, label = "Module to globally unload:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   767
};
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   768
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   769
local globally_unload_module_handler = adhoc_initial(globally_unload_module_layout, function()
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   770
	local loaded_modules = array(keys(modulemanager.get_modules("*")));
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   771
	for _, host in pairs(hosts) do
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   772
		loaded_modules:append(array(keys(host.modules)));
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   773
	end
5818
5733a277237a mod_admin_adhoc: As the only user of set:items(), update... it's now an iterator, and the extra keys() iterator is now unnecessary
Matthew Wild <mwild1@gmail.com>
parents: 5721
diff changeset
   774
	loaded_modules = array(set.new(loaded_modules):items()):sort();
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   775
	return { module = loaded_modules };
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   776
end, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   777
	local is_global = false;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   778
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   779
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   780
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   781
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   782
	if modulemanager.is_loaded("*", fields.module) then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   783
		local ok, err = modulemanager.unload("*", fields.module);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   784
		if not ok then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   785
			return { status = "completed", info = 'Global module '..fields.module..' failed to unload: '..err };
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   786
		end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   787
		is_global = true;
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   788
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   789
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   790
	local ok_list, err_list = {}, {};
9402
ec60e74fd9bb mod_admin_adhoc: Remove unused loop variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9089
diff changeset
   791
	for host_name in pairs(hosts) do
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   792
		if modulemanager.is_loaded(host_name, fields.module)  then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   793
			local ok, err = modulemanager.unload(host_name, fields.module);
3778
bd1845f9d5a4 mod_admin_adhoc: Support unloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3777
diff changeset
   794
			if ok then
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   795
				ok_list[#ok_list + 1] = host_name;
3778
bd1845f9d5a4 mod_admin_adhoc: Support unloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3777
diff changeset
   796
			else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   797
				err_list[#err_list + 1] = host_name .. " (Error: " .. tostring(err) .. ")";
3778
bd1845f9d5a4 mod_admin_adhoc: Support unloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3777
diff changeset
   798
			end
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   799
		end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   800
	end
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   801
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   802
	if #ok_list == 0 and #err_list == 0 then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   803
		if is_global then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   804
			return { status = "completed", info = 'Successfully unloaded global module '..fields.module };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   805
		else
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   806
			return { status = "completed", info = 'Module '..fields.module..' not loaded on any host.' };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   807
		end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   808
	end
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   809
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   810
	module:log("info", "mod_%s globally unloaded by %s", fields.module, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   811
	local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully unloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   812
		.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   813
		(#err_list > 0 and ("Failed to unload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   814
	return { status = "completed", info = info };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   815
end);
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   816
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   817
-- Activating a host
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   818
local activate_host_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   819
	title = "Activate host";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   820
	instructions = "";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   821
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   822
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   823
	{ name = "host", type = "text-single", required = true, label = "Host:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   824
};
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   825
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   826
local activate_host_handler = adhoc_simple(activate_host_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   827
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   828
		return generate_error_message(err);
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   829
	end
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   830
	local ok, err = hostmanager_activate(fields.host);
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   831
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   832
	if ok then
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   833
		module:log("info", "Host '%s' activated by %s", fields.host, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   834
		return { status = "completed", info = fields.host .. " activated" };
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   835
	else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   836
		return { status = "canceled", error = err }
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   837
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   838
end);
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   839
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   840
-- Deactivating a host
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   841
local deactivate_host_layout = dataforms_new {
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   842
	title = "Deactivate host";
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   843
	instructions = "";
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   844
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   845
	{ name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/hosts#activate" };
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   846
	{ name = "host", type = "text-single", required = true, label = "Host:"};
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   847
};
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   848
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   849
local deactivate_host_handler = adhoc_simple(deactivate_host_layout, function(fields, err, data)
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   850
	if err then
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   851
		return generate_error_message(err);
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   852
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   853
	local ok, err = hostmanager_deactivate(fields.host);
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   854
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   855
	if ok then
11637
77e38ea34d82 mod_admin_adhoc: Log who performs administrative actions
Kim Alvefur <zash@zash.se>
parents: 11636
diff changeset
   856
		module:log("info", "Host '%s' deactivated by %s", fields.host, jid.bare(data.from));
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   857
		return { status = "completed", info = fields.host .. " deactivated" };
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   858
	else
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   859
		return { status = "canceled", error = err }
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   860
	end
5514
1091d7c3b4d2 mod_admin_adhoc: Use util.adhoc
Florian Zeitz <florob@babelmonkeys.de>
parents: 5371
diff changeset
   861
end);
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   862
9405
b530b5daae91 mod_admin_adhoc: Ignore the very long lines at the end [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9404
diff changeset
   863
-- luacheck: max_line_length 180
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   864
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   865
local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin");
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   866
local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin");
4292
894ffea639e9 mod_admin_adhoc: Add "Reload configuration" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 3778
diff changeset
   867
local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin");
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   868
local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
12914
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   869
local disable_user_desc = adhoc_new("Disable User", "http://jabber.org/protocol/admin#disable-user", disable_user_command_handler, "admin");
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   870
local enable_user_desc = adhoc_new("Re-Enable User", "http://jabber.org/protocol/admin#reenable-user", enable_user_command_handler, "admin");
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   871
local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   872
local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   873
local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
5721
579c51cbc12c mod_admin_adhoc: Fix node of the "Get List of Online Users" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 5514
diff changeset
   874
local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users-list", get_online_users_command_handler, "admin");
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   875
local list_s2s_this_desc = adhoc_new("List S2S connections", "http://prosody.im/protocol/s2s#list", list_s2s_this_handler, "admin");
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   876
local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin");
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   877
local load_module_desc = adhoc_new("Load module", "http://prosody.im/protocol/modules#load", load_module_handler, "admin");
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   878
local globally_load_module_desc = adhoc_new("Globally load module", "http://prosody.im/protocol/modules#global-load", globally_load_module_handler, "global_admin");
3777
5ecbcef42ffb mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3540
diff changeset
   879
local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/protocol/modules#reload", reload_modules_handler, "admin");
5327
b0c36b043f00 mod_admin_adhoc: Implement global module reloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5326
diff changeset
   880
local globally_reload_module_desc = adhoc_new("Globally reload module", "http://prosody.im/protocol/modules#global-reload", globally_reload_module_handler, "global_admin");
4296
b991ffa0f2c5 mod_admin_adhoc: Only allow global admins to shut the server down
Florian Zeitz <florob@babelmonkeys.de>
parents: 4292
diff changeset
   881
local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin");
3778
bd1845f9d5a4 mod_admin_adhoc: Support unloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3777
diff changeset
   882
local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin");
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   883
local globally_unload_module_desc = adhoc_new("Globally unload module", "http://prosody.im/protocol/modules#global-unload", globally_unload_module_handler, "global_admin");
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   884
local activate_host_desc = adhoc_new("Activate host", "http://prosody.im/protocol/hosts#activate", activate_host_handler, "global_admin");
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   885
local deactivate_host_desc = adhoc_new("Deactivate host", "http://prosody.im/protocol/hosts#deactivate", deactivate_host_handler, "global_admin");
3487
b5c92275910b mod_admin_adhoc: New module with merged functonality of mod_adhoc_cmd_admin and mod_adhoc_cmd_modules (of prosody-modules fame)
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   886
4926
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   887
module:provides("adhoc", add_user_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   888
module:provides("adhoc", change_user_password_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   889
module:provides("adhoc", config_reload_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   890
module:provides("adhoc", delete_user_desc);
12914
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   891
module:provides("adhoc", disable_user_desc);
5c90862e39aa mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Kim Alvefur <zash@zash.se>
parents: 11876
diff changeset
   892
module:provides("adhoc", enable_user_desc);
4926
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   893
module:provides("adhoc", end_user_session_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   894
module:provides("adhoc", get_user_roster_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   895
module:provides("adhoc", get_user_stats_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   896
module:provides("adhoc", get_online_users_desc);
6461
f906b803dc42 mod_admin_web: Add "List S2S connections" command
Florian Zeitz <florob@babelmonkeys.de>
parents: 6460
diff changeset
   897
module:provides("adhoc", list_s2s_this_desc);
4926
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   898
module:provides("adhoc", list_modules_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   899
module:provides("adhoc", load_module_desc);
5325
97bf651e32a4 mod_admin_adhoc: Implement global module loading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5324
diff changeset
   900
module:provides("adhoc", globally_load_module_desc);
4926
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   901
module:provides("adhoc", reload_modules_desc);
5327
b0c36b043f00 mod_admin_adhoc: Implement global module reloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5326
diff changeset
   902
module:provides("adhoc", globally_reload_module_desc);
4926
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   903
module:provides("adhoc", shut_down_service_desc);
58714123f600 mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands
Florian Zeitz <florob@babelmonkeys.de>
parents: 4780
diff changeset
   904
module:provides("adhoc", unload_modules_desc);
5328
5e15e6700412 mod_admin_adhoc: Implement global module unloading
Florian Zeitz <florob@babelmonkeys.de>
parents: 5327
diff changeset
   905
module:provides("adhoc", globally_unload_module_desc);
5135
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   906
module:provides("adhoc", activate_host_desc);
52eafe0e9772 mod_admin_adhoc: Add commands for activating and deactivating hosts
Kim Alvefur <zash@zash.se>
parents: 5100
diff changeset
   907
module:provides("adhoc", deactivate_host_desc);