diff options
Diffstat (limited to 'prosodyctl')
-rwxr-xr-x | prosodyctl | 179 |
1 files changed, 68 insertions, 111 deletions
@@ -44,22 +44,33 @@ end ----------- -local startup = require "util.startup"; +-- Check before first require, to preempt the probable failure +if _VERSION < "Lua 5.2" then + io.stderr:write("Prosody is no longer compatible with Lua 5.1\n") + io.stderr:write("See https://prosody.im/doc/depends#lua for more information\n") + return os.exit(1); +end + +if not pcall(require, "prosody.loader") then + pcall(require, "loader"); +end + +local startup = require "prosody.util.startup"; startup.prosodyctl(); ----------- -local configmanager = require "core.configmanager"; -local modulemanager = require "core.modulemanager" -local prosodyctl = require "util.prosodyctl" +local configmanager = require "prosody.core.configmanager"; +local modulemanager = require "prosody.core.modulemanager" +local prosodyctl = require "prosody.util.prosodyctl" local socket = require "socket" -local dependencies = require "util.dependencies"; +local dependencies = require "prosody.util.dependencies"; local lfs = dependencies.softreq "lfs"; ----------------------- -local parse_args = require "util.argparse".parse; -local human_io = require "util.human.io"; +local parse_args = require "prosody.util.argparse".parse; +local human_io = require "prosody.util.human.io"; local show_message, show_warning = prosodyctl.show_message, prosodyctl.show_warning; local show_usage = prosodyctl.show_usage; @@ -67,8 +78,6 @@ 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; - local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * 2; ----------------------- local commands = {}; @@ -135,38 +144,9 @@ function commands.adduser(arg) show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); return opts.help and 0 or 1; end - local user, host = jid_split(arg[1]); - if not user and host then - show_message [[Failed to understand JID, please supply the JID you want to create]] - show_usage [[adduser user@host]] - return 1; - end - - if not host then - show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; - return 1; - end - - if not prosody.hosts[host] then - show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) - show_warning("The user will not be able to log in until this is changed."); - prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 - end - - if prosodyctl.user_exists{ user = user, host = host } then - show_message [[That user already exists]]; - return 1; - end - - local password = read_password(); - if not password then return 1; end - - local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; - - if ok then return 0; end - show_message(error_messages[msg]) - return 1; + local shell = require "prosody.util.prosodyctl.shell"; + return shell.shell({ ("user:create(%q, nil, %q)"):format(arg[1], "prosody:member") }); end function commands.passwd(arg) @@ -175,38 +155,9 @@ function commands.passwd(arg) show_usage([[passwd JID]], [[Set the password for the specified user account in Prosody]]); return opts.help and 0 or 1; end - local user, host = jid_split(arg[1]); - if not user and host then - show_message [[Failed to understand JID, please supply the JID you want to set the password for]] - show_usage [[passwd user@host]] - return 1; - end - - if not host then - show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; - return 1; - end - - if not prosody.hosts[host] then - show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) - show_warning("The user will not be able to log in until this is changed."); - prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 - end - - if not prosodyctl.user_exists { user = user, host = host } then - show_message [[That user does not exist, use prosodyctl adduser to create a new user]] - return 1; - end - - local password = read_password(); - if not password then return 1; end - - local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; - if ok then return 0; end - - show_message(error_messages[msg]) - return 1; + local shell = require "prosody.util.prosodyctl.shell"; + return shell.shell({ ("user:password(%q, nil)"):format(arg[1]) }); end function commands.deluser(arg) @@ -215,34 +166,9 @@ function commands.deluser(arg) show_usage([[deluser JID]], [[Permanently remove the specified user account from Prosody]]); return opts.help and 0 or 1; end - local user, host = jid_split(arg[1]); - if not user and host then - show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] - show_usage [[deluser user@host]] - return 1; - end - - if not host then - show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; - return 1; - end - if not prosody.hosts[host] then - show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) - prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 - end - - if not prosodyctl.user_exists { user = user, host = host } then - show_message [[That user does not exist on this server]] - return 1; - end - - local ok, msg = prosodyctl.deluser { user = user, host = host }; - - if ok then return 0; end - - show_message(error_messages[msg]) - return 1; + local shell = require "prosody.util.prosodyctl.shell"; + return shell.shell({ ("user:delete(%q)"):format(arg[1]) }); end local function has_init_system() --> which @@ -427,8 +353,8 @@ function commands.about(arg) end local pwd = "."; - local sorted_pairs = require "util.iterators".sorted_pairs; - local hg = require"util.mercurial"; + local sorted_pairs = require "prosody.util.iterators".sorted_pairs; + local hg = require"prosody.util.mercurial"; local relpath = configmanager.resolve_relative_path; print("Prosody "..(prosody.version or "(unknown version)")); @@ -450,7 +376,7 @@ function commands.about(arg) .."\n "; end))); print(""); - local have_pposix, pposix = pcall(require, "util.pposix"); + local have_pposix, pposix = pcall(require, "prosody.util.pposix"); if have_pposix and pposix.uname then print("# Operating system"); local uname, err = pposix.uname(); @@ -483,7 +409,7 @@ function commands.about(arg) print(""); print("# Network"); print(""); - print("Backend: "..require "net.server".get_backend()); + print("Backend: "..require "prosody.net.server".get_backend()); print(""); print("# Lua module versions"); local module_versions, longest_name = {}, 8; @@ -505,7 +431,7 @@ function commands.about(arg) } local lunbound = dependencies.softreq"lunbound"; local lxp = dependencies.softreq"lxp"; - local hashes = dependencies.softreq"util.hashes"; + local hashes = dependencies.softreq"prosody.util.hashes"; for name, module in pairs(package.loaded) do local version_field = alternate_version_fields[name] or "_VERSION"; if type(module) == "table" and rawget(module, version_field) @@ -538,7 +464,7 @@ function commands.about(arg) end print(""); print("# library versions"); - if require "net.server".event_base then + if require "prosody.net.server".event_base then library_versions["libevent"] = require"luaevent".core.libevent_version(); end for name, version in sorted_pairs(library_versions) do @@ -547,6 +473,28 @@ function commands.about(arg) print(""); end +function commands.version(arg) + local flags = { short_params = { h = "help"; ["?"] = "help", v = "verbose" } }; + local opts = parse_args(arg, flags); + if opts.help then + show_usage("version [-v]", [[Show current Prosody version, or more]]); + return 0; + elseif opts.verbose then + return commands.about(arg); + end + + print("Prosody "..(prosody.version or "(unknown version)")); +end + +function commands.lua_paths() + local function shell_escape(s) + return "'" .. tostring(s):gsub("'",[['\'']]) .. "'"; + end + + print("LUA_PATH="..shell_escape(package.path)); + print("LUA_CPATH="..shell_escape(package.cpath)); +end + function commands.reload(arg) local opts = parse_args(arg, only_help); if opts.help then @@ -554,6 +502,15 @@ function commands.reload(arg) return 0; end + if arg[1] and arg[1]:match"^mod_" then + -- TODO reword the usage text, document + local shell = require "prosody.util.prosodyctl.shell"; + arg[1] = arg[1]:match("^mod_(.*)"); -- strip mod_ prefix + table.insert(arg, 1, "module"); + table.insert(arg, 2, "reload"); + return shell.shell(arg); + end + service_command_warning("reload"); if not prosodyctl.isrunning() then @@ -573,7 +530,7 @@ function commands.reload(arg) end -- ejabberdctl compatibility -local unpack = table.unpack or unpack; -- luacheck: ignore 113 +local unpack = table.unpack; function commands.register(arg) local user, host, password = unpack(arg); @@ -628,8 +585,8 @@ end --------------------- -local async = require "util.async"; -local server = require "net.server"; +local async = require "prosody.util.async"; +local server = require "prosody.net.server"; local watchers = { error = function (_, err) error(err); @@ -675,7 +632,7 @@ local command_runner = async.runner(function () end if command and not commands[command] then - local ok, command_module = pcall(require, "util.prosodyctl."..command); + local ok, command_module = pcall(require, "prosody.util.prosodyctl."..command); if ok and command_module[command] then commands[command] = command_module[command]; end @@ -683,7 +640,7 @@ local command_runner = async.runner(function () if not commands[command] then -- Show help for all commands function show_usage(usage, desc) - print(string.format(" %-11s %s", usage, desc)); + print(string.format(" %-14s %s", usage, desc)); end print("prosodyctl - Manage a Prosody server"); @@ -692,7 +649,7 @@ local command_runner = async.runner(function () print(""); print("Where COMMAND may be one of:"); - local hidden_commands = require "util.set".new{ "register", "unregister" }; + local hidden_commands = require "prosody.util.set".new{ "register", "unregister", "lua_paths" }; local commands_order = { "Process management:", "start"; "stop"; "restart"; "reload"; "status"; @@ -702,8 +659,8 @@ local command_runner = async.runner(function () "Plugin management:", "install"; "remove"; "list"; "Informative:", - "about", "check", + "version", "Other:", "cert", }; |