From 8d8c6bd619ded1b202ebd19bda33bde475c4c37d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 10 Jan 2019 14:57:26 +0100 Subject: util.prosodyctl: Allow passing path to Lua runtime to the start() function By default the shebang is used. Being able to override it is useful in cases where the shebang does not match the configured runtime. --- util/prosodyctl.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 5f0c4d12..9b627bde 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -229,7 +229,8 @@ local function isrunning() return true, signal.kill(pid, 0) == 0; end -local function start(source_dir) +local function start(source_dir, lua) + lua = lua and lua .. " " or ""; local ok, ret = isrunning(); if not ok then return ok, ret; @@ -238,9 +239,9 @@ local function start(source_dir) return false, "already-running"; end if not source_dir then - os.execute("./prosody"); + os.execute(lua .. "./prosody"); else - os.execute(source_dir.."/../../bin/prosody"); + os.execute(lua .. source_dir.."/../../bin/prosody"); end return true; end -- cgit v1.2.3 From 122bde2f2c4816e89bd02be36e0e9f1ee31f7557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 25 Jun 2019 13:20:54 +0100 Subject: util.prosodyctl: Moved the 'admin_operation' function from prosodyctl to here --- util/prosodyctl.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 9b627bde..e2bc4369 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -278,6 +278,22 @@ local function reload() return true; end +local function admin_operation(operation, arg) + local modules, tree, server, refresh = "", "", "", "" + for i, _ in ipairs(arg) do + if arg[i]:sub(1, #"--tree=") == "--tree=" then + tree = arg[i].." " + elseif arg[i]:sub(1, #"--server=") == "--server=" then + server = arg[i].." " + elseif arg[i]:sub(1, #"--no-refresh") == "--no-refresh" then + refresh = arg[i].." " + else + modules=modules..arg[i].." " + end + end + os.execute("luarocks-admin "..tree..operation..server..refresh..modules) +end + return { show_message = show_message; show_warning = show_message; @@ -297,4 +313,5 @@ return { start = start; stop = stop; reload = reload; + admin_operation = admin_operation; }; -- cgit v1.2.3 From 7555016ac24cb681b2c443324652a5cc9df61799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Thu, 27 Jun 2019 18:01:36 +0100 Subject: util.prosodyctl: Added help support to 'admin_operation' --- util/prosodyctl.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index e2bc4369..c2235e85 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -279,6 +279,11 @@ local function reload() end local function admin_operation(operation, arg) + if arg[1] == "--help" then + print(" admin-"..operation) + print(" "..operation.."plugins from a server (repository)") + return 1; + end local modules, tree, server, refresh = "", "", "", "" for i, _ in ipairs(arg) do if arg[i]:sub(1, #"--tree=") == "--tree=" then -- cgit v1.2.3 From c21b60857f9f0f6b15e9f95ee11ec6291b56c574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Sat, 20 Jul 2019 12:41:31 -0700 Subject: util.prosodyctl: Corrected indentation on my code --- util/prosodyctl.lua | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index c2235e85..6f7bf065 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -279,24 +279,24 @@ local function reload() end local function admin_operation(operation, arg) - if arg[1] == "--help" then - print(" admin-"..operation) - print(" "..operation.."plugins from a server (repository)") - return 1; - end - local modules, tree, server, refresh = "", "", "", "" - for i, _ in ipairs(arg) do - if arg[i]:sub(1, #"--tree=") == "--tree=" then - tree = arg[i].." " - elseif arg[i]:sub(1, #"--server=") == "--server=" then - server = arg[i].." " - elseif arg[i]:sub(1, #"--no-refresh") == "--no-refresh" then - refresh = arg[i].." " - else - modules=modules..arg[i].." " - end - end - os.execute("luarocks-admin "..tree..operation..server..refresh..modules) + if arg[1] == "--help" then + print(" admin-"..operation) + print(" "..operation.."plugins from a server (repository)") + return 1; + end + local modules, tree, server, refresh = "", "", "", "" + for i, _ in ipairs(arg) do + if arg[i]:sub(1, #"--tree=") == "--tree=" then + tree = arg[i].." " + elseif arg[i]:sub(1, #"--server=") == "--server=" then + server = arg[i].." " + elseif arg[i]:sub(1, #"--no-refresh") == "--no-refresh" then + refresh = arg[i].." " + else + modules=modules..arg[i].." " + end + end + os.execute("luarocks-admin "..tree..operation..server..refresh..modules) end return { -- cgit v1.2.3 From 94ddde2e9e756f420fd6f6d271acbc1f7df630b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 23 Jul 2019 10:24:55 -0700 Subject: util.prosodyctl: Added the show_module_configuration_help function --- util/prosodyctl.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 6f7bf065..84f65665 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -39,6 +39,16 @@ local function show_usage(usage, desc) end end +local function show_module_configuration_help(mod_name) + print("Done.") + print("If you installed a prosody plugin, don't forget to add its name under the 'modules_enabled' section inside your configuration file.") + print("Depending on the module, there might be further configuration steps required.") + print("") + print("More info about: ") + print(" modules_enabled: https://prosody.im/doc/modules_enabled") + print(" "..mod_name..": https://modules.prosody.im/"..mod_name..".html") +end + local function getchar(n) local stty_ret = os.execute("stty raw -echo 2>/dev/null"); local ok, char; @@ -303,6 +313,7 @@ return { show_message = show_message; show_warning = show_message; show_usage = show_usage; + show_module_configuration_help = show_module_configuration_help; getchar = getchar; getline = getline; getpass = getpass; -- cgit v1.2.3 From c84fa6fd262025b7394f4e51992ffaacdb9c6eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 04:44:44 -0700 Subject: util.prosodyctl: Removed the admin_operation command --- util/prosodyctl.lua | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 84f65665..5e19937e 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -288,27 +288,6 @@ local function reload() return true; end -local function admin_operation(operation, arg) - if arg[1] == "--help" then - print(" admin-"..operation) - print(" "..operation.."plugins from a server (repository)") - return 1; - end - local modules, tree, server, refresh = "", "", "", "" - for i, _ in ipairs(arg) do - if arg[i]:sub(1, #"--tree=") == "--tree=" then - tree = arg[i].." " - elseif arg[i]:sub(1, #"--server=") == "--server=" then - server = arg[i].." " - elseif arg[i]:sub(1, #"--no-refresh") == "--no-refresh" then - refresh = arg[i].." " - else - modules=modules..arg[i].." " - end - end - os.execute("luarocks-admin "..tree..operation..server..refresh..modules) -end - return { show_message = show_message; show_warning = show_message; @@ -329,5 +308,4 @@ return { start = start; stop = stop; reload = reload; - admin_operation = admin_operation; }; -- cgit v1.2.3 From 52f963350f11ac6317bcf2ac1e184a6c0f7b9c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 11:20:35 -0700 Subject: util.prosodyctl: Created the helper function get_path_custom_plugins --- util/prosodyctl.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 5e19937e..fbeb9540 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -288,6 +288,14 @@ local function reload() return true; end +local function get_path_custom_plugins(plugin_paths) + -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now + -- luacheck: ignore 512 + for path in plugin_paths:gmatch("[^;]+") do + return path + end +end + return { show_message = show_message; show_warning = show_message; @@ -308,4 +316,5 @@ return { start = start; stop = stop; reload = reload; + get_path_custom_plugins = get_path_custom_plugins; }; -- cgit v1.2.3 From d2524edff49771ad0c131ac85461241eb6cd99f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 06:42:13 -0700 Subject: util.prosodyctl: Added the check_flags function --- util/prosodyctl.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index fbeb9540..affa2f6b 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -292,10 +292,20 @@ local function get_path_custom_plugins(plugin_paths) -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now -- luacheck: ignore 512 for path in plugin_paths:gmatch("[^;]+") do - return path + return path; end end +local function check_flags(arg) + local flag = "--tree="; + -- There might not be any argument when the list command is calling this function + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + return true, arg[2], dir; + end + return false, arg[1] +end + return { show_message = show_message; show_warning = show_message; @@ -317,4 +327,5 @@ return { stop = stop; reload = reload; get_path_custom_plugins = get_path_custom_plugins; + check_flags = check_flags; }; -- cgit v1.2.3 From b60081c28ce425696a3839d10039f23d6250e840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 07:24:43 -0700 Subject: util.prosodyctl: Added the call_luarocks function --- util/prosodyctl.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index affa2f6b..22571061 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -306,6 +306,12 @@ local function check_flags(arg) return false, arg[1] end +local function call_luarocks(operation, mod, dir) + show_message("Installing %s at %s", mod, dir); + os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); + show_module_configuration_help(mod); +end + return { show_message = show_message; show_warning = show_message; @@ -328,4 +334,5 @@ return { reload = reload; get_path_custom_plugins = get_path_custom_plugins; check_flags = check_flags; + call_luarocks = call_luarocks; }; -- cgit v1.2.3 From 289378113abb5b92d1628369fad66454b58cb738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 10:02:42 -0700 Subject: util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove --- util/prosodyctl.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 22571061..a98a89d7 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -307,9 +307,15 @@ local function check_flags(arg) end local function call_luarocks(operation, mod, dir) + if operation == "install" then show_message("Installing %s at %s", mod, dir); - os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); + elseif operation == "remove" then + show_message("Removing %s from %s", mod, dir); + end + os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); + if operation == "install" then show_module_configuration_help(mod); + end end return { -- cgit v1.2.3 From 2b8e9031a41af9046dc19c35e95f8cac0b4e67b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 10:22:11 -0700 Subject: util.prosodyctl: call_luarocks function is now compatible with the list command --- util/prosodyctl.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index a98a89d7..7fe87dab 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -312,7 +312,11 @@ local function call_luarocks(operation, mod, dir) elseif operation == "remove" then show_message("Removing %s from %s", mod, dir); end - os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); + if operation == "list" then + os.execute("luarocks list --tree='"..dir.."'") + else + os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); + end if operation == "install" then show_module_configuration_help(mod); end -- cgit v1.2.3 From 2049e20696aecd37419fafb8b38c96550b04a442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 11:00:20 -0700 Subject: util.prosodyctl: Added the execute_command function --- util/prosodyctl.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 7fe87dab..274d611c 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -322,6 +322,19 @@ local function call_luarocks(operation, mod, dir) end end +local function execute_command(arg) + local operation = arg[#arg] + local tree, mod, dir = check_flags(arg); + if tree then + call_luarocks(operation, mod, dir); + return 0; + else + dir = get_path_custom_plugins(prosody.paths.plugins); + call_luarocks(operation, mod, dir); + return 0; + end +end + return { show_message = show_message; show_warning = show_message; @@ -345,4 +358,5 @@ return { get_path_custom_plugins = get_path_custom_plugins; check_flags = check_flags; call_luarocks = call_luarocks; + execute_command = execute_command; }; -- cgit v1.2.3 From 5aa4dda0fb32d81ee08d873bd9528ab26aa56c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 11:08:43 -0700 Subject: util.prosodyctl: The check_flags function now considers that a module, if given, is specified at the penultimate argument it receives --- util/prosodyctl.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 274d611c..bf65e396 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -301,9 +301,9 @@ local function check_flags(arg) -- There might not be any argument when the list command is calling this function if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - return true, arg[2], dir; + return true, arg[#arg-1], dir; end - return false, arg[1] + return false, arg[#arg-1]; end local function call_luarocks(operation, mod, dir) -- cgit v1.2.3 From ee4ae338f9f6f4cbb162ff5c77c9873a38be8b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Thu, 1 Aug 2019 04:16:00 -0700 Subject: util.prosodyctl: Changed a comment --- util/prosodyctl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index bf65e396..c6abc02f 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -289,7 +289,7 @@ local function reload() end local function get_path_custom_plugins(plugin_paths) - -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now + -- I'm considering that the custom plugins' path is the first one at prosody.paths.plugins -- luacheck: ignore 512 for path in plugin_paths:gmatch("[^;]+") do return path; -- cgit v1.2.3 From d323072816a3060dc0d77f7e58a3ebc3c2f90ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 16 Aug 2019 15:01:57 -0700 Subject: util/prosodyctl: Removed the check_flags and execute_command function --- util/prosodyctl.lua | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index c6abc02f..316831a9 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -296,16 +296,6 @@ local function get_path_custom_plugins(plugin_paths) end end -local function check_flags(arg) - local flag = "--tree="; - -- There might not be any argument when the list command is calling this function - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - return true, arg[#arg-1], dir; - end - return false, arg[#arg-1]; -end - local function call_luarocks(operation, mod, dir) if operation == "install" then show_message("Installing %s at %s", mod, dir); @@ -322,19 +312,6 @@ local function call_luarocks(operation, mod, dir) end end -local function execute_command(arg) - local operation = arg[#arg] - local tree, mod, dir = check_flags(arg); - if tree then - call_luarocks(operation, mod, dir); - return 0; - else - dir = get_path_custom_plugins(prosody.paths.plugins); - call_luarocks(operation, mod, dir); - return 0; - end -end - return { show_message = show_message; show_warning = show_message; @@ -356,7 +333,5 @@ return { stop = stop; reload = reload; get_path_custom_plugins = get_path_custom_plugins; - check_flags = check_flags; call_luarocks = call_luarocks; - execute_command = execute_command; }; -- cgit v1.2.3 From 6ae5f04781c82e8064ceb9acc91ab9cfdb295969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 16 Aug 2019 15:03:50 -0700 Subject: util/prosodyctl: call_luarocks now sets a directory variable itself --- util/prosodyctl.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 316831a9..163658f3 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -296,7 +296,8 @@ local function get_path_custom_plugins(plugin_paths) end end -local function call_luarocks(operation, mod, dir) +local function call_luarocks(mod, operation) + local dir = get_path_custom_plugins(prosody.paths.plugins); if operation == "install" then show_message("Installing %s at %s", mod, dir); elseif operation == "remove" then -- cgit v1.2.3 From 45936787cb44aaef09f568cc2d74c4de6113579b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 1 Nov 2019 22:53:14 +0100 Subject: util.prosodyctl: Enforce strict JID validation on user creation This is where 64ddcbc9a328 should have started. By preventing creation of users with invalid JIDs, it will slowly become safer to enforce strict validation on everything. --- util/prosodyctl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 163658f3..586802d3 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -134,7 +134,7 @@ end -- Server control local function adduser(params) - local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; + local user, host, password = nodeprep(params.user, true), nameprep(params.host), params.password; if not user then return false, "invalid-username"; elseif not host then -- cgit v1.2.3 From 14d66d84121f2ff5a90da95d6b713d91910a9aa7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 23 Dec 2019 21:16:00 +0100 Subject: util.prosodyctl: Silence luacheck warnings --- util/prosodyctl.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 586802d3..0787b8c3 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -210,7 +210,7 @@ local function getpid() return false, "pidfile-read-failed", err; end - local locked, err = lfs.lock(file, "w"); + local locked, err = lfs.lock(file, "w"); -- luacheck: ignore 211/err if locked then file:close(); return false, "pidfile-not-locked"; @@ -227,7 +227,7 @@ local function getpid() end local function isrunning() - local ok, pid, err = getpid(); + local ok, pid, err = getpid(); -- luacheck: ignore 211/err if not ok then if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then -- Report as not running, since we can't open the pidfile -- cgit v1.2.3 From a15d977f4446660e899dc8c3bafb984163a2de27 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Jan 2020 16:40:21 +0100 Subject: util.prosodyctl: Pass command line flag to force daemonization on start Part of the deprecation of the 'daemonize' config option. Further, it is a bit weird to run `prosodyctl start` and get Prosody running in the foreground. --- util/prosodyctl.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 0787b8c3..ea697ffc 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -249,9 +249,9 @@ local function start(source_dir, lua) return false, "already-running"; end if not source_dir then - os.execute(lua .. "./prosody"); + os.execute(lua .. "./prosody -D"); else - os.execute(lua .. source_dir.."/../../bin/prosody"); + os.execute(lua .. source_dir.."/../../bin/prosody -D"); end return true; end -- cgit v1.2.3 From 46022b09886badc89425865ae1ac02651995f8c8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 2 Jun 2020 08:01:21 +0100 Subject: prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl --- util/prosodyctl.lua | 109 ++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 93 deletions(-) (limited to 'util/prosodyctl.lua') diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index ea697ffc..cb86a5a1 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -15,7 +15,6 @@ local usermanager = require "core.usermanager"; local signal = require "util.signal"; local set = require "util.set"; local lfs = require "lfs"; -local pcall = pcall; local type = type; local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; @@ -27,10 +26,22 @@ local tonumber = tonumber; local _G = _G; local prosody = prosody; +local error_messages = setmetatable({ + ["invalid-username"] = "The given username is invalid in a Jabber ID"; + ["invalid-hostname"] = "The given hostname is invalid"; + ["no-password"] = "No password was supplied"; + ["no-such-user"] = "The given user does not exist on the server"; + ["no-such-host"] = "The given hostname does not exist in the config"; + ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?"; + ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see https://prosody.im/doc/prosodyctl#pidfile for help"; + ["invalid-pidfile"] = "The 'pidfile' option in the configuration file is not a string, see https://prosody.im/doc/prosodyctl#pidfile for help"; + ["no-posix"] = "The mod_posix module is not enabled in the Prosody config file, see https://prosody.im/doc/prosodyctl for more info"; + ["no-such-method"] = "This module has no commands"; + ["not-running"] = "Prosody is not running"; + }, { __index = function (_,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end }); + -- UI helpers -local function show_message(msg, ...) - print(msg:format(...)); -end +local show_message = require "util.human.io".printf; local function show_usage(usage, desc) print("Usage: ".._G.arg[0].." "..usage); @@ -49,89 +60,6 @@ local function show_module_configuration_help(mod_name) print(" "..mod_name..": https://modules.prosody.im/"..mod_name..".html") end -local function getchar(n) - local stty_ret = os.execute("stty raw -echo 2>/dev/null"); - local ok, char; - if stty_ret == true or stty_ret == 0 then - ok, char = pcall(io.read, n or 1); - os.execute("stty sane"); - else - ok, char = pcall(io.read, "*l"); - if ok then - char = char:sub(1, n or 1); - end - end - if ok then - return char; - end -end - -local function getline() - local ok, line = pcall(io.read, "*l"); - if ok then - return line; - end -end - -local function getpass() - local stty_ret, _, status_code = os.execute("stty -echo 2>/dev/null"); - if status_code then -- COMPAT w/ Lua 5.1 - stty_ret = status_code; - end - if stty_ret ~= 0 then - io.write("\027[08m"); -- ANSI 'hidden' text attribute - end - local ok, pass = pcall(io.read, "*l"); - if stty_ret == 0 then - os.execute("stty sane"); - else - io.write("\027[00m"); - end - io.write("\n"); - if ok then - return pass; - end -end - -local function show_yesno(prompt) - io.write(prompt, " "); - local choice = getchar():lower(); - io.write("\n"); - if not choice:match("%a") then - choice = prompt:match("%[.-(%U).-%]$"); - if not choice then return nil; end - end - return (choice == "y"); -end - -local function read_password() - local password; - while true do - io.write("Enter new password: "); - password = getpass(); - if not password then - show_message("No password - cancelled"); - return; - end - io.write("Retype new password: "); - if getpass() ~= password then - if not show_yesno [=[Passwords did not match, try again? [Y/n]]=] then - return; - end - else - break; - end - end - return password; -end - -local function show_prompt(prompt) - io.write(prompt, " "); - local line = getline(); - line = line and line:gsub("\n$",""); - return (line and #line > 0) and line or nil; -end - -- Server control local function adduser(params) local user, host, password = nodeprep(params.user, true), nameprep(params.host), params.password; @@ -318,12 +246,6 @@ return { show_warning = show_message; show_usage = show_usage; show_module_configuration_help = show_module_configuration_help; - getchar = getchar; - getline = getline; - getpass = getpass; - show_yesno = show_yesno; - read_password = read_password; - show_prompt = show_prompt; adduser = adduser; user_exists = user_exists; passwd = passwd; @@ -335,4 +257,5 @@ return { reload = reload; get_path_custom_plugins = get_path_custom_plugins; call_luarocks = call_luarocks; + error_messages = error_messages; }; -- cgit v1.2.3