aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_admin_adhoc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_admin_adhoc.lua')
-rw-r--r--plugins/mod_admin_adhoc.lua98
1 files changed, 43 insertions, 55 deletions
diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua
index 37e77ab0..1471fba0 100644
--- a/plugins/mod_admin_adhoc.lua
+++ b/plugins/mod_admin_adhoc.lua
@@ -18,7 +18,6 @@ local keys = require "util.iterators".keys;
local usermanager_user_exists = require "core.usermanager".user_exists;
local usermanager_create_user = require "core.usermanager".create_user;
local usermanager_delete_user = require "core.usermanager".delete_user;
-local usermanager_get_password = require "core.usermanager".get_password;
local usermanager_set_password = require "core.usermanager".set_password;
local hostmanager_activate = require "core.hostmanager".activate;
local hostmanager_deactivate = require "core.hostmanager".deactivate;
@@ -55,11 +54,11 @@ local add_user_layout = dataforms_new{
{ name = "password-verify", type = "text-private", label = "Retype password" };
};
-local add_user_command_handler = adhoc_simple(add_user_layout, function(fields, err)
+local add_user_command_handler = adhoc_simple(add_user_layout, function(fields, err, data)
if err then
return generate_error_message(err);
end
- local username, host, resource = jid.split(fields.accountjid);
+ local username, host = jid.split(fields.accountjid);
if module_host ~= host then
return { status = "completed", error = { message = "Trying to add a user on " .. host .. " but command was sent to " .. module_host}};
end
@@ -68,7 +67,7 @@ local add_user_command_handler = adhoc_simple(add_user_layout, function(fields,
return { status = "completed", error = { message = "Account already exists" } };
else
if usermanager_create_user(username, fields.password, host) then
- module:log("info", "Created new account %s@%s", username, host);
+ module:log("info", "Created new account %s@%s by %s", username, host, jid.bare(data.from));
return { status = "completed", info = "Account successfully created" };
else
return { status = "completed", error = { message = "Failed to write data to disk" } };
@@ -90,11 +89,11 @@ local change_user_password_layout = dataforms_new{
{ name = "password", type = "text-private", required = true, label = "The password for this account" };
};
-local change_user_password_command_handler = adhoc_simple(change_user_password_layout, function(fields, err)
+local change_user_password_command_handler = adhoc_simple(change_user_password_layout, function(fields, err, data)
if err then
return generate_error_message(err);
end
- local username, host, resource = jid.split(fields.accountjid);
+ local username, host = jid.split(fields.accountjid);
if module_host ~= host then
return {
status = "completed",
@@ -104,6 +103,7 @@ local change_user_password_command_handler = adhoc_simple(change_user_password_l
};
end
if usermanager_user_exists(username, host) and usermanager_set_password(username, fields.password, host, nil) then
+ module:log("info", "Password of account %s@%s changed by %s", username, host, jid.bare(data.from));
return { status = "completed", info = "Password successfully changed" };
else
return { status = "completed", error = { message = "User does not exist" } };
@@ -112,6 +112,7 @@ end);
-- Reloading the config
local function config_reload_handler(self, data, state)
+ module:log("info", "%s reloads the config", jid.bare(data.from));
local ok, err = prosody.reload_config();
if ok then
return { status = "completed", info = "Configuration reloaded (modules may need to be reloaded for this to have an effect)" };
@@ -129,19 +130,19 @@ local delete_user_layout = dataforms_new{
{ name = "accountjids", type = "jid-multi", required = true, label = "The Jabber ID(s) to delete" };
};
-local delete_user_command_handler = adhoc_simple(delete_user_layout, function(fields, err)
+local delete_user_command_handler = adhoc_simple(delete_user_layout, function(fields, err, data)
if err then
return generate_error_message(err);
end
local failed = {};
local succeeded = {};
for _, aJID in ipairs(fields.accountjids) do
- local username, host, resource = jid.split(aJID);
+ local username, host = jid.split(aJID);
if (host == module_host) and usermanager_user_exists(username, host) and usermanager_delete_user(username, host) then
- module:log("debug", "User %s has been deleted", aJID);
+ module:log("info", "User %s has been deleted by %s", aJID, jid.bare(data.from));
succeeded[#succeeded+1] = aJID;
else
- module:log("debug", "Tried to delete non-existant user %s", aJID);
+ module:log("debug", "Tried to delete non-existent user %s", aJID);
failed[#failed+1] = aJID;
end
end
@@ -180,7 +181,7 @@ local end_user_session_handler = adhoc_simple(end_user_session_layout, function(
local failed = {};
local succeeded = {};
for _, aJID in ipairs(fields.accountjids) do
- local username, host, resource = jid.split(aJID);
+ local username, host = jid.split(aJID);
if (host == module_host) and usermanager_user_exists(username, host) and disconnect_user(aJID) then
succeeded[#succeeded+1] = aJID;
else
@@ -193,39 +194,6 @@ local end_user_session_handler = adhoc_simple(end_user_session_layout, function(
"The following accounts could not be disconnected:\n"..t_concat(failed, "\n") or "") };
end);
--- Getting a user's password
-local get_user_password_layout = dataforms_new{
- title = "Getting User's Password";
- instructions = "Fill out this form to get a user's password.";
-
- { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
- { name = "accountjid", type = "jid-single", required = true, label = "The Jabber ID for which to retrieve the password" };
-};
-
-local get_user_password_result_layout = dataforms_new{
- { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
- { name = "accountjid", type = "jid-single", label = "JID" };
- { name = "password", type = "text-single", label = "Password" };
-};
-
-local get_user_password_handler = adhoc_simple(get_user_password_layout, function(fields, err)
- if err then
- return generate_error_message(err);
- end
- local user, host, resource = jid.split(fields.accountjid);
- local accountjid;
- local password;
- if host ~= module_host then
- return { status = "completed", error = { message = "Tried to get password for a user on " .. host .. " but command was sent to " .. module_host } };
- elseif usermanager_user_exists(user, host) then
- accountjid = fields.accountjid;
- password = usermanager_get_password(user, host);
- else
- return { status = "completed", error = { message = "User does not exist" } };
- end
- return { status = "completed", result = { layout = get_user_password_result_layout, values = {accountjid = accountjid, password = password} } };
-end);
-
-- Getting a user's roster
local get_user_roster_layout = dataforms_new{
{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
@@ -243,7 +211,7 @@ local get_user_roster_handler = adhoc_simple(get_user_roster_layout, function(fi
return generate_error_message(err);
end
- local user, host, resource = jid.split(fields.accountjid);
+ local user, host = jid.split(fields.accountjid);
if host ~= module_host then
return { status = "completed", error = { message = "Tried to get roster for a user on " .. host .. " but command was sent to " .. module_host } };
elseif not usermanager_user_exists(user, host) then
@@ -392,6 +360,12 @@ local function session_flags(session, line)
if session.cert_identity_status == "valid" then
flags[#flags+1] = "authenticated";
end
+ if session.dialback_key then
+ flags[#flags+1] = "dialback";
+ end
+ if session.external_auth then
+ flags[#flags+1] = "SASL";
+ end
if session.secure then
flags[#flags+1] = "encrypted";
end
@@ -404,6 +378,12 @@ local function session_flags(session, line)
if session.ip and session.ip:match(":") then
flags[#flags+1] = "IPv6";
end
+ if session.incoming and session.outgoing then
+ flags[#flags+1] = "bidi";
+ elseif session.is_bidi or session.bidi_session then
+ flags[#flags+1] = "bidi";
+ end
+
line[#line+1] = "("..t_concat(flags, ", ")..")";
return t_concat(line, " ");
@@ -495,7 +475,7 @@ local globally_load_module_layout = dataforms_new {
{ name = "module", type = "text-single", required = true, label = "Module to globally load:"};
};
-local globally_load_module_handler = adhoc_simple(globally_load_module_layout, function(fields, err)
+local globally_load_module_handler = adhoc_simple(globally_load_module_layout, function(fields, err, data)
local ok_list, err_list = {}, {};
if err then
@@ -511,6 +491,7 @@ local globally_load_module_handler = adhoc_simple(globally_load_module_layout, f
-- Is this a global module?
if modulemanager.is_loaded("*", fields.module) and not modulemanager.is_loaded(module_host, fields.module) then
+ module:log("info", "mod_%s loaded by %s", fields.module, jid.bare(data.from));
return { status = "completed", info = 'Global module '..fields.module..' loaded.' };
end
@@ -526,6 +507,7 @@ local globally_load_module_handler = adhoc_simple(globally_load_module_layout, f
end
end
+ module:log("info", "mod_%s loaded by %s", fields.module, jid.bare(data.from));
local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully loaded onto the hosts:\n"..t_concat(ok_list, "\n")) or "")
.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
(#err_list > 0 and ("Failed to load the module "..fields.module.." onto the hosts:\n"..t_concat(err_list, "\n")) or "");
@@ -543,7 +525,7 @@ local reload_modules_layout = dataforms_new {
local reload_modules_handler = adhoc_initial(reload_modules_layout, function()
return { modules = array.collect(keys(hosts[module_host].modules)):sort() };
-end, function(fields, err)
+end, function(fields, err, data)
if err then
return generate_error_message(err);
end
@@ -556,6 +538,7 @@ end, function(fields, err)
err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
end
end
+ module:log("info", "mod_%s reloaded by %s", fields.module, jid.bare(data.from));
local info = (#ok_list > 0 and ("The following modules were successfully reloaded on host "..module_host..":\n"..t_concat(ok_list, "\n")) or "")
.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
(#err_list > 0 and ("Failed to reload the following modules on host "..module_host..":\n"..t_concat(err_list, "\n")) or "");
@@ -578,7 +561,7 @@ local globally_reload_module_handler = adhoc_initial(globally_reload_module_layo
end
loaded_modules = array(set.new(loaded_modules):items()):sort();
return { module = loaded_modules };
-end, function(fields, err)
+end, function(fields, err, data)
local is_global = false;
if err then
@@ -613,6 +596,7 @@ end, function(fields, err)
end
end
+ module:log("info", "mod_%s reloaded by %s", fields.module, jid.bare(data.from));
local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully reloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
(#err_list > 0 and ("Failed to reload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
@@ -662,11 +646,13 @@ local shut_down_service_layout = dataforms_new{
{ name = "announcement", type = "text-multi", label = "Announcement" };
};
-local shut_down_service_handler = adhoc_simple(shut_down_service_layout, function(fields, err)
+local shut_down_service_handler = adhoc_simple(shut_down_service_layout, function(fields, err, data)
if err then
return generate_error_message(err);
end
+ module:log("info", "Server being shut down by %s", jid.bare(data.from));
+
if fields.announcement and #fields.announcement > 0 then
local message = st.message({type = "headline"}, fields.announcement):up()
:tag("subject"):text("Server is shutting down");
@@ -689,7 +675,7 @@ local unload_modules_layout = dataforms_new {
local unload_modules_handler = adhoc_initial(unload_modules_layout, function()
return { modules = array.collect(keys(hosts[module_host].modules)):sort() };
-end, function(fields, err)
+end, function(fields, err, data)
if err then
return generate_error_message(err);
end
@@ -702,6 +688,7 @@ end, function(fields, err)
err_list[#err_list + 1] = module .. "(Error: " .. tostring(err) .. ")";
end
end
+ module:log("info", "mod_%s unloaded by %s", fields.module, jid.bare(data.from));
local info = (#ok_list > 0 and ("The following modules were successfully unloaded on host "..module_host..":\n"..t_concat(ok_list, "\n")) or "")
.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
(#err_list > 0 and ("Failed to unload the following modules on host "..module_host..":\n"..t_concat(err_list, "\n")) or "");
@@ -724,7 +711,7 @@ local globally_unload_module_handler = adhoc_initial(globally_unload_module_layo
end
loaded_modules = array(set.new(loaded_modules):items()):sort();
return { module = loaded_modules };
-end, function(fields, err)
+end, function(fields, err, data)
local is_global = false;
if err then
return generate_error_message(err);
@@ -758,6 +745,7 @@ end, function(fields, err)
end
end
+ module:log("info", "mod_%s globally unloaded by %s", fields.module, jid.bare(data.from));
local info = (#ok_list > 0 and ("The module "..fields.module.." was successfully unloaded on the hosts:\n"..t_concat(ok_list, "\n")) or "")
.. ((#ok_list > 0 and #err_list > 0) and "\n" or "") ..
(#err_list > 0 and ("Failed to unload the module "..fields.module.." on the hosts:\n"..t_concat(err_list, "\n")) or "");
@@ -773,13 +761,14 @@ local activate_host_layout = dataforms_new {
{ name = "host", type = "text-single", required = true, label = "Host:"};
};
-local activate_host_handler = adhoc_simple(activate_host_layout, function(fields, err)
+local activate_host_handler = adhoc_simple(activate_host_layout, function(fields, err, data)
if err then
return generate_error_message(err);
end
local ok, err = hostmanager_activate(fields.host);
if ok then
+ module:log("info", "Host '%s' activated by %s", fields.host, jid.bare(data.from));
return { status = "completed", info = fields.host .. " activated" };
else
return { status = "canceled", error = err }
@@ -795,13 +784,14 @@ local deactivate_host_layout = dataforms_new {
{ name = "host", type = "text-single", required = true, label = "Host:"};
};
-local deactivate_host_handler = adhoc_simple(deactivate_host_layout, function(fields, err)
+local deactivate_host_handler = adhoc_simple(deactivate_host_layout, function(fields, err, data)
if err then
return generate_error_message(err);
end
local ok, err = hostmanager_deactivate(fields.host);
if ok then
+ module:log("info", "Host '%s' deactivated by %s", fields.host, jid.bare(data.from));
return { status = "completed", info = fields.host .. " deactivated" };
else
return { status = "canceled", error = err }
@@ -815,7 +805,6 @@ local change_user_password_desc = adhoc_new("Change User Password", "http://jabb
local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin");
local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin");
local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin");
-local get_user_password_desc = adhoc_new("Get User Password", "http://jabber.org/protocol/admin#get-user-password", get_user_password_handler, "admin");
local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin");
local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin");
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");
@@ -836,7 +825,6 @@ module:provides("adhoc", change_user_password_desc);
module:provides("adhoc", config_reload_desc);
module:provides("adhoc", delete_user_desc);
module:provides("adhoc", end_user_session_desc);
-module:provides("adhoc", get_user_password_desc);
module:provides("adhoc", get_user_roster_desc);
module:provides("adhoc", get_user_stats_desc);
module:provides("adhoc", get_online_users_desc);