Merge 0.10->trunk
[prosody.git] / prosodyctl
index 1a487fb5f54dbb5b8b897ee3f226f51eea09ebf0..ef62a9d8f155099a575e57556bab7766350950f5 100755 (executable)
@@ -233,6 +233,7 @@ local function make_host(hostname)
                type = "local",
                events = prosody.events,
                modules = {},
+               sessions = {},
                users = require "core.usermanager".new_null_provider(hostname)
        };
 end
@@ -364,8 +365,8 @@ function commands.deluser(arg)
        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]]
+               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
        
@@ -697,30 +698,43 @@ function cert_commands.config(arg)
                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(hosts, config, arg);
-               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 i, k in ipairs(openssl._DN_order) do
-                       local v = conf.distinguished_name[k];
-                       if v then
-                               local nv;
-                               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();
+               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 i, k in ipairs(openssl._DN_order) do
+                               local v = conf.distinguished_name[k];
+                               if v then
+                                       local nv;
+                                       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
-                               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
                local conf_file, err = io.open(conf_filename, "w");
@@ -1183,6 +1197,7 @@ function commands.check(arg)
                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;
@@ -1197,19 +1212,18 @@ function commands.check(arg)
                        for host in enabled_hosts() do
                                print("Checking certificate for "..host);
                                -- First, let's find out what certificate this host uses.
-                               local ssl_config = config.rawget(host, "ssl");
-                               if not ssl_config then
-                                       local base_host = host:match("%.(.*)");
-                                       ssl_config = config.get(base_host, "ssl");
-                               end
-                               if not ssl_config then
-                                       print("  No 'ssl' option defined for "..host)
+                               local host_ssl_config = config.rawget(host, "ssl")
+                                       or config.rawget(host:match("%.(.*)"), "ssl");
+                               local global_ssl_config = config.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' set in ssl option for "..host)
+                                       print("  No 'certificate' found for "..host)
                                        cert_ok = false
                                elseif not ssl_config.key then
-                                       print("  No 'key' set in ssl option for "..host)
+                                       print("  No 'key' found for "..host)
                                        cert_ok = false
                                else
                                        local key, err = io.open(ssl_config.key); -- Permissions check only
@@ -1229,6 +1243,13 @@ function commands.check(arg)
                                                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 config.get(host, "component_module") == nil
                                                        and not x509_verify_identity(host, "_xmpp-client", cert) then