portmanager: Show a friendly error message when initializing SSL fails (thanks MattJ...
[prosody.git] / util / prosodyctl.lua
index d0045abc9d251ce3eaebf0e1666f65002dfb3ea7..439de551687d6c87bc3aa826e6ac5201a3f8e8a7 100644 (file)
@@ -16,6 +16,7 @@ local signal = require "util.signal";
 local set = require "util.set";
 local lfs = require "lfs";
 local pcall = pcall;
+local type = type;
 
 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep;
 
@@ -63,6 +64,13 @@ function getchar(n)
        end
 end
 
+function getline()
+       local ok, line = pcall(io.read, "*l");
+       if ok then
+               return line;
+       end
+end
+
 function getpass()
        local stty_ret = os.execute("stty -echo 2>/dev/null");
        if stty_ret ~= 0 then
@@ -112,6 +120,13 @@ function read_password()
        return password;
 end
 
+function show_prompt(prompt)
+       io.write(prompt, " ");
+       local line = getline();
+       line = line and line:gsub("\n$","");
+       return (line and #line > 0) and line or nil;
+end
+
 -- Server control
 function adduser(params)
        local user, host, password = nodeprep(params.user), nameprep(params.host), params.password;
@@ -121,7 +136,11 @@ function adduser(params)
                return false, "invalid-hostname";
        end
 
-       local provider = prosody.hosts[host].users;
+       local host_session = prosody.hosts[host];
+       if not host_session then
+               return false, "no-such-host";
+       end
+       local provider = host_session.users;
        if not(provider) or provider.name == "null" then
                usermanager.initialize_host(host);
        end