From f76c2aa90b3cc7ba714571448865fcb30d63ef78 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Tue, 12 Jun 2012 14:29:04 +0200 Subject: mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands --- plugins/mod_admin_adhoc.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'plugins/mod_admin_adhoc.lua') diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index 4d2c60d7..b8cb0637 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -605,17 +605,17 @@ local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/proto local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); -module:add_item("adhoc", add_user_desc); -module:add_item("adhoc", change_user_password_desc); -module:add_item("adhoc", config_reload_desc); -module:add_item("adhoc", delete_user_desc); -module:add_item("adhoc", end_user_session_desc); -module:add_item("adhoc", get_user_password_desc); -module:add_item("adhoc", get_user_roster_desc); -module:add_item("adhoc", get_user_stats_desc); -module:add_item("adhoc", get_online_users_desc); -module:add_item("adhoc", list_modules_desc); -module:add_item("adhoc", load_module_desc); -module:add_item("adhoc", reload_modules_desc); -module:add_item("adhoc", shut_down_service_desc); -module:add_item("adhoc", unload_modules_desc); +module:provides("adhoc", add_user_desc); +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); +module:provides("adhoc", list_modules_desc); +module:provides("adhoc", load_module_desc); +module:provides("adhoc", reload_modules_desc); +module:provides("adhoc", shut_down_service_desc); +module:provides("adhoc", unload_modules_desc); -- cgit v1.2.3 From bb7fd8bb306ea2d2893bb7c5bc460ec2f9886687 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Thu, 5 Jul 2012 00:15:49 +0200 Subject: mod_admin_web: Use util.dataforms' own error checking --- plugins/mod_admin_adhoc.lua | 84 +++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 34 deletions(-) (limited to 'plugins/mod_admin_adhoc.lua') diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index b8cb0637..efb7f72b 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -27,6 +27,14 @@ local modulemanager = require "modulemanager"; module:depends("adhoc"); local adhoc_new = module:require "adhoc".new; +local function generate_error_message(errors) + local errmsg = {}; + for name, err in pairs(errors) do + errmsg[#errmsg + 1] = name .. ": " .. err; + end + return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; +end + function add_user_command_handler(self, data, state) local add_user_layout = dataforms_new{ title = "Adding a User"; @@ -42,9 +50,9 @@ function add_user_command_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = add_user_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "You need to specify a JID." } }; + local fields, err = add_user_layout:data(data.form); + if err then + return generate_error_message(err); end local username, host, resource = jid.split(fields.accountjid); if data.to ~= host then @@ -85,9 +93,9 @@ function change_user_password_command_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = change_user_password_layout:data(data.form); - if not fields.accountjid or fields.accountjid == "" or not fields.password then - return { status = "completed", error = { message = "Please specify username and password" } }; + local fields, err = change_user_password_layout:data(data.form); + if err then + return generate_error_message(err); end local username, host, resource = jid.split(fields.accountjid); if data.to ~= host then @@ -126,7 +134,10 @@ function delete_user_command_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = delete_user_layout:data(data.form); + local fields, err = delete_user_layout:data(data.form); + if err then + return generate_error_message(err); + end local failed = {}; local succeeded = {}; for _, aJID in ipairs(fields.accountjids) do @@ -175,7 +186,10 @@ function end_user_session_handler(self, data, state) return { status = "canceled" }; end - local fields = end_user_session_layout:data(data.form); + local fields, err = end_user_session_layout:data(data.form); + if err then + return generate_error_message(err); + end local failed = {}; local succeeded = {}; for _, aJID in ipairs(fields.accountjids) do @@ -223,9 +237,9 @@ function get_user_password_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = get_user_password_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "Please specify a JID." } }; + local fields, err = get_user_password_layout:data(data.form); + if err then + return generate_error_message(err); end local user, host, resource = jid.split(fields.accountjid); local accountjid = ""; @@ -261,10 +275,10 @@ function get_user_roster_handler(self, data, state) return { status = "canceled" }; end - local fields = get_user_roster_layout:data(data.form); + local fields, err = get_user_roster_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "Please specify a JID" } }; + if err then + return generate_error_message(err); end local user, host, resource = jid.split(fields.accountjid); @@ -323,10 +337,10 @@ function get_user_stats_handler(self, data, state) return { status = "canceled" }; end - local fields = get_user_stats_layout:data(data.form); + local fields, err = get_user_stats_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "Please specify a JID." } }; + if err then + return generate_error_message(err); end local user, host, resource = jid.split(fields.accountjid); @@ -376,7 +390,11 @@ function get_online_users_command_handler(self, data, state) return { status = "canceled" }; end - local fields = get_online_users_layout:data(data.form); + local fields, err = get_online_users_layout:data(data.form); + + if err then + return generate_error_message(err); + end local max_items = nil if fields.max_items ~= "all" then @@ -436,11 +454,9 @@ function load_module_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = layout:data(data.form); - if (not fields.module) or (fields.module == "") then - return { status = "completed", error = { - message = "Please specify a module." - } }; + local fields, err = layout:data(data.form); + if err then + return generate_error_message(err); end if modulemanager.is_loaded(data.to, fields.module) then return { status = "completed", info = "Module already loaded" }; @@ -470,11 +486,9 @@ function reload_modules_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = layout:data(data.form); - if #fields.modules == 0 then - return { status = "completed", error = { - message = "Please specify a module. (This means your client misbehaved, as this field is required)" - } }; + local fields, err = layout:data(data.form); + if err then + return generate_error_message(err); end local ok_list, err_list = {}, {}; for _, module in ipairs(fields.modules) do @@ -538,7 +552,11 @@ function shut_down_service_handler(self, data, state) return { status = "canceled" }; end - local fields = shut_down_service_layout:data(data.form); + local fields, err = shut_down_service_layout:data(data.form); + + if err then + return generate_error_message(err); + end if fields.announcement and #fields.announcement > 0 then local message = st.message({type = "headline"}, fields.announcement):up() @@ -566,11 +584,9 @@ function unload_modules_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = layout:data(data.form); - if #fields.modules == 0 then - return { status = "completed", error = { - message = "Please specify a module. (This means your client misbehaved, as this field is required)" - } }; + local fields, err = layout:data(data.form); + if err then + return generate_error_message(err); end local ok_list, err_list = {}, {}; for _, module in ipairs(fields.modules) do -- cgit v1.2.3 From f4719b66bc5ed4391b93fb5931a256c1b21fbf1a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 19 Jul 2012 15:36:16 +0100 Subject: mod_admin_adhoc: Remove unused variable and save a bit of CPU... --- plugins/mod_admin_adhoc.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'plugins/mod_admin_adhoc.lua') diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index b8cb0637..80fca4b7 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -453,7 +453,6 @@ function load_module_handler(self, data, state) '". Error was: "'..tostring(err or "")..'"' } }; end else - local modules = array.collect(keys(hosts[data.to].modules)):sort(); return { status = "executing", form = layout }, "executing"; end end -- cgit v1.2.3 From e89b006f03f692a7e807c54757f0623302c40b85 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 17:32:33 +0100 Subject: Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages --- plugins/mod_admin_adhoc.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'plugins/mod_admin_adhoc.lua') diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index ee89d84f..016eeb4a 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -63,15 +63,14 @@ function add_user_command_handler(self, data, state) return { status = "completed", error = { message = "Account already exists" } }; else if usermanager_create_user(username, fields.password, host) then - module:log("info", "Created new account " .. username.."@"..host); + module:log("info", "Created new account %s@%s", username, host); return { status = "completed", info = "Account successfully created" }; else return { status = "completed", error = { message = "Failed to write data to disk" } }; end end else - module:log("debug", (fields.accountjid or "") .. " " .. (fields.password or "") .. " " - .. (fields["password-verify"] or "")); + module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or ""); return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } }; end else @@ -143,10 +142,10 @@ function delete_user_command_handler(self, data, state) for _, aJID in ipairs(fields.accountjids) do local username, host, resource = jid.split(aJID); if (host == data.to) and usermanager_user_exists(username, host) and disconnect_user(aJID) and usermanager_create_user(username, nil, host) then - module:log("debug", "User " .. aJID .. " has been deleted"); + module:log("debug", "User %s has been deleted", aJID); succeeded[#succeeded+1] = aJID; else - module:log("debug", "Tried to delete non-existant user "..aJID); + module:log("debug", "Tried to delete non-existant user %s", aJID); failed[#failed+1] = aJID; end end @@ -165,7 +164,7 @@ function disconnect_user(match_jid) local sessions = host.sessions[node] and host.sessions[node].sessions; for resource, session in pairs(sessions or {}) do if not givenResource or (resource == givenResource) then - module:log("debug", "Disconnecting "..node.."@"..hostname.."/"..resource); + module:log("debug", "Disconnecting %s@%s/%s", node, hostname, resource); session:close(); end end -- cgit v1.2.3 From 9114e88ee0cf86ca0ffe500e089389e54bb730ec Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 04:33:17 +0200 Subject: 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. --- plugins/mod_admin_adhoc.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_admin_adhoc.lua') diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index 016eeb4a..50493abe 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -23,6 +23,7 @@ local timer_add_task = require "util.timer".add_task; local dataforms_new = require "util.dataforms".new; local array = require "util.array"; local modulemanager = require "modulemanager"; +local core_post_stanza = prosody.core_post_stanza; module:depends("adhoc"); local adhoc_new = module:require "adhoc".new; -- cgit v1.2.3