From e31667cf151d9d81cf2ab16eece72e559983fb52 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 10 Jan 2019 14:54:34 +0100 Subject: prosodyctl: Pass the original argv table to subcommands (with first argument removed) This preserves eg arg[-1] where you might find the path to the Lua executable, which can be useful. --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 76de45a2..ecf00baa 100755 --- a/prosodyctl +++ b/prosodyctl @@ -83,7 +83,7 @@ local jid_split = require "util.jid".prepped_split; local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * 2; ----------------------- local commands = {}; -local command = arg[1]; +local command = table.remove(arg, 1); function commands.adduser(arg) if not arg[1] or arg[1] == "--help" then @@ -1365,7 +1365,7 @@ local command_runner = async.runner(function () os.exit(0); end - os.exit(commands[command]({ select(2, unpack(arg)) })); + os.exit(commands[command](arg)); end, watchers); command_runner:run(true); -- cgit v1.2.3 From 1e4a0ebba24834980440a61636601732b762e397 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 10 Jan 2019 15:25:38 +0100 Subject: prosodyctl: Use the same runtime for starting prosody Improves the experience with the `make integration-test` command --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index ecf00baa..0ff03a7b 100755 --- a/prosodyctl +++ b/prosodyctl @@ -222,7 +222,7 @@ function commands.start(arg) end --luacheck: ignore 411/ret - local ok, ret = prosodyctl.start(prosody.paths.source); + local ok, ret = prosodyctl.start(prosody.paths.source, arg[-1]); if ok then local daemonize = configmanager.get("*", "daemonize"); if daemonize == nil then -- cgit v1.2.3 From 467260e6f51942bc4a113bc0ca23808002289147 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 4 Oct 2018 12:23:06 +0200 Subject: mod_bosh: Drop CORS code in favor of than in mod_http This deprecates the cross_domain_bosh setting. As a compat measure, if it is set, mod_http_crossdomain is loaded. --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 0ff03a7b..4d91cfe5 100755 --- a/prosodyctl +++ b/prosodyctl @@ -806,7 +806,7 @@ function commands.check(arg) print("Checking config..."); local deprecated = set.new({ "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption", - "vcard_compatibility", + "vcard_compatibility", "cross_domain_bosh", }); local known_global_options = set.new({ "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", -- cgit v1.2.3 From 7fefafa8f6cc312b41f69d8149d5a926657bc9fb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 4 Oct 2018 12:24:08 +0200 Subject: mod_websocket: Drop CORS code in favor of that in mod_http Like for mod_bosh, deprecates consider_websocket_secure and depend on mod_http_crossdomain if it is set. --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 4d91cfe5..efb98386 100755 --- a/prosodyctl +++ b/prosodyctl @@ -806,7 +806,7 @@ function commands.check(arg) print("Checking config..."); local deprecated = set.new({ "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption", - "vcard_compatibility", "cross_domain_bosh", + "vcard_compatibility", "cross_domain_bosh", "cross_domain_websocket" }); local known_global_options = set.new({ "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", -- cgit v1.2.3 From d254f7e101f76154ad5fb1a22964b74cba93d675 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 18 Jan 2019 18:30:41 +0100 Subject: prosodyctl: Fix module.command invocation (thanks woffs) The first argument is already removed once since c7727c13260f --- prosodyctl | 2 -- 1 file changed, 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index efb98386..a628ed2b 100755 --- a/prosodyctl +++ b/prosodyctl @@ -1300,8 +1300,6 @@ local command_runner = async.runner(function () end end - table.remove(arg, 1); - local module = modulemanager.get_module("*", module_name); if not module then show_message("Failed to load module '"..module_name.."': Unknown error"); -- cgit v1.2.3 From 42f4b6b225edf608828ca0716934c41a690964db Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 8 Dec 2018 18:02:56 +0100 Subject: prosodyctl: about: Report the current operating system according to uname --- prosodyctl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index a628ed2b..f6812e23 100755 --- a/prosodyctl +++ b/prosodyctl @@ -363,6 +363,13 @@ function commands.about(arg) .."\n "; end))); print(""); + local have_pposix, pposix = pcall(require, "util.pposix"); + if have_pposix and pposix.uname then + print("# Operating system"); + local uname, err = pposix.uname(); + print(uname and uname.sysname .. " " .. uname.release or "Unknown POSIX", err or ""); + print(""); + end print("# Lua environment"); print("Lua version: ", _G._VERSION); print(""); -- cgit v1.2.3 From de37e6cb589e0124b93a38721c8ad809ba762b16 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 29 Jun 2019 16:54:39 +0200 Subject: prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386) Interpreter goes into the lowest negative index. See http://www.lua.org/manual/5.2/manual.html#7 --- prosodyctl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index f5786ff9..3809beff 100755 --- a/prosodyctl +++ b/prosodyctl @@ -222,7 +222,15 @@ function commands.start(arg) end --luacheck: ignore 411/ret - local ok, ret = prosodyctl.start(prosody.paths.source, arg[-1]); + local lua; + do + local i = 0; + repeat + i = i - 1; + until arg[i-1] == nil + lua = arg[i]; + end + local ok, ret = prosodyctl.start(prosody.paths.source, lua); if ok then local daemonize = configmanager.get("*", "daemonize"); if daemonize == nil then -- cgit v1.2.3 From 66bb4ab4494853abfad5a53854355f03d4b7ae6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 7 Jun 2019 11:36:13 +0100 Subject: prosodyctl: Created a custom function, 'test', that prints back a welcoming message --- prosodyctl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index f5786ff9..db7b0dc4 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,6 +85,10 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); +function commands.test() + show_message [[Well, hello there!]] +end + function commands.adduser(arg) if not arg[1] or arg[1] == "--help" then show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); -- cgit v1.2.3 From 83ca8aef547856ab0caead6f9f999f642818de95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 7 Jun 2019 11:46:19 +0100 Subject: prosodyctl: The 'test' function now also prints which plugins are enabled --- prosodyctl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index db7b0dc4..4036c59a 100755 --- a/prosodyctl +++ b/prosodyctl @@ -87,6 +87,8 @@ local command = table.remove(arg, 1); function commands.test() show_message [[Well, hello there!]] + --show_message [[Enabled Plugins: ], modulemanager.get_modules_for_host()] + show_warning("Trying to peek at the plugin directory: '%s'", modulemanager.get_modules_for_host()) end function commands.adduser(arg) -- cgit v1.2.3 From cf25afe5b143eea8b1ca7d74462965d6e8184b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 7 Jun 2019 13:00:40 +0100 Subject: prosodyctl: Added the 'local_plugins' command function, which prints back a list of locally available plugins --- prosodyctl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 4036c59a..00d24b1c 100755 --- a/prosodyctl +++ b/prosodyctl @@ -87,10 +87,25 @@ local command = table.remove(arg, 1); function commands.test() show_message [[Well, hello there!]] - --show_message [[Enabled Plugins: ], modulemanager.get_modules_for_host()] show_warning("Trying to peek at the plugin directory: '%s'", modulemanager.get_modules_for_host()) end +function commands.local_plugins() + local directory = "./plugins" + local i, t, popen = 0, {}, io.popen + local pfile = popen('ls -a "'..directory..'"') + for filename in pfile:lines() do + if filename == "." or filename == ".." then + i = i + 1 + else + i = i + 1 + t[i] = filename + show_warning("%s", t[i]) + end + end + pfile:close() +end + function commands.adduser(arg) if not arg[1] or arg[1] == "--help" then show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); -- cgit v1.2.3 From 8025f98427a23a64f3dd303aedde6fcc8d5ea688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 7 Jun 2019 13:09:01 +0100 Subject: prosodyctl: Renamed the command function 'test' to 'enabled_plugins', which now only shows the plugins, in a list --- prosodyctl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 00d24b1c..a7300973 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,9 +85,10 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); -function commands.test() - show_message [[Well, hello there!]] - show_warning("Trying to peek at the plugin directory: '%s'", modulemanager.get_modules_for_host()) +function commands.enabled_plugins() + for module in modulemanager.get_modules_for_host() do + show_warning("%s", module) + end end function commands.local_plugins() -- cgit v1.2.3 From 992d18aa62af23bbb5849e728a9b298b556e2cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Thu, 20 Jun 2019 19:17:47 +0100 Subject: prosodyctl: Implemented the 'list' command, which is a bridge to 'luarocks list' --- prosodyctl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index a7300973..d726c028 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,6 +85,19 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); +function commands.list(arg) + -- Need to think about the case with many flags + local flag="--tree=" + -- I'm considering the flag is the first, but there can be many flags + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + -- These extra double brackets allow us to correctly process names with spaces + os.execute("luarocks list --tree=".."'"..dir.."'") + else + os.execute("luarocks list --tree="..prosody.paths.data.."/rocks") + end +end + function commands.enabled_plugins() for module in modulemanager.get_modules_for_host() do show_warning("%s", module) -- cgit v1.2.3 From 1fda45e5860bbfd748ec163b4f7ebe03d1ba7c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 21 Jun 2019 19:03:04 +0100 Subject: prosodyctl: Implemented a command bridge to the 'luarocks-admin add' command, called 'admin_add' --- prosodyctl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index d726c028..efe6394e 100755 --- a/prosodyctl +++ b/prosodyctl @@ -87,7 +87,7 @@ local command = table.remove(arg, 1); function commands.list(arg) -- Need to think about the case with many flags - local flag="--tree=" + local flag = "--tree=" -- I'm considering the flag is the first, but there can be many flags if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") @@ -98,6 +98,22 @@ function commands.list(arg) end end +function commands.admin_add(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.."add "..server..refresh..modules) +end + function commands.enabled_plugins() for module in modulemanager.get_modules_for_host() do show_warning("%s", module) -- cgit v1.2.3 From b12ba155400cc80ff269a100e18bcbdd53f86041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 25 Jun 2019 00:52:12 +0100 Subject: prosodyctl: Changed the command 'admin_add' to 'admin_operation', which will be called by both add/remove operations --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index efe6394e..56fa3f24 100755 --- a/prosodyctl +++ b/prosodyctl @@ -98,7 +98,7 @@ function commands.list(arg) end end -function commands.admin_add(arg) +function admin_operation(operation, arg) local modules, tree, server, refresh = "", "", "", "" for i, _ in ipairs(arg) do if arg[i]:sub(1, #"--tree=") == "--tree=" then @@ -111,7 +111,7 @@ function commands.admin_add(arg) modules=modules..arg[i].." " end end - os.execute("luarocks-admin "..tree.."add "..server..refresh..modules) + os.execute("luarocks-admin "..tree..operation..server..refresh..modules) end function commands.enabled_plugins() -- cgit v1.2.3 From 6021b5871292b692043b80334ecbe1133965519d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 25 Jun 2019 12:02:37 +0100 Subject: prosodyctl: Added the 'admin_add' command --- prosodyctl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 56fa3f24..1180d039 100755 --- a/prosodyctl +++ b/prosodyctl @@ -114,6 +114,10 @@ function admin_operation(operation, arg) os.execute("luarocks-admin "..tree..operation..server..refresh..modules) end +function commands.admin_add(arg) + admin_operation("add ", arg) +end + function commands.enabled_plugins() for module in modulemanager.get_modules_for_host() do show_warning("%s", module) -- cgit v1.2.3 From 2aa2aff974345346344416ca1f91f0c5190dd93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 25 Jun 2019 12:03:20 +0100 Subject: prosodyctl: Added the 'admin_remove' command --- prosodyctl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 1180d039..75b36e34 100755 --- a/prosodyctl +++ b/prosodyctl @@ -118,6 +118,10 @@ function commands.admin_add(arg) admin_operation("add ", arg) end +function commands.admin_remove(arg) + admin_operation("remove ", arg) +end + function commands.enabled_plugins() for module in modulemanager.get_modules_for_host() do show_warning("%s", module) -- 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 --- prosodyctl | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 75b36e34..05f711d7 100755 --- a/prosodyctl +++ b/prosodyctl @@ -98,22 +98,6 @@ function commands.list(arg) end end -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 - function commands.admin_add(arg) admin_operation("add ", arg) end -- cgit v1.2.3 From 79191ed8f28bc8a26b782f3ef3e28459029c9f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 25 Jun 2019 13:22:22 +0100 Subject: prosodyctl: Corrected the calls to the recently moved function 'admin_operation' --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 05f711d7..2c786b95 100755 --- a/prosodyctl +++ b/prosodyctl @@ -99,11 +99,11 @@ function commands.list(arg) end function commands.admin_add(arg) - admin_operation("add ", arg) + prosodyctl.admin_operation("add ", arg) end function commands.admin_remove(arg) - admin_operation("remove ", arg) + prosodyctl.admin_operation("remove ", arg) end function commands.enabled_plugins() -- cgit v1.2.3 From fce54a8010c647e28274b54e169f92c814855649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 26 Jun 2019 16:46:51 +0100 Subject: prosodyctl: Complemented my functions with return calls, when possible --- prosodyctl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 2c786b95..8cf90048 100755 --- a/prosodyctl +++ b/prosodyctl @@ -10,7 +10,6 @@ -- prosodyctl - command-line controller for Prosody XMPP server -- Will be modified by configure script if run -- - CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); @@ -93,17 +92,21 @@ function commands.list(arg) local dir = arg[1]:match("=(.+)$") -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks list --tree=".."'"..dir.."'") + return 0; else os.execute("luarocks list --tree="..prosody.paths.data.."/rocks") + return 0; end end function commands.admin_add(arg) prosodyctl.admin_operation("add ", arg) + return 0; end function commands.admin_remove(arg) prosodyctl.admin_operation("remove ", arg) + return 0; end function commands.enabled_plugins() @@ -126,6 +129,7 @@ function commands.local_plugins() end end pfile:close() + return 0 end function commands.adduser(arg) -- cgit v1.2.3 From 11a354176f389c17770db9a11f45cd3cdcfe7472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Thu, 27 Jun 2019 18:00:11 +0100 Subject: prosodyctl: added help support to all my functions --- prosodyctl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 8cf90048..7cae908e 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,6 +85,10 @@ local commands = {}; local command = table.remove(arg, 1); function commands.list(arg) + if not arg[1] or arg[1] == "--help" then + show_usage([[list]], [[Shows installed rocks]]); + return 1; + end -- Need to think about the case with many flags local flag = "--tree=" -- I'm considering the flag is the first, but there can be many flags @@ -109,13 +113,21 @@ function commands.admin_remove(arg) return 0; end -function commands.enabled_plugins() +function commands.enabled_plugins(arg) + if arg[1] == "--help" then + show_usage([[enabled_plugins]], [[Shows plugins currently enabled on prosody]]); + return 1; + end for module in modulemanager.get_modules_for_host() do show_warning("%s", module) end end -function commands.local_plugins() +function commands.local_plugins(arg) + if arg[1] == "--help" then + show_usage([[local_plugins]], [[Shows plugins currently available for prosody, locally]]); + return 1; + end local directory = "./plugins" local i, t, popen = 0, {}, io.popen local pfile = popen('ls -a "'..directory..'"') @@ -1397,7 +1409,8 @@ local command_runner = async.runner(function () print("Where COMMAND may be one of:\n"); local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; - local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about" }; + local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about", "local_plugins", "enabled_plugins", + "admin_add", "admin_remove", "list", }; local done = {}; -- cgit v1.2.3 From 7c291a6e154b0325ca4173995810f7b0831f7480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 16 Jul 2019 10:05:31 -0700 Subject: prosodyctl: Added the 'get_modules' commands --- prosodyctl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 7cae908e..0bde4478 100755 --- a/prosodyctl +++ b/prosodyctl @@ -84,6 +84,35 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); +-- This function receives no arguments. It clones all the plugins from prosody's plugin repository +function commands.get_modules(arg) + if arg[1] == "--help" then + show_usage([[get_modules]], [[Downloads all available modules]]); + return 1 + end + if os.execute '[ -e "./downloaded_modules" ]' then + print("The modules have already been imported") + print("Do you want to re-import?(Y/N)") + local answer = io.read() + if answer == "Y" then + print("Deleting previous imports") + os.execute("rm -rf downloaded_modules") + print("Downloading plugins") + os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") + print("Done!") + return 0 + else + print("We keep what we have then!") + return 0 + end + else + print("Getting all the available modules") + os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") + print("Done!") + return 0 + end +end + function commands.list(arg) if not arg[1] or arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); -- cgit v1.2.3 From db90fc5da5288330ba1780d387ab7bdafc3210ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 16 Jul 2019 10:08:12 -0700 Subject: prosodyctl: Added the 'write_rockspec' function --- prosodyctl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 0bde4478..baea969a 100755 --- a/prosodyctl +++ b/prosodyctl @@ -113,6 +113,22 @@ function commands.get_modules(arg) end end +-- Function to write rockspecs from a module at working_directory/downloaded_modules +-- Receives the module's name as an argument +-- The rockspec is saved inside its module's folder +function commands.write_rockspec(arg) + if arg[1] == "--help" then + show_usage([[write_rockspec]], [[Picks up a module and writes an initial rockspec]]); + return 1 + end + print("Writing rockspec for "..arg[1]) + os.execute("luarocks write_rockspec "..arg[1].." ./downloaded_modules/"..arg[1]) + print("Rockspec created! Moving it into the ./downloaded_modules/"..arg[1].." folder") + os.execute("mv "..arg[1].."-scm-1.rockspec ./downloaded_modules/"..arg[1]) + print("Done!") + return 0 +end + function commands.list(arg) if not arg[1] or arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); -- cgit v1.2.3 From 8fa4d6e25003773649665a5c9d4924b723a21fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 16 Jul 2019 10:26:44 -0700 Subject: prosodyctl: Added the 'make' function --- prosodyctl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index baea969a..7f7b515e 100755 --- a/prosodyctl +++ b/prosodyctl @@ -129,6 +129,17 @@ function commands.write_rockspec(arg) return 0 end +-- Command to install a rockspec with local sources +-- The module is installed at the plugins folder +function commands.make(arg) + if arg[1] == "--help" then + show_usage([[make]], [[Installs a module with sources available locally]]); + return 1 + end + os.execute("cd downloaded_modules/"..arg[1].." && luarocks --tree='../../plugins' make "..arg[1].."-scm-1.rockspec") + return 0 +end + function commands.list(arg) if not arg[1] or arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); -- cgit v1.2.3 From 5b190cf27618c048a69021dae3415727a50630e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 16 Jul 2019 10:34:13 -0700 Subject: prosodyctl: Added the 'remove' command --- prosodyctl | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 7f7b515e..dac0c1f9 100755 --- a/prosodyctl +++ b/prosodyctl @@ -140,6 +140,19 @@ function commands.make(arg) return 0 end +-- Command to remove a rockspec +-- Receives as an argument the name of the plugin to be removed from the plugins folder +function commands.remove(arg) + if arg[1] == "--help" then + show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); + return 1 + end + print("Removing "..arg[1].." from ./plugins") + os.execute("luarocks --tree='./plugins' remove "..arg[1]) + print("Done!") + return 0 +end + function commands.list(arg) if not arg[1] or arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); -- cgit v1.2.3 From 344f333e82da80a66a357ba5b271043b504ada2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 17 Jul 2019 03:20:08 -0700 Subject: prosodyctl: Added the 'install' command --- prosodyctl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index dac0c1f9..f04c1d46 100755 --- a/prosodyctl +++ b/prosodyctl @@ -153,6 +153,16 @@ function commands.remove(arg) return 0 end +function commands.install(arg) + if arg[1] == "--help" then + show_usage([[make]], [[Installs a rockspec/rock from a specified server]]); + return 1 + end + print("Installing module "..arg[1].." locally, from luarocks repo") + os.execute("luarocks --tree='./plugins' install "..arg[1]) + return 0 +end + function commands.list(arg) if not arg[1] or arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); -- cgit v1.2.3 From 184b2a45b80a03728038643d0c5ec1cfd70e617f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 17 Jul 2019 03:31:02 -0700 Subject: prosodyctl: Improved the 'list' command --- prosodyctl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index f04c1d46..750c84e4 100755 --- a/prosodyctl +++ b/prosodyctl @@ -164,7 +164,7 @@ function commands.install(arg) end function commands.list(arg) - if not arg[1] or arg[1] == "--help" then + if arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); return 1; end @@ -174,10 +174,10 @@ function commands.list(arg) if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks list --tree=".."'"..dir.."'") + os.execute("luarocks list --tree='"..dir.."'") return 0; else - os.execute("luarocks list --tree="..prosody.paths.data.."/rocks") + os.execute("luarocks list --tree="..prosody.paths.plugins) return 0; end end -- cgit v1.2.3 From 213539ccd90da28856875c64bd41868cb818f2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 17 Jul 2019 03:45:26 -0700 Subject: prosodyctl: The 'install' command can now recognize the flag '--tree' --- prosodyctl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 750c84e4..a1dd1614 100755 --- a/prosodyctl +++ b/prosodyctl @@ -158,9 +158,20 @@ function commands.install(arg) show_usage([[make]], [[Installs a rockspec/rock from a specified server]]); return 1 end - print("Installing module "..arg[1].." locally, from luarocks repo") - os.execute("luarocks --tree='./plugins' install "..arg[1]) - return 0 + -- Need to think about the case with many flags + local flag = "--tree=" + -- I'm considering the flag is the first, but there can be many flags + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + print("Installing module "..arg[2].." at "..dir..", from luarocks repo") + -- These extra double brackets allow us to correctly process names with spaces + os.execute("luarocks install --tree='"..dir.."' "..arg[2]) + return 0; + else + print("Installing module "..arg[1].." locally, from luarocks repo") + os.execute("luarocks --tree='"..prosody.paths.plugins.."' install "..arg[1]) + return 0 + end end function commands.list(arg) -- cgit v1.2.3 From efb9164e517ff5d95a6b82fd3cf416535b2fe3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 17 Jul 2019 09:03:15 -0700 Subject: prosodyctl: Improved the 'remove' command --- prosodyctl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index a1dd1614..af1fea54 100755 --- a/prosodyctl +++ b/prosodyctl @@ -147,10 +147,20 @@ function commands.remove(arg) show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1 end - print("Removing "..arg[1].." from ./plugins") - os.execute("luarocks --tree='./plugins' remove "..arg[1]) - print("Done!") - return 0 + local flag = "--tree=" + -- I'm considering the flag is the first, but there can be many flags + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + print("Removing module "..arg[2].." at "..dir..", from luarocks repo") + -- These extra double brackets allow us to correctly process names with spaces + os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) + return 0; + else + print("Removing "..arg[1].." from ./plugins") + os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) + print("Done!") + return 0 + end end function commands.install(arg) -- cgit v1.2.3 From 5fa25a8910bcb012944b3abbc23b5904e8df46a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 17 Jul 2019 09:12:32 -0700 Subject: prosodyctl: Added missing semicolons to some return calls --- prosodyctl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index af1fea54..dea588a2 100755 --- a/prosodyctl +++ b/prosodyctl @@ -88,7 +88,7 @@ local command = table.remove(arg, 1); function commands.get_modules(arg) if arg[1] == "--help" then show_usage([[get_modules]], [[Downloads all available modules]]); - return 1 + return 1; end if os.execute '[ -e "./downloaded_modules" ]' then print("The modules have already been imported") @@ -100,16 +100,16 @@ function commands.get_modules(arg) print("Downloading plugins") os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") print("Done!") - return 0 + return 0; else print("We keep what we have then!") - return 0 + return 0; end else print("Getting all the available modules") os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") print("Done!") - return 0 + return 0; end end @@ -119,14 +119,14 @@ end function commands.write_rockspec(arg) if arg[1] == "--help" then show_usage([[write_rockspec]], [[Picks up a module and writes an initial rockspec]]); - return 1 + return 1; end print("Writing rockspec for "..arg[1]) os.execute("luarocks write_rockspec "..arg[1].." ./downloaded_modules/"..arg[1]) print("Rockspec created! Moving it into the ./downloaded_modules/"..arg[1].." folder") os.execute("mv "..arg[1].."-scm-1.rockspec ./downloaded_modules/"..arg[1]) print("Done!") - return 0 + return 0; end -- Command to install a rockspec with local sources @@ -134,10 +134,10 @@ end function commands.make(arg) if arg[1] == "--help" then show_usage([[make]], [[Installs a module with sources available locally]]); - return 1 + return 1; end os.execute("cd downloaded_modules/"..arg[1].." && luarocks --tree='../../plugins' make "..arg[1].."-scm-1.rockspec") - return 0 + return 0; end -- Command to remove a rockspec @@ -145,7 +145,7 @@ end function commands.remove(arg) if arg[1] == "--help" then show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); - return 1 + return 1; end local flag = "--tree=" -- I'm considering the flag is the first, but there can be many flags @@ -159,14 +159,14 @@ function commands.remove(arg) print("Removing "..arg[1].." from ./plugins") os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) print("Done!") - return 0 + return 0; end end function commands.install(arg) if arg[1] == "--help" then show_usage([[make]], [[Installs a rockspec/rock from a specified server]]); - return 1 + return 1; end -- Need to think about the case with many flags local flag = "--tree=" @@ -180,7 +180,7 @@ function commands.install(arg) else print("Installing module "..arg[1].." locally, from luarocks repo") os.execute("luarocks --tree='"..prosody.paths.plugins.."' install "..arg[1]) - return 0 + return 0; end end @@ -219,7 +219,7 @@ function commands.enabled_plugins(arg) return 1; end for module in modulemanager.get_modules_for_host() do - show_warning("%s", module) + show_warning("%s", module) end end @@ -241,7 +241,7 @@ function commands.local_plugins(arg) end end pfile:close() - return 0 + return 0; end function commands.adduser(arg) -- cgit v1.2.3 From cbeea7c2875da04e63c97727be48eaf689fc1745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 17 Jul 2019 09:47:37 -0700 Subject: prosodyctl: Removed trailing whitespaces --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index dea588a2..477ddcfe 100755 --- a/prosodyctl +++ b/prosodyctl @@ -219,7 +219,7 @@ function commands.enabled_plugins(arg) return 1; end for module in modulemanager.get_modules_for_host() do - show_warning("%s", module) + show_warning("%s", module) end end -- cgit v1.2.3 From aaac83292f531d4f5b540bc8e35e5e8999ae21cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Sat, 20 Jul 2019 12:41:06 -0700 Subject: prosodyctl: Corrected indentation on my code --- prosodyctl | 212 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 106 insertions(+), 106 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 477ddcfe..244a1a24 100755 --- a/prosodyctl +++ b/prosodyctl @@ -86,137 +86,137 @@ local command = table.remove(arg, 1); -- This function receives no arguments. It clones all the plugins from prosody's plugin repository function commands.get_modules(arg) - if arg[1] == "--help" then + if arg[1] == "--help" then show_usage([[get_modules]], [[Downloads all available modules]]); - return 1; - end - if os.execute '[ -e "./downloaded_modules" ]' then - print("The modules have already been imported") - print("Do you want to re-import?(Y/N)") - local answer = io.read() - if answer == "Y" then - print("Deleting previous imports") - os.execute("rm -rf downloaded_modules") - print("Downloading plugins") - os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") - print("Done!") - return 0; - else - print("We keep what we have then!") - return 0; - end - else - print("Getting all the available modules") - os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") - print("Done!") - return 0; - end + return 1; + end + if os.execute '[ -e "./downloaded_modules" ]' then + print("The modules have already been imported") + print("Do you want to re-import?(Y/N)") + local answer = io.read() + if answer == "Y" then + print("Deleting previous imports") + os.execute("rm -rf downloaded_modules") + print("Downloading plugins") + os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") + print("Done!") + return 0; + else + print("We keep what we have then!") + return 0; + end + else + print("Getting all the available modules") + os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") + print("Done!") + return 0; + end end -- Function to write rockspecs from a module at working_directory/downloaded_modules -- Receives the module's name as an argument -- The rockspec is saved inside its module's folder function commands.write_rockspec(arg) - if arg[1] == "--help" then - show_usage([[write_rockspec]], [[Picks up a module and writes an initial rockspec]]); - return 1; - end - print("Writing rockspec for "..arg[1]) - os.execute("luarocks write_rockspec "..arg[1].." ./downloaded_modules/"..arg[1]) - print("Rockspec created! Moving it into the ./downloaded_modules/"..arg[1].." folder") - os.execute("mv "..arg[1].."-scm-1.rockspec ./downloaded_modules/"..arg[1]) - print("Done!") - return 0; + if arg[1] == "--help" then + show_usage([[write_rockspec]], [[Picks up a module and writes an initial rockspec]]); + return 1; + end + print("Writing rockspec for "..arg[1]) + os.execute("luarocks write_rockspec "..arg[1].." ./downloaded_modules/"..arg[1]) + print("Rockspec created! Moving it into the ./downloaded_modules/"..arg[1].." folder") + os.execute("mv "..arg[1].."-scm-1.rockspec ./downloaded_modules/"..arg[1]) + print("Done!") + return 0; end -- Command to install a rockspec with local sources -- The module is installed at the plugins folder function commands.make(arg) - if arg[1] == "--help" then - show_usage([[make]], [[Installs a module with sources available locally]]); - return 1; - end - os.execute("cd downloaded_modules/"..arg[1].." && luarocks --tree='../../plugins' make "..arg[1].."-scm-1.rockspec") - return 0; + if arg[1] == "--help" then + show_usage([[make]], [[Installs a module with sources available locally]]); + return 1; + end + os.execute("cd downloaded_modules/"..arg[1].." && luarocks --tree='../../plugins' make "..arg[1].."-scm-1.rockspec") + return 0; end -- Command to remove a rockspec -- Receives as an argument the name of the plugin to be removed from the plugins folder function commands.remove(arg) - if arg[1] == "--help" then - show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); - return 1; - end - local flag = "--tree=" - -- I'm considering the flag is the first, but there can be many flags - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - print("Removing module "..arg[2].." at "..dir..", from luarocks repo") - -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) - return 0; - else - print("Removing "..arg[1].." from ./plugins") - os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) - print("Done!") - return 0; - end + if arg[1] == "--help" then + show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); + return 1; + end + local flag = "--tree=" + -- I'm considering the flag is the first, but there can be many flags + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + print("Removing module "..arg[2].." at "..dir..", from luarocks repo") + -- These extra double brackets allow us to correctly process names with spaces + os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) + return 0; + else + print("Removing "..arg[1].." from ./plugins") + os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) + print("Done!") + return 0; + end end function commands.install(arg) - if arg[1] == "--help" then - show_usage([[make]], [[Installs a rockspec/rock from a specified server]]); - return 1; - end - -- Need to think about the case with many flags - local flag = "--tree=" - -- I'm considering the flag is the first, but there can be many flags - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - print("Installing module "..arg[2].." at "..dir..", from luarocks repo") - -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks install --tree='"..dir.."' "..arg[2]) - return 0; - else - print("Installing module "..arg[1].." locally, from luarocks repo") - os.execute("luarocks --tree='"..prosody.paths.plugins.."' install "..arg[1]) - return 0; - end + if arg[1] == "--help" then + show_usage([[make]], [[Installs a rockspec/rock from a specified server]]); + return 1; + end + -- Need to think about the case with many flags + local flag = "--tree=" + -- I'm considering the flag is the first, but there can be many flags + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + print("Installing module "..arg[2].." at "..dir..", from luarocks repo") + -- These extra double brackets allow us to correctly process names with spaces + os.execute("luarocks install --tree='"..dir.."' "..arg[2]) + return 0; + else + print("Installing module "..arg[1].." locally, from luarocks repo") + os.execute("luarocks --tree='"..prosody.paths.plugins.."' install "..arg[1]) + return 0; + end end function commands.list(arg) - if arg[1] == "--help" then + if arg[1] == "--help" then show_usage([[list]], [[Shows installed rocks]]); return 1; end - -- Need to think about the case with many flags - local flag = "--tree=" - -- I'm considering the flag is the first, but there can be many flags - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks list --tree='"..dir.."'") - return 0; - else - os.execute("luarocks list --tree="..prosody.paths.plugins) - return 0; - end + -- Need to think about the case with many flags + local flag = "--tree=" + -- I'm considering the flag is the first, but there can be many flags + if arg[1] and arg[1]:sub(1, #flag) == flag then + local dir = arg[1]:match("=(.+)$") + -- These extra double brackets allow us to correctly process names with spaces + os.execute("luarocks list --tree='"..dir.."'") + return 0; + else + os.execute("luarocks list --tree="..prosody.paths.plugins) + return 0; + end end function commands.admin_add(arg) - prosodyctl.admin_operation("add ", arg) - return 0; + prosodyctl.admin_operation("add ", arg) + return 0; end function commands.admin_remove(arg) - prosodyctl.admin_operation("remove ", arg) - return 0; + prosodyctl.admin_operation("remove ", arg) + return 0; end function commands.enabled_plugins(arg) - if arg[1] == "--help" then - show_usage([[enabled_plugins]], [[Shows plugins currently enabled on prosody]]); - return 1; + if arg[1] == "--help" then + show_usage([[enabled_plugins]], [[Shows plugins currently enabled on prosody]]); + return 1; end for module in modulemanager.get_modules_for_host() do show_warning("%s", module) @@ -224,24 +224,24 @@ function commands.enabled_plugins(arg) end function commands.local_plugins(arg) - if arg[1] == "--help" then - show_usage([[local_plugins]], [[Shows plugins currently available for prosody, locally]]); - return 1; + if arg[1] == "--help" then + show_usage([[local_plugins]], [[Shows plugins currently available for prosody, locally]]); + return 1; end local directory = "./plugins" - local i, t, popen = 0, {}, io.popen - local pfile = popen('ls -a "'..directory..'"') - for filename in pfile:lines() do + local i, t, popen = 0, {}, io.popen + local pfile = popen('ls -a "'..directory..'"') + for filename in pfile:lines() do if filename == "." or filename == ".." then i = i + 1 else i = i + 1 t[i] = filename show_warning("%s", t[i]) - end - end - pfile:close() - return 0; + end + end + pfile:close() + return 0; end function commands.adduser(arg) -- cgit v1.2.3 From 9da55591971c39bbc5f3c8d24b521be89dc51897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 23 Jul 2019 07:21:08 -0700 Subject: prosodyctl: Corrected output printed by the remove command --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 244a1a24..4831150c 100755 --- a/prosodyctl +++ b/prosodyctl @@ -151,12 +151,12 @@ function commands.remove(arg) -- I'm considering the flag is the first, but there can be many flags if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - print("Removing module "..arg[2].." at "..dir..", from luarocks repo") + print("Removing module "..arg[2].." at "..dir) -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) return 0; else - print("Removing "..arg[1].." from ./plugins") + print("Removing "..arg[1].." from "..prosody.paths.plugins) os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) print("Done!") return 0; -- cgit v1.2.3 From 94ba83d8e657ba8c934c1875dac049f2f4f38101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 23 Jul 2019 08:36:06 -0700 Subject: prosodyctl: Corrected the outputs from the install command --- prosodyctl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 4831150c..820a274f 100755 --- a/prosodyctl +++ b/prosodyctl @@ -165,7 +165,7 @@ end function commands.install(arg) if arg[1] == "--help" then - show_usage([[make]], [[Installs a rockspec/rock from a specified server]]); + show_usage([[make]], [[Installs a prosody/luarocks plugin]]); return 1; end -- Need to think about the case with many flags @@ -173,12 +173,12 @@ function commands.install(arg) -- I'm considering the flag is the first, but there can be many flags if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - print("Installing module "..arg[2].." at "..dir..", from luarocks repo") + print("Installing module "..arg[2].." at "..dir) -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks install --tree='"..dir.."' "..arg[2]) return 0; else - print("Installing module "..arg[1].." locally, from luarocks repo") + print("Installing module "..arg[1].." at "..prosody.paths.plugins) os.execute("luarocks --tree='"..prosody.paths.plugins.."' install "..arg[1]) return 0; end -- cgit v1.2.3 From d5026a6f633fddc5c459a6e63b3568c073029387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 23 Jul 2019 08:48:31 -0700 Subject: prosodyctl: The install command is now also checking a specified remote server --- prosodyctl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 820a274f..f485f517 100755 --- a/prosodyctl +++ b/prosodyctl @@ -175,11 +175,13 @@ function commands.install(arg) local dir = arg[1]:match("=(.+)$") print("Installing module "..arg[2].." at "..dir) -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks install --tree='"..dir.."' "..arg[2]) + os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) return 0; else print("Installing module "..arg[1].." at "..prosody.paths.plugins) - os.execute("luarocks --tree='"..prosody.paths.plugins.."' install "..arg[1]) + -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from + -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules + os.execute("luarocks --tree='"..prosody.paths.plugins.."' --server='http://localhost/' install "..arg[1]) return 0; end end -- cgit v1.2.3 From a935d786f3ad27b543eae92d8ac404442c2cc6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 23 Jul 2019 10:26:00 -0700 Subject: prosodyctl: The install command now prints output regarding module configuration --- prosodyctl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index f485f517..26d6a850 100755 --- a/prosodyctl +++ b/prosodyctl @@ -76,6 +76,7 @@ local show_usage = prosodyctl.show_usage; local show_yesno = prosodyctl.show_yesno; local show_prompt = prosodyctl.show_prompt; local read_password = prosodyctl.read_password; +local show_module_configuration_help = prosodyctl.show_module_configuration_help; local jid_split = require "util.jid".prepped_split; @@ -176,12 +177,14 @@ function commands.install(arg) print("Installing module "..arg[2].." at "..dir) -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) + show_module_configuration_help(arg[2]); return 0; else print("Installing module "..arg[1].." at "..prosody.paths.plugins) -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules os.execute("luarocks --tree='"..prosody.paths.plugins.."' --server='http://localhost/' install "..arg[1]) + show_module_configuration_help(arg[1]); return 0; end end -- cgit v1.2.3 From ecd9e8f5d771da2fffa4721df0880756c2203714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 23 Jul 2019 13:27:19 -0700 Subject: prosodyctl: Created a temporary function, that automatically sets up a repo with rockspecs for prosody modules --- prosodyctl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 26d6a850..13494bb8 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,6 +85,43 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); +function commands.magic(arg) + --print("Getting all the available modules") + --os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") + local i, popen = 0, io.popen + local flag = "mod_" + os.execute("mkdir repository") + local pfile = popen('ls -a "'..arg[1]..'"') + for filename in pfile:lines() do + i = i + 1 + if filename:sub(1, #flag) == flag then + local file = io.open("repository/"..filename.."-scm-1.rockspec", "w") + file:write('package = "'..filename..'"', '\n') + file:write('version = "scm-1"', '\n') + file:write('source = {', '\n') + file:write('\turl = "hg+https://hg.prosody.im/prosody-modules",', '\n') + file:write('\tdir = "prosody-modules"', '\n') + file:write('}', '\n') + file:write('description = {', '\n') + file:write('\thomepage = "https://prosody.im/",', '\n') + file:write('\tlicense = "MIT"', '\n') + file:write('}', '\n') + file:write('dependencies = {', '\n') + file:write('\t"lua >= 5.1"', '\n') + file:write('}', '\n') + file:write('build = {', '\n') + file:write('\ttype = "builtin",', '\n') + file:write('\tmodules = {', '\n') + file:write('\t\t["'..filename..'.'..filename..'"] = "'..filename..'/'..filename..'.lua"', '\n') + file:write('\t}', '\n') + file:write('}', '\n') + file:close() + end + end + pfile:close() + os.execute("cd repository/ && luarocks-admin make_manifest ./ && chmod -R 644 ./*") +end + -- This function receives no arguments. It clones all the plugins from prosody's plugin repository function commands.get_modules(arg) if arg[1] == "--help" then -- cgit v1.2.3 From 447b7f8731db9be3caab0e8500caa2cafe168ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 04:24:29 -0700 Subject: prosodyctl: Removed the development commands magic, get_modules and write_rockspec --- prosodyctl | 82 -------------------------------------------------------------- 1 file changed, 82 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 13494bb8..420337da 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,88 +85,6 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); -function commands.magic(arg) - --print("Getting all the available modules") - --os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") - local i, popen = 0, io.popen - local flag = "mod_" - os.execute("mkdir repository") - local pfile = popen('ls -a "'..arg[1]..'"') - for filename in pfile:lines() do - i = i + 1 - if filename:sub(1, #flag) == flag then - local file = io.open("repository/"..filename.."-scm-1.rockspec", "w") - file:write('package = "'..filename..'"', '\n') - file:write('version = "scm-1"', '\n') - file:write('source = {', '\n') - file:write('\turl = "hg+https://hg.prosody.im/prosody-modules",', '\n') - file:write('\tdir = "prosody-modules"', '\n') - file:write('}', '\n') - file:write('description = {', '\n') - file:write('\thomepage = "https://prosody.im/",', '\n') - file:write('\tlicense = "MIT"', '\n') - file:write('}', '\n') - file:write('dependencies = {', '\n') - file:write('\t"lua >= 5.1"', '\n') - file:write('}', '\n') - file:write('build = {', '\n') - file:write('\ttype = "builtin",', '\n') - file:write('\tmodules = {', '\n') - file:write('\t\t["'..filename..'.'..filename..'"] = "'..filename..'/'..filename..'.lua"', '\n') - file:write('\t}', '\n') - file:write('}', '\n') - file:close() - end - end - pfile:close() - os.execute("cd repository/ && luarocks-admin make_manifest ./ && chmod -R 644 ./*") -end - --- This function receives no arguments. It clones all the plugins from prosody's plugin repository -function commands.get_modules(arg) - if arg[1] == "--help" then - show_usage([[get_modules]], [[Downloads all available modules]]); - return 1; - end - if os.execute '[ -e "./downloaded_modules" ]' then - print("The modules have already been imported") - print("Do you want to re-import?(Y/N)") - local answer = io.read() - if answer == "Y" then - print("Deleting previous imports") - os.execute("rm -rf downloaded_modules") - print("Downloading plugins") - os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") - print("Done!") - return 0; - else - print("We keep what we have then!") - return 0; - end - else - print("Getting all the available modules") - os.execute("hg clone https://hg.prosody.im/prosody-modules/ downloaded_modules") - print("Done!") - return 0; - end -end - --- Function to write rockspecs from a module at working_directory/downloaded_modules --- Receives the module's name as an argument --- The rockspec is saved inside its module's folder -function commands.write_rockspec(arg) - if arg[1] == "--help" then - show_usage([[write_rockspec]], [[Picks up a module and writes an initial rockspec]]); - return 1; - end - print("Writing rockspec for "..arg[1]) - os.execute("luarocks write_rockspec "..arg[1].." ./downloaded_modules/"..arg[1]) - print("Rockspec created! Moving it into the ./downloaded_modules/"..arg[1].." folder") - os.execute("mv "..arg[1].."-scm-1.rockspec ./downloaded_modules/"..arg[1]) - print("Done!") - return 0; -end - -- Command to install a rockspec with local sources -- The module is installed at the plugins folder function commands.make(arg) -- cgit v1.2.3 From d38ebec46613682f618c932b1ab16b6ca5f9e6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 04:42:45 -0700 Subject: prosodyctl: Removed the make, admin_add and admin_remove commands --- prosodyctl | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 420337da..14db6c29 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,17 +85,6 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); --- Command to install a rockspec with local sources --- The module is installed at the plugins folder -function commands.make(arg) - if arg[1] == "--help" then - show_usage([[make]], [[Installs a module with sources available locally]]); - return 1; - end - os.execute("cd downloaded_modules/"..arg[1].." && luarocks --tree='../../plugins' make "..arg[1].."-scm-1.rockspec") - return 0; -end - -- Command to remove a rockspec -- Receives as an argument the name of the plugin to be removed from the plugins folder function commands.remove(arg) @@ -163,16 +152,6 @@ function commands.list(arg) end end -function commands.admin_add(arg) - prosodyctl.admin_operation("add ", arg) - return 0; -end - -function commands.admin_remove(arg) - prosodyctl.admin_operation("remove ", arg) - return 0; -end - function commands.enabled_plugins(arg) if arg[1] == "--help" then show_usage([[enabled_plugins]], [[Shows plugins currently enabled on prosody]]); -- cgit v1.2.3 From b291e91de25427e836f74cb41ab9ee644fd510c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 04:53:02 -0700 Subject: prosodyctl: Removed the admin_add and admin_remove from the commands_order variable --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 14db6c29..ae73ed54 100755 --- a/prosodyctl +++ b/prosodyctl @@ -1448,8 +1448,8 @@ local command_runner = async.runner(function () print("Where COMMAND may be one of:\n"); local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; - local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about", "local_plugins", "enabled_plugins", - "admin_add", "admin_remove", "list", }; + local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about", "local_plugins", + "enabled_plugins", "list"}; local done = {}; -- cgit v1.2.3 From e1969065c487c60fa6df682d2aca5614d2dae690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 04:59:46 -0700 Subject: prosodyctl: Added the install and remove arguments to the reorganized commands_order variable --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index ae73ed54..905e00cf 100755 --- a/prosodyctl +++ b/prosodyctl @@ -1448,8 +1448,8 @@ local command_runner = async.runner(function () print("Where COMMAND may be one of:\n"); local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; - local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about", "local_plugins", - "enabled_plugins", "list"}; + local commands_order = { "install", "remove", "list", "enabled_plugins", "local_plugins","adduser", "passwd", "deluser", "start", "stop", "restart", + "reload", "about", "list" }; local done = {}; -- cgit v1.2.3 From f736aec6b2c3062216b6f7481bd80a2444ffc36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 05:01:35 -0700 Subject: prosodyctl: Corrected the remove and install commands' order --- prosodyctl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 905e00cf..2fd3084d 100755 --- a/prosodyctl +++ b/prosodyctl @@ -85,50 +85,50 @@ local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * local commands = {}; local command = table.remove(arg, 1); --- Command to remove a rockspec --- Receives as an argument the name of the plugin to be removed from the plugins folder -function commands.remove(arg) +function commands.install(arg) if arg[1] == "--help" then - show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); + show_usage([[make]], [[Installs a prosody/luarocks plugin]]); return 1; end + -- Need to think about the case with many flags local flag = "--tree=" -- I'm considering the flag is the first, but there can be many flags if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - print("Removing module "..arg[2].." at "..dir) + print("Installing module "..arg[2].." at "..dir) -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) + os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) + show_module_configuration_help(arg[2]); return 0; else - print("Removing "..arg[1].." from "..prosody.paths.plugins) - os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) - print("Done!") + print("Installing module "..arg[1].." at "..prosody.paths.plugins) + -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from + -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules + os.execute("luarocks --tree='"..prosody.paths.plugins.."' --server='http://localhost/' install "..arg[1]) + show_module_configuration_help(arg[1]); return 0; end end -function commands.install(arg) +-- Command to remove a rockspec +-- Receives as an argument the name of the plugin to be removed from the plugins folder +function commands.remove(arg) if arg[1] == "--help" then - show_usage([[make]], [[Installs a prosody/luarocks plugin]]); + show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end - -- Need to think about the case with many flags local flag = "--tree=" -- I'm considering the flag is the first, but there can be many flags if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - print("Installing module "..arg[2].." at "..dir) + print("Removing module "..arg[2].." at "..dir) -- These extra double brackets allow us to correctly process names with spaces - os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) - show_module_configuration_help(arg[2]); + os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) return 0; else - print("Installing module "..arg[1].." at "..prosody.paths.plugins) - -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from - -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules - os.execute("luarocks --tree='"..prosody.paths.plugins.."' --server='http://localhost/' install "..arg[1]) - show_module_configuration_help(arg[1]); + print("Removing "..arg[1].." from "..prosody.paths.plugins) + os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) + print("Done!") return 0; end end -- cgit v1.2.3 From 46ae143d9a6a51b72365b8d2781e7d45d8e332c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 05:07:57 -0700 Subject: prosodyctl: Removed/rewrote comments at the install, remove and list commands --- prosodyctl | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 2fd3084d..be6df959 100755 --- a/prosodyctl +++ b/prosodyctl @@ -90,13 +90,11 @@ function commands.install(arg) show_usage([[make]], [[Installs a prosody/luarocks plugin]]); return 1; end - -- Need to think about the case with many flags + -- I'm considering this optional flag comes first local flag = "--tree=" - -- I'm considering the flag is the first, but there can be many flags if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") print("Installing module "..arg[2].." at "..dir) - -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) show_module_configuration_help(arg[2]); return 0; @@ -110,19 +108,16 @@ function commands.install(arg) end end --- Command to remove a rockspec --- Receives as an argument the name of the plugin to be removed from the plugins folder function commands.remove(arg) if arg[1] == "--help" then show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end local flag = "--tree=" - -- I'm considering the flag is the first, but there can be many flags + -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") print("Removing module "..arg[2].." at "..dir) - -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) return 0; else @@ -138,12 +133,10 @@ function commands.list(arg) show_usage([[list]], [[Shows installed rocks]]); return 1; end - -- Need to think about the case with many flags local flag = "--tree=" - -- I'm considering the flag is the first, but there can be many flags + -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - -- These extra double brackets allow us to correctly process names with spaces os.execute("luarocks list --tree='"..dir.."'") return 0; else -- cgit v1.2.3 From 27e711c5876b0008fa871b26787c0c134e90d744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 10:43:28 -0700 Subject: prosodyctl: The install command now performs its job at a dedicated folder for custom plugins --- prosodyctl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index be6df959..1c702576 100755 --- a/prosodyctl +++ b/prosodyctl @@ -90,6 +90,12 @@ function commands.install(arg) show_usage([[make]], [[Installs a prosody/luarocks plugin]]); return 1; end + local installer_plugin_path + -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now + for path in prosody.paths.plugins:gmatch("[^;]+") do + installer_plugin_path = path + break + end -- I'm considering this optional flag comes first local flag = "--tree=" if arg[1] and arg[1]:sub(1, #flag) == flag then @@ -99,10 +105,10 @@ function commands.install(arg) show_module_configuration_help(arg[2]); return 0; else - print("Installing module "..arg[1].." at "..prosody.paths.plugins) + print("Installing module "..arg[1].." at "..installer_plugin_path) -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules - os.execute("luarocks --tree='"..prosody.paths.plugins.."' --server='http://localhost/' install "..arg[1]) + os.execute("luarocks --tree='"..installer_plugin_path.."' --server='http://localhost/' install "..arg[1]) show_module_configuration_help(arg[1]); return 0; end -- cgit v1.2.3 From cf695f88f1bc15c7ccb69c65aee555579ad80da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 10:46:05 -0700 Subject: prosodyctl: Updated the remove command to use the new directory for custom plugins --- prosodyctl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 1c702576..33f58fc1 100755 --- a/prosodyctl +++ b/prosodyctl @@ -119,6 +119,11 @@ function commands.remove(arg) show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end + -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now + for path in prosody.paths.plugins:gmatch("[^;]+") do + installer_plugin_path = path + break + end local flag = "--tree=" -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then @@ -127,8 +132,8 @@ function commands.remove(arg) os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) return 0; else - print("Removing "..arg[1].." from "..prosody.paths.plugins) - os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1]) + print("Removing "..arg[1].." from "..installer_plugin_path) + os.execute("luarocks --tree='"..installer_plugin_path.."' remove "..arg[1]) print("Done!") return 0; end -- cgit v1.2.3 From f1a27b4554175c04fbd3c5ffedbc5b9e6ad40967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 10:48:20 -0700 Subject: prosodyctl: Updated the list command, to use the new directory for custom plugins --- prosodyctl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 33f58fc1..777b2c30 100755 --- a/prosodyctl +++ b/prosodyctl @@ -144,6 +144,11 @@ function commands.list(arg) show_usage([[list]], [[Shows installed rocks]]); return 1; end + -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now + for path in prosody.paths.plugins:gmatch("[^;]+") do + installer_plugin_path = path + break + end local flag = "--tree=" -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then @@ -151,7 +156,7 @@ function commands.list(arg) os.execute("luarocks list --tree='"..dir.."'") return 0; else - os.execute("luarocks list --tree="..prosody.paths.plugins) + os.execute("luarocks list --tree="..installer_plugin_path) return 0; end end -- cgit v1.2.3 From 843f28994734b5791eb1f011dd60de87e2b2fa7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 11:26:29 -0700 Subject: prosodyctl: Custom plugins paths are now retrieved by an helper function --- prosodyctl | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 777b2c30..c50900f2 100755 --- a/prosodyctl +++ b/prosodyctl @@ -90,12 +90,7 @@ function commands.install(arg) show_usage([[make]], [[Installs a prosody/luarocks plugin]]); return 1; end - local installer_plugin_path - -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now - for path in prosody.paths.plugins:gmatch("[^;]+") do - installer_plugin_path = path - break - end + local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) -- I'm considering this optional flag comes first local flag = "--tree=" if arg[1] and arg[1]:sub(1, #flag) == flag then @@ -120,10 +115,7 @@ function commands.remove(arg) return 1; end -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now - for path in prosody.paths.plugins:gmatch("[^;]+") do - installer_plugin_path = path - break - end + local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) local flag = "--tree=" -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then @@ -145,10 +137,7 @@ function commands.list(arg) return 1; end -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now - for path in prosody.paths.plugins:gmatch("[^;]+") do - installer_plugin_path = path - break - end + local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) local flag = "--tree=" -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then -- cgit v1.2.3 From d93db0b931b21e041baf0badb7b5224ebced7a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 24 Jul 2019 11:29:55 -0700 Subject: prosodyctl: Removed the local_plugins command --- prosodyctl | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index c50900f2..cf51ca7d 100755 --- a/prosodyctl +++ b/prosodyctl @@ -160,27 +160,6 @@ function commands.enabled_plugins(arg) end end -function commands.local_plugins(arg) - if arg[1] == "--help" then - show_usage([[local_plugins]], [[Shows plugins currently available for prosody, locally]]); - return 1; - end - local directory = "./plugins" - local i, t, popen = 0, {}, io.popen - local pfile = popen('ls -a "'..directory..'"') - for filename in pfile:lines() do - if filename == "." or filename == ".." then - i = i + 1 - else - i = i + 1 - t[i] = filename - show_warning("%s", t[i]) - end - end - pfile:close() - return 0; -end - function commands.adduser(arg) if not arg[1] or arg[1] == "--help" then show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); @@ -1446,8 +1425,8 @@ local command_runner = async.runner(function () print("Where COMMAND may be one of:\n"); local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; - local commands_order = { "install", "remove", "list", "enabled_plugins", "local_plugins","adduser", "passwd", "deluser", "start", "stop", "restart", - "reload", "about", "list" }; + local commands_order = { "install", "remove", "list", "enabled_plugins", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", + "about", "list" }; local done = {}; -- cgit v1.2.3 From 47421968357f79d18b68ca8999bc1c17b8a786e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Thu, 25 Jul 2019 04:25:40 -0700 Subject: prosodyctl: Removed the list duplicate at the commands_order variable --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index cf51ca7d..54e883b2 100755 --- a/prosodyctl +++ b/prosodyctl @@ -1426,7 +1426,7 @@ local command_runner = async.runner(function () local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; local commands_order = { "install", "remove", "list", "enabled_plugins", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", - "about", "list" }; + "about" }; local done = {}; -- cgit v1.2.3 From 449256fa0c00cce042fe8dc1a2b18bcbc0c07258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 26 Jul 2019 05:53:18 -0700 Subject: prosodyctl: Corrected the help output of the install and remove commands --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 54e883b2..9990a485 100755 --- a/prosodyctl +++ b/prosodyctl @@ -87,7 +87,7 @@ local command = table.remove(arg, 1); function commands.install(arg) if arg[1] == "--help" then - show_usage([[make]], [[Installs a prosody/luarocks plugin]]); + show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) @@ -111,7 +111,7 @@ end function commands.remove(arg) if arg[1] == "--help" then - show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]); + show_usage([[remove]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now -- cgit v1.2.3 From 1e03cec66433732be858cca013ce8c9f84169c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 05:47:36 -0700 Subject: prosodyctl: Swapped prints for the show_message function at the install/remove commands --- prosodyctl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 9990a485..72f7cbb5 100755 --- a/prosodyctl +++ b/prosodyctl @@ -95,12 +95,12 @@ function commands.install(arg) local flag = "--tree=" if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - print("Installing module "..arg[2].." at "..dir) + show_message("Installing module %s at %s", arg[2], dir) os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) show_module_configuration_help(arg[2]); return 0; else - print("Installing module "..arg[1].." at "..installer_plugin_path) + show_message("Installing module %s at %s", arg[1], installer_plugin_path) -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules os.execute("luarocks --tree='"..installer_plugin_path.."' --server='http://localhost/' install "..arg[1]) @@ -120,13 +120,12 @@ function commands.remove(arg) -- I'm considering this optional flag comes first if arg[1] and arg[1]:sub(1, #flag) == flag then local dir = arg[1]:match("=(.+)$") - print("Removing module "..arg[2].." at "..dir) + show_message("Removing module %s at %s", arg[2], dir) os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) return 0; else - print("Removing "..arg[1].." from "..installer_plugin_path) + show_message("Removing %s from %s", arg[1], installer_plugin_path) os.execute("luarocks --tree='"..installer_plugin_path.."' remove "..arg[1]) - print("Done!") return 0; end end -- cgit v1.2.3 From 372a90aff6bb86406df0e56f65ff0427b7b01172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 05:55:32 -0700 Subject: prosodyctl: Removed unnecessary comments from the remove command --- prosodyctl | 1 - 1 file changed, 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 72f7cbb5..24874ade 100755 --- a/prosodyctl +++ b/prosodyctl @@ -114,7 +114,6 @@ function commands.remove(arg) show_usage([[remove]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end - -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) local flag = "--tree=" -- I'm considering this optional flag comes first -- cgit v1.2.3 From 7e472f4b26c85841e3306cf46b3bfd378dabca25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 07:31:03 -0700 Subject: prosodyctl: Rewrote the install command, to make it more cleaner --- prosodyctl | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 24874ade..18db72b7 100755 --- a/prosodyctl +++ b/prosodyctl @@ -76,7 +76,9 @@ local show_usage = prosodyctl.show_usage; local show_yesno = prosodyctl.show_yesno; local show_prompt = prosodyctl.show_prompt; local read_password = prosodyctl.read_password; -local show_module_configuration_help = prosodyctl.show_module_configuration_help; +local check_flags = prosodyctl.check_flags; +local call_luarocks = prosodyctl.call_luarocks; +local get_path_custom_plugins = prosodyctl.get_path_custom_plugins; local jid_split = require "util.jid".prepped_split; @@ -90,21 +92,14 @@ function commands.install(arg) show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end - local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) - -- I'm considering this optional flag comes first - local flag = "--tree=" - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - show_message("Installing module %s at %s", arg[2], dir) - os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' install "..arg[2]) - show_module_configuration_help(arg[2]); + local operation = "install"; + local tree, mod, dir = check_flags(arg); + if tree then + call_luarocks(operation, mod, dir); return 0; else - show_message("Installing module %s at %s", arg[1], installer_plugin_path) - -- I've build a local server to upload some new rockspecs, like mod_smacks'. We can replace this server by one from - -- prosody's, where we can oficially disbrute rocks/rockspecs for all modules - os.execute("luarocks --tree='"..installer_plugin_path.."' --server='http://localhost/' install "..arg[1]) - show_module_configuration_help(arg[1]); + dir = get_path_custom_plugins(prosody.paths.plugins); + call_luarocks(operation, mod, dir); return 0; end end -- cgit v1.2.3 From f74f2d0d17b792139c85d44cbb4a64939bd2347e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 10:07:22 -0700 Subject: prosodyctl: Rewrote the remove command, to make it cleaner and easier to work with --- prosodyctl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 18db72b7..b92b166b 100755 --- a/prosodyctl +++ b/prosodyctl @@ -109,17 +109,14 @@ function commands.remove(arg) show_usage([[remove]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end - local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) - local flag = "--tree=" - -- I'm considering this optional flag comes first - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - show_message("Removing module %s at %s", arg[2], dir) - os.execute("luarocks remove --tree='"..dir.."' "..arg[2]) + local operation = "remove"; + local tree, mod, dir = check_flags(arg); + if tree then + call_luarocks(operation, mod, dir); return 0; else - show_message("Removing %s from %s", arg[1], installer_plugin_path) - os.execute("luarocks --tree='"..installer_plugin_path.."' remove "..arg[1]) + dir = get_path_custom_plugins(prosody.paths.plugins); + call_luarocks(operation, mod, dir); return 0; end end -- cgit v1.2.3 From 849165ba69da619e45f7d4da5e0ae2554cea35a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 10:22:40 -0700 Subject: prosodyctl: Rewrote the list command, to make it cleaner and easier to work with --- prosodyctl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index b92b166b..c0690293 100755 --- a/prosodyctl +++ b/prosodyctl @@ -126,16 +126,14 @@ function commands.list(arg) show_usage([[list]], [[Shows installed rocks]]); return 1; end - -- I'm considering that we are using just one path to custom plugins, and it is the first in prosody.paths.plugins, for now - local installer_plugin_path = prosodyctl.get_path_custom_plugins(prosody.paths.plugins) - local flag = "--tree=" - -- I'm considering this optional flag comes first - if arg[1] and arg[1]:sub(1, #flag) == flag then - local dir = arg[1]:match("=(.+)$") - os.execute("luarocks list --tree='"..dir.."'") + local operation = "list"; + local tree, mod, dir = check_flags(arg); + if tree then + call_luarocks(operation, mod, dir); return 0; else - os.execute("luarocks list --tree="..installer_plugin_path) + dir = get_path_custom_plugins(prosody.paths.plugins); + call_luarocks(operation, mod, dir); return 0; end end -- cgit v1.2.3 From 5ba7a798fbf368a845cfc3fd04c3241d29f75d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 11:01:36 -0700 Subject: prosodyctl: The install, remove and list commands now work by calling the execute_command function --- prosodyctl | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index c0690293..57632964 100755 --- a/prosodyctl +++ b/prosodyctl @@ -76,9 +76,7 @@ local show_usage = prosodyctl.show_usage; local show_yesno = prosodyctl.show_yesno; local show_prompt = prosodyctl.show_prompt; local read_password = prosodyctl.read_password; -local check_flags = prosodyctl.check_flags; -local call_luarocks = prosodyctl.call_luarocks; -local get_path_custom_plugins = prosodyctl.get_path_custom_plugins; +local execute_command = prosodyctl.execute_command; local jid_split = require "util.jid".prepped_split; @@ -92,16 +90,8 @@ function commands.install(arg) show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end - local operation = "install"; - 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 + table.insert(arg, "install"); + execute_command(arg); end function commands.remove(arg) @@ -109,16 +99,8 @@ function commands.remove(arg) show_usage([[remove]], [[Removes a module installed in the wroking directory's plugins folder]]); return 1; end - local operation = "remove"; - 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 + table.insert(arg, "remove"); + execute_command(arg); end function commands.list(arg) @@ -126,16 +108,8 @@ function commands.list(arg) show_usage([[list]], [[Shows installed rocks]]); return 1; end - local operation = "list"; - 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 + table.insert(arg, "list"); + execute_command(arg); end function commands.enabled_plugins(arg) -- cgit v1.2.3 From 3fe8683f5ec784091353788cf7f1b722747e489a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 31 Jul 2019 11:13:14 -0700 Subject: prosodyctl: Removed the auxiliary command 'enabled_plugins' --- prosodyctl | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 57632964..9c94fea4 100755 --- a/prosodyctl +++ b/prosodyctl @@ -112,16 +112,6 @@ function commands.list(arg) execute_command(arg); end -function commands.enabled_plugins(arg) - if arg[1] == "--help" then - show_usage([[enabled_plugins]], [[Shows plugins currently enabled on prosody]]); - return 1; - end - for module in modulemanager.get_modules_for_host() do - show_warning("%s", module) - end -end - function commands.adduser(arg) if not arg[1] or arg[1] == "--help" then show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); @@ -1387,7 +1377,7 @@ local command_runner = async.runner(function () print("Where COMMAND may be one of:\n"); local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; - local commands_order = { "install", "remove", "list", "enabled_plugins", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", + local commands_order = { "install", "remove", "list", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about" }; local done = {}; -- cgit v1.2.3 From ce4f9d56d998d47c6466a7ae2edd1149d88bd334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 16 Aug 2019 08:38:29 -0700 Subject: prosodyctl: Fixed a typo --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 9c94fea4..4c8892ac 100755 --- a/prosodyctl +++ b/prosodyctl @@ -96,7 +96,7 @@ end function commands.remove(arg) if arg[1] == "--help" then - show_usage([[remove]], [[Removes a module installed in the wroking directory's plugins folder]]); + show_usage([[remove]], [[Removes a module installed in the working directory's plugins folder]]); return 1; end table.insert(arg, "remove"); -- cgit v1.2.3 From 9d8380db119f65c4bb6d5ef5701c35e7b5722e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Fri, 16 Aug 2019 14:58:29 -0700 Subject: prosodyctl: Install, remove and list commands now use the call_luarocks function --- prosodyctl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 4c8892ac..664deb51 100755 --- a/prosodyctl +++ b/prosodyctl @@ -76,7 +76,7 @@ local show_usage = prosodyctl.show_usage; local show_yesno = prosodyctl.show_yesno; local show_prompt = prosodyctl.show_prompt; local read_password = prosodyctl.read_password; -local execute_command = prosodyctl.execute_command; +local call_luarocks = prosodyctl.call_luarocks; local jid_split = require "util.jid".prepped_split; @@ -90,8 +90,7 @@ function commands.install(arg) show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end - table.insert(arg, "install"); - execute_command(arg); + call_luarocks(arg[1], "install") end function commands.remove(arg) @@ -99,8 +98,7 @@ function commands.remove(arg) show_usage([[remove]], [[Removes a module installed in the working directory's plugins folder]]); return 1; end - table.insert(arg, "remove"); - execute_command(arg); + call_luarocks(arg[1], "remove") end function commands.list(arg) @@ -108,8 +106,7 @@ function commands.list(arg) show_usage([[list]], [[Shows installed rocks]]); return 1; end - table.insert(arg, "list"); - execute_command(arg); + call_luarocks(arg[1], "list") end function commands.adduser(arg) -- cgit v1.2.3 From f6983a3d514a29fb8eab260f65373523450046cf Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 1 Nov 2019 23:16:58 +0100 Subject: prosodyctl: Print friendly version of error messages --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 82b5faaa..a4724a19 100755 --- a/prosodyctl +++ b/prosodyctl @@ -144,7 +144,7 @@ function commands.adduser(arg) if ok then return 0; end - show_message(msg) + show_message(error_messages[msg]) return 1; end -- cgit v1.2.3 From 5d10f5303be4464df34bb482cdbb561615ad7445 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Jan 2020 16:52:32 +0100 Subject: prosodyctl: Add 'daemonize' to deprecated options known by check command --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index cc3ca3a5..964285a0 100755 --- a/prosodyctl +++ b/prosodyctl @@ -871,7 +871,7 @@ function commands.check(arg) print("Checking config..."); local deprecated = set.new({ "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption", - "vcard_compatibility", "cross_domain_bosh", "cross_domain_websocket" + "vcard_compatibility", "cross_domain_bosh", "cross_domain_websocket", "daemonize", }); local known_global_options = set.new({ "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", -- cgit v1.2.3 From a355440c01d5ece456bda9c5a4f302ec82929dff Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 1 Jun 2020 15:44:44 +0100 Subject: prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell --- prosodyctl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 964285a0..43ed47c3 100755 --- a/prosodyctl +++ b/prosodyctl @@ -1356,6 +1356,10 @@ function commands.check(arg) return ok and 0 or 2; end +function commands.shell(arg) + require "util.prosodyctl.shell".start(arg); +end + --------------------- local async = require "util.async"; -- 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 --- prosodyctl | 836 +------------------------------------------------------------ 1 file changed, 11 insertions(+), 825 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 43ed47c3..3b5291d6 100755 --- a/prosodyctl +++ b/prosodyctl @@ -49,20 +49,6 @@ startup.prosodyctl(); ----------- -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 }); - local configmanager = require "core.configmanager"; local modulemanager = require "core.modulemanager" local prosodyctl = require "util.prosodyctl" @@ -72,12 +58,13 @@ local lfs = dependencies.softreq "lfs"; ----------------------- +local human_io = require "util.human.io"; + local show_message, show_warning = prosodyctl.show_message, prosodyctl.show_warning; local show_usage = prosodyctl.show_usage; -local show_yesno = prosodyctl.show_yesno; -local show_prompt = prosodyctl.show_prompt; -local read_password = prosodyctl.read_password; +local read_password = human_io.read_password; local call_luarocks = prosodyctl.call_luarocks; +local error_messages = prosodyctl.error_messages; local jid_split = require "util.jid".prepped_split; @@ -552,814 +539,6 @@ function commands.unregister(arg) return 1; end -local openssl; - -local cert_commands = {}; - --- If a file already exists, ask if the user wants to use it or replace it --- Backups the old file if replaced -local function use_existing(filename) - local attrs = lfs.attributes(filename); - if attrs then - if show_yesno(filename .. " exists, do you want to replace it? [y/n]") then - local backup = filename..".bkp~"..os.date("%FT%T", attrs.change); - os.rename(filename, backup); - show_message(filename.." backed up to "..backup); - else - -- Use the existing file - return true; - end - end -end - -local have_pposix, pposix = pcall(require, "util.pposix"); -local cert_basedir = prosody.paths.data == "." and "./certs" or prosody.paths.data; -if have_pposix and pposix.getuid() == 0 then - -- FIXME should be enough to check if this directory is writable - local cert_dir = configmanager.get("*", "certificates") or "certs"; - cert_basedir = configmanager.resolve_relative_path(prosody.paths.config, cert_dir); -end - -function cert_commands.config(arg) - if #arg >= 1 and arg[1] ~= "--help" then - local conf_filename = cert_basedir .. "/" .. arg[1] .. ".cnf"; - if use_existing(conf_filename) then - return nil, conf_filename; - end - local distinguished_name; - if arg[#arg]:find("^/") then - distinguished_name = table.remove(arg); - end - local conf = openssl.config.new(); - conf:from_prosody(prosody.hosts, configmanager, arg); - if distinguished_name then - local dn = {}; - for k, v in distinguished_name:gmatch("/([^=/]+)=([^/]+)") do - table.insert(dn, k); - dn[k] = v; - end - conf.distinguished_name = dn; - else - show_message("Please provide details to include in the certificate config file."); - show_message("Leave the field empty to use the default value or '.' to exclude the field.") - for _, k in ipairs(openssl._DN_order) do - local v = conf.distinguished_name[k]; - if v then - local nv = nil; - if k == "commonName" then - v = arg[1] - elseif k == "emailAddress" then - v = "xmpp@" .. arg[1]; - elseif k == "countryName" then - local tld = arg[1]:match"%.([a-z]+)$"; - if tld and #tld == 2 and tld ~= "uk" then - v = tld:upper(); - end - end - nv = show_prompt(("%s (%s):"):format(k, nv or v)); - nv = (not nv or nv == "") and v or nv; - if nv:find"[\192-\252][\128-\191]+" then - conf.req.string_mask = "utf8only" - end - conf.distinguished_name[k] = nv ~= "." and nv or nil; - end - end - end - local conf_file, err = io.open(conf_filename, "w"); - if not conf_file then - show_warning("Could not open OpenSSL config file for writing"); - show_warning(err); - os.exit(1); - end - conf_file:write(conf:serialize()); - conf_file:close(); - print(""); - show_message("Config written to " .. conf_filename); - return nil, conf_filename; - else - show_usage("cert config HOSTNAME [HOSTNAME+]", "Builds a certificate config file covering the supplied hostname(s)") - end -end - -function cert_commands.key(arg) - if #arg >= 1 and arg[1] ~= "--help" then - local key_filename = cert_basedir .. "/" .. arg[1] .. ".key"; - if use_existing(key_filename) then - return nil, key_filename; - end - os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions - local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048); - local old_umask = pposix.umask("0377"); - if openssl.genrsa{out=key_filename, key_size} then - os.execute(("chmod 400 '%s'"):format(key_filename)); - show_message("Key written to ".. key_filename); - pposix.umask(old_umask); - return nil, key_filename; - end - show_message("There was a problem, see OpenSSL output"); - else - show_usage("cert key HOSTNAME ", "Generates a RSA key named HOSTNAME.key\n " - .."Prompts for a key size if none given") - end -end - -function cert_commands.request(arg) - if #arg >= 1 and arg[1] ~= "--help" then - local req_filename = cert_basedir .. "/" .. arg[1] .. ".req"; - if use_existing(req_filename) then - return nil, req_filename; - end - local _, key_filename = cert_commands.key({arg[1]}); - local _, conf_filename = cert_commands.config(arg); - if openssl.req{new=true, key=key_filename, utf8=true, sha256=true, config=conf_filename, out=req_filename} then - show_message("Certificate request written to ".. req_filename); - else - show_message("There was a problem, see OpenSSL output"); - end - else - show_usage("cert request HOSTNAME [HOSTNAME+]", "Generates a certificate request for the supplied hostname(s)") - end -end - -function cert_commands.generate(arg) - if #arg >= 1 and arg[1] ~= "--help" then - local cert_filename = cert_basedir .. "/" .. arg[1] .. ".crt"; - if use_existing(cert_filename) then - return nil, cert_filename; - end - local _, key_filename = cert_commands.key({arg[1]}); - local _, conf_filename = cert_commands.config(arg); - if key_filename and conf_filename and cert_filename - and openssl.req{new=true, x509=true, nodes=true, key=key_filename, - days=365, sha256=true, utf8=true, config=conf_filename, out=cert_filename} then - show_message("Certificate written to ".. cert_filename); - print(); - else - show_message("There was a problem, see OpenSSL output"); - end - else - show_usage("cert generate HOSTNAME [HOSTNAME+]", "Generates a self-signed certificate for the current hostname(s)") - end -end - -local function sh_esc(s) - return "'" .. s:gsub("'", "'\\''") .. "'"; -end - -local function copy(from, to, umask, owner, group) - local old_umask = umask and pposix.umask(umask); - local attrs = lfs.attributes(to); - if attrs then -- Move old file out of the way - local backup = to..".bkp~"..os.date("%FT%T", attrs.change); - os.rename(to, backup); - end - -- FIXME friendlier error handling, maybe move above backup back? - local input = assert(io.open(from)); - local output = assert(io.open(to, "w")); - local data = input:read(2^11); - while data and output:write(data) do - data = input:read(2^11); - end - assert(input:close()); - assert(output:close()); - if not prosody.installed then - -- FIXME this is possibly specific to GNU chown - os.execute(("chown -c --reference=%s %s"):format(sh_esc(cert_basedir), sh_esc(to))); - elseif owner and group then - local ok = os.execute(("chown %s:%s %s"):format(sh_esc(owner), sh_esc(group), sh_esc(to))); - assert(ok == true or ok == 0, "Failed to change ownership of "..to); - end - if old_umask then pposix.umask(old_umask); end - return true; -end - -function cert_commands.import(arg) - local hostnames = {}; - -- Move hostname arguments out of arg, the rest should be a list of paths - while arg[1] and prosody.hosts[ arg[1] ] do - table.insert(hostnames, table.remove(arg, 1)); - end - if hostnames[1] == nil then - local domains = os.getenv"RENEWED_DOMAINS"; -- Set if invoked via certbot - if domains then - for host in domains:gmatch("%S+") do - table.insert(hostnames, host); - end - else - for host in pairs(prosody.hosts) do - if host ~= "*" and configmanager.get(host, "enabled") ~= false then - table.insert(hostnames, host); - end - end - end - end - if not arg[1] or arg[1] == "--help" then -- Probably forgot the path - show_usage("cert import [HOSTNAME+] /path/to/certs [/other/paths/]+", - "Copies certificates to "..cert_basedir); - return 1; - end - local owner, group; - if pposix.getuid() == 0 then -- We need root to change ownership - owner = configmanager.get("*", "prosody_user") or "prosody"; - group = configmanager.get("*", "prosody_group") or owner; - end - local cm = require "core.certmanager"; - local imported = {}; - for _, host in ipairs(hostnames) do - for _, dir in ipairs(arg) do - local paths = cm.find_cert(dir, host); - if paths then - copy(paths.certificate, cert_basedir .. "/" .. host .. ".crt", nil, owner, group); - copy(paths.key, cert_basedir .. "/" .. host .. ".key", "0377", owner, group); - table.insert(imported, host); - else - -- TODO Say where we looked - show_warning("No certificate for host "..host.." found :("); - end - -- TODO Additional checks - -- Certificate names matches the hostname - -- Private key matches public key in certificate - end - end - if imported[1] then - show_message("Imported certificate and key for hosts "..table.concat(imported, ", ")); - local ok, err = prosodyctl.reload(); - if not ok and err ~= "not-running" then - show_message(error_messages[err]); - end - else - show_warning("No certificates imported :("); - return 1; - end -end - -function commands.cert(arg) - if #arg >= 1 and arg[1] ~= "--help" then - openssl = require "util.openssl"; - lfs = require "lfs"; - local cert_dir_attrs = lfs.attributes(cert_basedir); - if not cert_dir_attrs then - show_warning("The directory "..cert_basedir.." does not exist"); - return 1; -- TODO Should we create it? - end - local uid = pposix.getuid(); - if uid ~= 0 and uid ~= cert_dir_attrs.uid then - show_warning("The directory "..cert_basedir.." is not owned by the current user, won't be able to write files to it"); - return 1; - elseif not cert_dir_attrs.permissions then -- COMPAT with LuaFilesystem < 1.6.2 (hey CentOS!) - show_message("Unable to check permissions on "..cert_basedir.." (LuaFilesystem 1.6.2+ required)"); - show_message("Please confirm that Prosody (and only Prosody) can write to this directory)"); - elseif cert_dir_attrs.permissions:match("^%.w..%-..%-.$") then - show_warning("The directory "..cert_basedir.." not only writable by its owner"); - return 1; - end - local subcmd = table.remove(arg, 1); - if type(cert_commands[subcmd]) == "function" then - if subcmd ~= "import" then -- hostnames are optional for import - if not arg[1] then - show_message"You need to supply at least one hostname" - arg = { "--help" }; - end - if arg[1] ~= "--help" and not prosody.hosts[arg[1]] then - show_message(error_messages["no-such-host"]); - return 1; - end - end - return cert_commands[subcmd](arg); - elseif subcmd == "check" then - return commands.check({"certs"}); - end - end - show_usage("cert config|request|generate|key|import", "Helpers for generating X.509 certificates and keys.") - for _, cmd in pairs(cert_commands) do - print() - cmd{ "--help" } - end -end - -function commands.check(arg) - if arg[1] == "--help" then - show_usage([[check]], [[Perform basic checks on your Prosody installation]]); - return 1; - end - local what = table.remove(arg, 1); - local set = require "util.set"; - local it = require "util.iterators"; - local ok = true; - local function disabled_hosts(host, conf) return host ~= "*" and conf.enabled ~= false; end - local function enabled_hosts() return it.filter(disabled_hosts, pairs(configmanager.getconfig())); end - if not (what == nil or what == "disabled" or what == "config" or what == "dns" or what == "certs") then - show_warning("Don't know how to check '%s'. Try one of 'config', 'dns', 'certs' or 'disabled'.", what); - return 1; - end - if not what or what == "disabled" then - local disabled_hosts_set = set.new(); - for host, host_options in it.filter("*", pairs(configmanager.getconfig())) do - if host_options.enabled == false then - disabled_hosts_set:add(host); - end - end - if not disabled_hosts_set:empty() then - local msg = "Checks will be skipped for these disabled hosts: %s"; - if what then msg = "These hosts are disabled: %s"; end - show_warning(msg, tostring(disabled_hosts_set)); - if what then return 0; end - print"" - end - end - if not what or what == "config" then - print("Checking config..."); - local deprecated = set.new({ - "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption", - "vcard_compatibility", "cross_domain_bosh", "cross_domain_websocket", "daemonize", - }); - local known_global_options = set.new({ - "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", - "umask", "prosodyctl_timeout", "use_ipv6", "use_libevent", "network_settings", - "network_backend", "http_default_host", - "statistics_interval", "statistics", "statistics_config", - }); - local config = configmanager.getconfig(); - -- Check that we have any global options (caused by putting a host at the top) - if it.count(it.filter("log", pairs(config["*"]))) == 0 then - ok = false; - print(""); - print(" No global options defined. Perhaps you have put a host definition at the top") - print(" of the config file? They should be at the bottom, see https://prosody.im/doc/configure#overview"); - end - if it.count(enabled_hosts()) == 0 then - ok = false; - print(""); - if it.count(it.filter("*", pairs(config))) == 0 then - print(" No hosts are defined, please add at least one VirtualHost section") - elseif config["*"]["enabled"] == false then - print(" No hosts are enabled. Remove enabled = false from the global section or put enabled = true under at least one VirtualHost section") - else - print(" All hosts are disabled. Remove enabled = false from at least one VirtualHost section") - end - end - if not config["*"].modules_enabled then - print(" No global modules_enabled is set?"); - local suggested_global_modules; - for host, options in enabled_hosts() do --luacheck: ignore 213/host - if not options.component_module and options.modules_enabled then - suggested_global_modules = set.intersection(suggested_global_modules or set.new(options.modules_enabled), set.new(options.modules_enabled)); - end - end - if suggested_global_modules and not suggested_global_modules:empty() then - print(" Consider moving these modules into modules_enabled in the global section:") - print(" "..tostring(suggested_global_modules / function (x) return ("%q"):format(x) end)); - end - print(); - end - - do -- Check for modules enabled both normally and as components - local modules = set.new(config["*"]["modules_enabled"]); - for host, options in enabled_hosts() do - local component_module = options.component_module; - if component_module and modules:contains(component_module) then - print((" mod_%s is enabled both in modules_enabled and as Component %q %q"):format(component_module, host, component_module)); - print(" This means the service is enabled on all VirtualHosts as well as the Component."); - print(" Are you sure this what you want? It may cause unexpected behaviour."); - end - end - end - - -- Check for global options under hosts - local global_options = set.new(it.to_array(it.keys(config["*"]))); - local deprecated_global_options = set.intersection(global_options, deprecated); - if not deprecated_global_options:empty() then - print(""); - print(" You have some deprecated options in the global section:"); - print(" "..tostring(deprecated_global_options)) - ok = false; - end - for host, options in it.filter(function (h) return h ~= "*" end, pairs(configmanager.getconfig())) do - local host_options = set.new(it.to_array(it.keys(options))); - local misplaced_options = set.intersection(host_options, known_global_options); - for name in pairs(options) do - if name:match("^interfaces?") - or name:match("_ports?$") or name:match("_interfaces?$") - or (name:match("_ssl$") and not name:match("^[cs]2s_ssl$")) then - misplaced_options:add(name); - end - end - if not misplaced_options:empty() then - ok = false; - print(""); - local n = it.count(misplaced_options); - print(" You have "..n.." option"..(n>1 and "s " or " ").."set under "..host.." that should be"); - print(" in the global section of the config file, above any VirtualHost or Component definitions,") - print(" see https://prosody.im/doc/configure#overview for more information.") - print(""); - print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", ")); - end - end - for host, options in enabled_hosts() do - local host_options = set.new(it.to_array(it.keys(options))); - local subdomain = host:match("^[^.]+"); - if not(host_options:contains("component_module")) and (subdomain == "jabber" or subdomain == "xmpp" - or subdomain == "chat" or subdomain == "im") then - print(""); - print(" Suggestion: If "..host.. " is a new host with no real users yet, consider renaming it now to"); - print(" "..host:gsub("^[^.]+%.", "")..". You can use SRV records to redirect XMPP clients and servers to "..host.."."); - print(" For more information see: https://prosody.im/doc/dns"); - end - end - local all_modules = set.new(config["*"].modules_enabled); - local all_options = set.new(it.to_array(it.keys(config["*"]))); - for host in enabled_hosts() do - all_options:include(set.new(it.to_array(it.keys(config[host])))); - all_modules:include(set.new(config[host].modules_enabled)); - end - for mod in all_modules do - if mod:match("^mod_") then - print(""); - print(" Modules in modules_enabled should not have the 'mod_' prefix included."); - print(" Change '"..mod.."' to '"..mod:match("^mod_(.*)").."'."); - elseif mod:match("^auth_") then - print(""); - print(" Authentication modules should not be added to modules_enabled,"); - print(" but be specified in the 'authentication' option."); - print(" Remove '"..mod.."' from modules_enabled and instead add"); - print(" authentication = '"..mod:match("^auth_(.*)").."'"); - print(" For more information see https://prosody.im/doc/authentication"); - elseif mod:match("^storage_") then - print(""); - print(" storage modules should not be added to modules_enabled,"); - print(" but be specified in the 'storage' option."); - print(" Remove '"..mod.."' from modules_enabled and instead add"); - print(" storage = '"..mod:match("^storage_(.*)").."'"); - print(" For more information see https://prosody.im/doc/storage"); - end - end - if all_modules:contains("vcard") and all_modules:contains("vcard_legacy") then - print(""); - print(" Both mod_vcard_legacy and mod_vcard are enabled but they conflict"); - print(" with each other. Remove one."); - end - if all_modules:contains("pep") and all_modules:contains("pep_simple") then - print(""); - print(" Both mod_pep_simple and mod_pep are enabled but they conflict"); - print(" with each other. Remove one."); - end - for host, host_config in pairs(config) do --luacheck: ignore 213/host - if type(rawget(host_config, "storage")) == "string" and rawget(host_config, "default_storage") then - print(""); - print(" The 'default_storage' option is not needed if 'storage' is set to a string."); - break; - end - end - local require_encryption = set.intersection(all_options, set.new({ - "require_encryption", "c2s_require_encryption", "s2s_require_encryption" - })):empty(); - local ssl = dependencies.softreq"ssl"; - if not ssl then - if not require_encryption then - print(""); - print(" You require encryption but LuaSec is not available."); - print(" Connections will fail."); - ok = false; - end - elseif not ssl.loadcertificate then - if all_options:contains("s2s_secure_auth") then - print(""); - print(" You have set s2s_secure_auth but your version of LuaSec does "); - print(" not support certificate validation, so all s2s connections will"); - print(" fail."); - ok = false; - elseif all_options:contains("s2s_secure_domains") then - local secure_domains = set.new(); - for host in enabled_hosts() do - if config[host].s2s_secure_auth == true then - secure_domains:add("*"); - else - secure_domains:include(set.new(config[host].s2s_secure_domains)); - end - end - if not secure_domains:empty() then - print(""); - print(" You have set s2s_secure_domains but your version of LuaSec does "); - print(" not support certificate validation, so s2s connections to/from "); - print(" these domains will fail."); - ok = false; - end - end - elseif require_encryption and not all_modules:contains("tls") then - print(""); - print(" You require encryption but mod_tls is not enabled."); - print(" Connections will fail."); - ok = false; - end - - print("Done.\n"); - end - if not what or what == "dns" then - local dns = require "net.dns"; - local idna = require "util.encodings".idna; - local ip = require "util.ip"; - local c2s_ports = set.new(configmanager.get("*", "c2s_ports") or {5222}); - local s2s_ports = set.new(configmanager.get("*", "s2s_ports") or {5269}); - - local c2s_srv_required, s2s_srv_required; - if not c2s_ports:contains(5222) then - c2s_srv_required = true; - end - if not s2s_ports:contains(5269) then - s2s_srv_required = true; - end - - local problem_hosts = set.new(); - - local external_addresses, internal_addresses = set.new(), set.new(); - - local fqdn = socket.dns.tohostname(socket.dns.gethostname()); - if fqdn then - do - local res = dns.lookup(idna.to_ascii(fqdn), "A"); - if res then - for _, record in ipairs(res) do - external_addresses:add(record.a); - end - end - end - do - local res = dns.lookup(idna.to_ascii(fqdn), "AAAA"); - if res then - for _, record in ipairs(res) do - external_addresses:add(record.aaaa); - end - end - end - end - - local local_addresses = require"util.net".local_addresses() or {}; - - for addr in it.values(local_addresses) do - if not ip.new_ip(addr).private then - external_addresses:add(addr); - else - internal_addresses:add(addr); - end - end - - if external_addresses:empty() then - print(""); - print(" Failed to determine the external addresses of this server. Checks may be inaccurate."); - c2s_srv_required, s2s_srv_required = true, true; - end - - local v6_supported = not not socket.tcp6; - - for jid, host_options in enabled_hosts() do - local all_targets_ok, some_targets_ok = true, false; - local node, host = jid_split(jid); - - local modules, component_module = modulemanager.get_modules_for_host(host); - if component_module then - modules:add(component_module); - end - - local is_component = not not host_options.component_module; - print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."..."); - if node then - print("Only the domain part ("..host..") is used in DNS.") - end - local target_hosts = set.new(); - if modules:contains("c2s") then - local res = dns.lookup("_xmpp-client._tcp."..idna.to_ascii(host)..".", "SRV"); - if res then - for _, record in ipairs(res) do - target_hosts:add(record.srv.target); - if not c2s_ports:contains(record.srv.port) then - print(" SRV target "..record.srv.target.." contains unknown client port: "..record.srv.port); - end - end - else - if c2s_srv_required then - print(" No _xmpp-client SRV record found for "..host..", but it looks like you need one."); - all_targets_ok = false; - else - target_hosts:add(host); - end - end - end - if modules:contains("s2s") then - local res = dns.lookup("_xmpp-server._tcp."..idna.to_ascii(host)..".", "SRV"); - if res then - for _, record in ipairs(res) do - target_hosts:add(record.srv.target); - if not s2s_ports:contains(record.srv.port) then - print(" SRV target "..record.srv.target.." contains unknown server port: "..record.srv.port); - end - end - else - if s2s_srv_required then - print(" No _xmpp-server SRV record found for "..host..", but it looks like you need one."); - all_targets_ok = false; - else - target_hosts:add(host); - end - end - end - if target_hosts:empty() then - target_hosts:add(host); - end - - if target_hosts:contains("localhost") then - print(" Target 'localhost' cannot be accessed from other servers"); - target_hosts:remove("localhost"); - end - - if modules:contains("proxy65") then - local proxy65_target = configmanager.get(host, "proxy65_address") or host; - if type(proxy65_target) == "string" then - local A, AAAA = dns.lookup(idna.to_ascii(proxy65_target), "A"), dns.lookup(idna.to_ascii(proxy65_target), "AAAA"); - local prob = {}; - if not A then - table.insert(prob, "A"); - end - if v6_supported and not AAAA then - table.insert(prob, "AAAA"); - end - if #prob > 0 then - print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/") - .." record. Create one or set 'proxy65_address' to the correct host/IP."); - end - else - print(" proxy65_address for "..host.." should be set to a string, unable to perform DNS check"); - end - end - - for target_host in target_hosts do - local host_ok_v4, host_ok_v6; - do - local res = dns.lookup(idna.to_ascii(target_host), "A"); - if res then - for _, record in ipairs(res) do - if external_addresses:contains(record.a) then - some_targets_ok = true; - host_ok_v4 = true; - elseif internal_addresses:contains(record.a) then - host_ok_v4 = true; - some_targets_ok = true; - print(" "..target_host.." A record points to internal address, external connections might fail"); - else - print(" "..target_host.." A record points to unknown address "..record.a); - all_targets_ok = false; - end - end - end - end - do - local res = dns.lookup(idna.to_ascii(target_host), "AAAA"); - if res then - for _, record in ipairs(res) do - if external_addresses:contains(record.aaaa) then - some_targets_ok = true; - host_ok_v6 = true; - elseif internal_addresses:contains(record.aaaa) then - host_ok_v6 = true; - some_targets_ok = true; - print(" "..target_host.." AAAA record points to internal address, external connections might fail"); - else - print(" "..target_host.." AAAA record points to unknown address "..record.aaaa); - all_targets_ok = false; - end - end - end - end - - local bad_protos = {} - if not host_ok_v4 then - table.insert(bad_protos, "IPv4"); - end - if not host_ok_v6 then - table.insert(bad_protos, "IPv6"); - end - if #bad_protos > 0 then - print(" Host "..target_host.." does not seem to resolve to this server ("..table.concat(bad_protos, "/")..")"); - end - if host_ok_v6 and not v6_supported then - print(" Host "..target_host.." has AAAA records, but your version of LuaSocket does not support IPv6."); - print(" Please see https://prosody.im/doc/ipv6 for more information."); - end - end - if not all_targets_ok then - print(" "..(some_targets_ok and "Only some" or "No").." targets for "..host.." appear to resolve to this server."); - if is_component then - print(" DNS records are necessary if you want users on other servers to access this component."); - end - problem_hosts:add(host); - end - print(""); - end - if not problem_hosts:empty() then - print(""); - print("For more information about DNS configuration please see https://prosody.im/doc/dns"); - print(""); - ok = false; - end - end - if not what or what == "certs" then - local cert_ok; - print"Checking certificates..." - local x509_verify_identity = require"util.x509".verify_identity; - local create_context = require "core.certmanager".create_context; - local ssl = dependencies.softreq"ssl"; - -- local datetime_parse = require"util.datetime".parse_x509; - local load_cert = ssl and ssl.loadcertificate; - -- or ssl.cert_from_pem - if not ssl then - print("LuaSec not available, can't perform certificate checks") - if what == "certs" then cert_ok = false end - elseif not load_cert then - print("This version of LuaSec (" .. ssl._VERSION .. ") does not support certificate checking"); - cert_ok = false - else - local function skip_bare_jid_hosts(host) - if jid_split(host) then - -- See issue #779 - return false; - end - return true; - end - for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do - print("Checking certificate for "..host); - -- First, let's find out what certificate this host uses. - local host_ssl_config = configmanager.rawget(host, "ssl") - or configmanager.rawget(host:match("%.(.*)"), "ssl"); - local global_ssl_config = configmanager.rawget("*", "ssl"); - local ok, err, ssl_config = create_context(host, "server", host_ssl_config, global_ssl_config); - if not ok then - print(" Error: "..err); - cert_ok = false - elseif not ssl_config.certificate then - print(" No 'certificate' found for "..host) - cert_ok = false - elseif not ssl_config.key then - print(" No 'key' found for "..host) - cert_ok = false - else - local key, err = io.open(ssl_config.key); -- Permissions check only - if not key then - print(" Could not open "..ssl_config.key..": "..err); - cert_ok = false - else - key:close(); - end - local cert_fh, err = io.open(ssl_config.certificate); -- Load the file. - if not cert_fh then - print(" Could not open "..ssl_config.certificate..": "..err); - cert_ok = false - else - print(" Certificate: "..ssl_config.certificate) - local cert = load_cert(cert_fh:read"*a"); cert_fh:close(); - if not cert:validat(os.time()) then - print(" Certificate has expired.") - cert_ok = false - elseif not cert:validat(os.time() + 86400) then - print(" Certificate expires within one day.") - cert_ok = false - elseif not cert:validat(os.time() + 86400*7) then - print(" Certificate expires within one week.") - elseif not cert:validat(os.time() + 86400*31) then - print(" Certificate expires within one month.") - end - if configmanager.get(host, "component_module") == nil - and not x509_verify_identity(host, "_xmpp-client", cert) then - print(" Not valid for client connections to "..host..".") - cert_ok = false - end - if (not (configmanager.get(host, "anonymous_login") - or configmanager.get(host, "authentication") == "anonymous")) - and not x509_verify_identity(host, "_xmpp-server", cert) then - print(" Not valid for server-to-server connections to "..host..".") - cert_ok = false - end - end - end - end - end - if cert_ok == false then - print("") - print("For more information about certificates please see https://prosody.im/doc/certificates"); - ok = false - end - print("") - end - if not ok then - print("Problems found, see above."); - else - print("All checks passed, congratulations!"); - end - return ok and 0 or 2; -end - -function commands.shell(arg) - require "util.prosodyctl.shell".start(arg); -end - --------------------- local async = require "util.async"; @@ -1408,6 +587,13 @@ local command_runner = async.runner(function () end end + if not commands[command] then + local ok, command_module = pcall(require, "util.prosodyctl."..command); + if ok and command_module[command] then + commands[command] = command_module[command]; + end + end + if not commands[command] then -- Show help for all commands function show_usage(usage, desc) print(" "..usage); -- cgit v1.2.3 From 366a0994097c212ff8859af10c57da4576c454b0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 4 Jun 2020 17:26:18 +0100 Subject: prosodyctl: Fix traceback when no command provided (thanks Zash) --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 3b5291d6..288d20b2 100755 --- a/prosodyctl +++ b/prosodyctl @@ -587,7 +587,7 @@ local command_runner = async.runner(function () end end - if not commands[command] then + if command and not commands[command] then local ok, command_module = pcall(require, "util.prosodyctl."..command); if ok and command_module[command] then commands[command] = command_module[command]; -- cgit v1.2.3 From 4a42f8042dc9c6289fc008c63ff2625fbdfc4808 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 25 Jun 2020 17:26:58 +0200 Subject: prosodyctl about: Report versions of luaunbound and libunbound --- prosodyctl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 288d20b2..6b82e678 100755 --- a/prosodyctl +++ b/prosodyctl @@ -442,6 +442,7 @@ function commands.about(arg) local luaevent =dependencies.softreq"luaevent"; dependencies.softreq"ssl"; dependencies.softreq"DBI"; + local lunbound = dependencies.softreq"lunbound"; for name, module in pairs(package.loaded) do if type(module) == "table" and rawget(module, "_VERSION") and name ~= "_G" and not name:match("%.") then @@ -454,6 +455,12 @@ function commands.about(arg) if luaevent then module_versions["libevent"] = luaevent.core.libevent_version(); end + if lunbound then + if not module_versions["lunbound"] then + module_versions["lunbound"] = "<= 0.5"; + end + module_versions["libunbound"] = lunbound._LIBVER; + end local sorted_keys = array.collect(keys(module_versions)):sort(); for _, name in ipairs(sorted_keys) do print(name..":"..string.rep(" ", longest_name-#name), module_versions[name]); -- cgit v1.2.3 From 37566b1cc38d34e84673d1a1d3d979df6a2bade0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Jul 2020 03:13:27 +0200 Subject: prosodyctl about: Use library function for sorted listing of lua modules Code reuse and one less module to import is nice. --- prosodyctl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 6b82e678..b5361d95 100755 --- a/prosodyctl +++ b/prosodyctl @@ -378,8 +378,7 @@ function commands.about(arg) end local pwd = "."; - local array = require "util.array"; - local keys = require "util.iterators".keys; + local sorted_pairs = require "util.iterators".sorted_pairs; local hg = require"util.mercurial"; local relpath = configmanager.resolve_relative_path; @@ -461,9 +460,8 @@ function commands.about(arg) end module_versions["libunbound"] = lunbound._LIBVER; end - local sorted_keys = array.collect(keys(module_versions)):sort(); - for _, name in ipairs(sorted_keys) do - print(name..":"..string.rep(" ", longest_name-#name), module_versions[name]); + for name, version in sorted_pairs(module_versions) do + print(name..":"..string.rep(" ", longest_name-#name), version); end print(""); end -- cgit v1.2.3 From 6e59b775022a6c385ce878898bf08a9def1f363c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Jul 2020 03:23:10 +0200 Subject: prosodyctl about: Split out libraries into a separate section Currently libevent and libunbound would show up under Lua modules but they are not, so a separate section seems more appropriate. --- prosodyctl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index b5361d95..d220355c 100755 --- a/prosodyctl +++ b/prosodyctl @@ -438,7 +438,7 @@ function commands.about(arg) print(""); print("# Lua module versions"); local module_versions, longest_name = {}, 8; - local luaevent =dependencies.softreq"luaevent"; + local library_versions = {}; dependencies.softreq"ssl"; dependencies.softreq"DBI"; local lunbound = dependencies.softreq"lunbound"; @@ -451,19 +451,24 @@ function commands.about(arg) module_versions[name] = module._VERSION; end end - if luaevent then - module_versions["libevent"] = luaevent.core.libevent_version(); - end if lunbound then if not module_versions["lunbound"] then module_versions["lunbound"] = "<= 0.5"; end - module_versions["libunbound"] = lunbound._LIBVER; + library_versions["libunbound"] = lunbound._LIBVER; end for name, version in sorted_pairs(module_versions) do print(name..":"..string.rep(" ", longest_name-#name), version); end print(""); + print("# library versions"); + if require "net.server".event_base then + library_versions["libevent"] = require"luaevent".core.libevent_version(); + end + for name, version in sorted_pairs(library_versions) do + print(name..":"..string.rep(" ", longest_name-#name), version); + end + print(""); end function commands.reload(arg) -- cgit v1.2.3 From c80ef421128f58dcfdce656c90a7d9daa918ae39 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Jul 2020 03:29:02 +0200 Subject: prosodyctl about: Substitute better names for some Lua modules E.g. 'lxp' isn't that easy to guess that it's LuaExpat --- prosodyctl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index d220355c..27a44ec4 100755 --- a/prosodyctl +++ b/prosodyctl @@ -441,10 +441,19 @@ function commands.about(arg) local library_versions = {}; dependencies.softreq"ssl"; dependencies.softreq"DBI"; + local friendly_names = { + DBI = "LuaDBI"; + lfs = "LuaFileSystem"; + lunbound = "luaunbound"; + lxp = "LuaExpat"; + socket = "LuaSocket"; + ssl = "LuaSec"; + }; local lunbound = dependencies.softreq"lunbound"; for name, module in pairs(package.loaded) do if type(module) == "table" and rawget(module, "_VERSION") - and name ~= "_G" and not name:match("%.") then + and name ~= "_G" and not name:match("%.") then + name = friendly_names[name] or name; if #name > longest_name then longest_name = #name; end -- cgit v1.2.3 From 947c136c95d5767f83127ee62c30f13f14aea615 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Jul 2020 03:29:06 +0200 Subject: prosodyctl about: Strip name from lua module _VERSION Some modules have _VERSION = "LuaModule x.y.z", so it is a bit weird to show the name twice. --- prosodyctl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 27a44ec4..fabfe04f 100755 --- a/prosodyctl +++ b/prosodyctl @@ -457,7 +457,11 @@ function commands.about(arg) if #name > longest_name then longest_name = #name; end - module_versions[name] = module._VERSION; + local mod_version = module._VERSION; + if tostring(mod_version):sub(1, #name+1) == name .. " " then + mod_version = mod_version:sub(#name+2); + end + module_versions[name] = mod_version; end end if lunbound then -- cgit v1.2.3 From f537afbb8e245beea12af9afa0de12744c6c595a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Jul 2020 03:33:37 +0200 Subject: prosodyctl about: Show longer name for luaunbound MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit luaunbound, lunbound, lua-unbound ... "kärt barn har många namn" --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index fabfe04f..dcd9e5a2 100755 --- a/prosodyctl +++ b/prosodyctl @@ -465,8 +465,8 @@ function commands.about(arg) end end if lunbound then - if not module_versions["lunbound"] then - module_versions["lunbound"] = "<= 0.5"; + if not module_versions["luaunbound"] then + module_versions["luaunbound"] = "0.5 (?)"; end library_versions["libunbound"] = lunbound._LIBVER; end -- cgit v1.2.3 From b74859e35c353452264b0f44704049932ae0e37a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Oct 2020 21:17:29 +0200 Subject: util.prosodyctl: Flip argument order "verb subject" feels better than "subject verb", especially since the subject (module) is optional. --- prosodyctl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index dcd9e5a2..928d2bec 100755 --- a/prosodyctl +++ b/prosodyctl @@ -78,7 +78,7 @@ function commands.install(arg) show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end - call_luarocks(arg[1], "install") + call_luarocks("install", arg[1]); end function commands.remove(arg) @@ -86,7 +86,7 @@ function commands.remove(arg) show_usage([[remove]], [[Removes a module installed in the working directory's plugins folder]]); return 1; end - call_luarocks(arg[1], "remove") + call_luarocks("remove", arg[1]) end function commands.list(arg) @@ -94,7 +94,7 @@ function commands.list(arg) show_usage([[list]], [[Shows installed rocks]]); return 1; end - call_luarocks(arg[1], "list") + call_luarocks("list", arg[1]) end function commands.adduser(arg) -- cgit v1.2.3 From 28aadca557b90b2a3a981aecd4626b577c002346 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Oct 2020 21:24:07 +0200 Subject: util.prosodyctl: Move hardcoded luarocks server into prosodyctl To be replaced with config option in future commit --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 928d2bec..ca631047 100755 --- a/prosodyctl +++ b/prosodyctl @@ -78,7 +78,7 @@ function commands.install(arg) show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end - call_luarocks("install", arg[1]); + call_luarocks("install", arg[1], "http://localhost/"); end function commands.remove(arg) -- cgit v1.2.3 From 42eec522a3a327185ee358ac77cf894e93c221e8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Oct 2020 21:24:14 +0200 Subject: util.prosodyctl: Get Luarocks server from config --- prosodyctl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index ca631047..c74a04d1 100755 --- a/prosodyctl +++ b/prosodyctl @@ -78,7 +78,8 @@ function commands.install(arg) show_usage([[install]], [[Installs a prosody/luarocks plugin]]); return 1; end - call_luarocks("install", arg[1], "http://localhost/"); + -- TODO finalize config option name + call_luarocks("install", arg[1], configmanager.get("*", "plugin_server") or "http://localhost/"); end function commands.remove(arg) -- cgit v1.2.3