util.xml: Remove unused parameter (thanks, luacheck)
[prosody.git] / util / prosodyctl.lua
index 2da39cb2fa2c14df4fd63a2602cc0d8c0f378896..cc48d5907155a9eee8b5afe1183f55daaa8b0e28 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;
@@ -125,11 +140,12 @@ function adduser(params)
        if not host_session then
                return false, "no-such-host";
        end
+
+       storagemanager.initialize_host(host);
        local provider = host_session.users;
        if not(provider) or provider.name == "null" then
                usermanager.initialize_host(host);
        end
-       storagemanager.initialize_host(host);
        
        local ok, errmsg = usermanager.create_user(user, password, host);
        if not ok then
@@ -140,11 +156,12 @@ end
 
 function user_exists(params)
        local user, host, password = nodeprep(params.user), nameprep(params.host), params.password;
+
+       storagemanager.initialize_host(host);
        local provider = prosody.hosts[host].users;
        if not(provider) or provider.name == "null" then
                usermanager.initialize_host(host);
        end
-       storagemanager.initialize_host(host);
        
        return usermanager.user_exists(user, host);
 end
@@ -161,19 +178,23 @@ function deluser(params)
        if not _M.user_exists(params) then
                return false, "no-such-user";
        end
-       params.password = nil;
+       local user, host = nodeprep(params.user), nameprep(params.host);
        
-       return _M.adduser(params);
+       return usermanager.delete_user(user, host);
 end
 
 function getpid()
-       local pidfile = config.get("*", "core", "pidfile");
+       local pidfile = config.get("*", "pidfile");
        if not pidfile then
                return false, "no-pidfile";
        end
+
+       if type(pidfile) ~= "string" then
+               return false, "invalid-pidfile";
+       end
        
-       local modules_enabled = set.new(config.get("*", "core", "modules_enabled"));
-       if not modules_enabled:contains("posix") then
+       local modules_enabled = set.new(config.get("*", "modules_disabled"));
+       if prosody.platform ~= "posix" or modules_enabled:contains("posix") then
                return false, "no-posix";
        end
        
@@ -258,3 +279,5 @@ function reload()
        signal.kill(pid, signal.SIGHUP);
        return true;
 end
+
+return _M;