From f63e2f139a315a48963b15f4de1e196c6bb7b2d6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 28 Jul 2009 14:48:37 +0100 Subject: net.server: Much improve SSL/TLS error reporting, do our best to understand and hide OpenSSL's ridiculously unfriendly error messages --- net/server.lua | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/net/server.lua b/net/server.lua index 6fe72712..966006c1 100644 --- a/net/server.lua +++ b/net/server.lua @@ -181,20 +181,41 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco out_error "server.lua: wrong server sslctx" ssl = false end - sslctx, err = ssl_newcontext( sslctx ) - if not sslctx then + local ctx; + ctx, err = ssl_newcontext( sslctx ) + if not ctx then err = err or "wrong sslctx parameters" - out_error( "server.lua: ", err ) + local file; + file = err:match("^error loading (.-) %("); + if file then + if file == "private key" then + file = sslctx.key or "your private key"; + elseif file == "certificate" then + file = sslctx.certificate or "your certificate file"; + end + local reason = err:match("%((.+)%)$") or "some reason"; + if reason == "Permission denied" then + reason = "Check that the permissions allow Prosody to read this file."; + elseif reason == "No such file or directory" then + reason = "Check that the path is correct, and the file exists."; + elseif reason == "system lib" then + reason = "Previous error (see logs), or other system error."; + else + reason = "Reason: "..tostring(reason or "unknown"):lower(); + end + log("error", "SSL/TLS: Failed to load %s: %s", file, reason); + else + log("error", "SSL/TLS: Error initialising for port %d: %s", serverport, err ); + end ssl = false end + sslctx = ctx; end if not ssl then sslctx = false; if startssl then - out_error( "server.lua: Cannot start ssl on port: ", serverport ) + log("error", "Failed to listen on port %d due to SSL/TLS to SSL/TLS initialisation errors (see logs)", serverport ) return nil, "Cannot start ssl, see log for details" - else - out_put("server.lua: ", "ssl not enabled on ", serverport); end end -- cgit v1.2.3 From ceb93e38fe12ed768f8f114e064b145bccacd62a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 28 Jul 2009 15:03:42 +0100 Subject: core.loggingmanager: Enable timestamps by default for file log sinks --- core/loggingmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 1d2f8d7d..d701511e 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -222,7 +222,7 @@ function log_sink_types.file(config) local timestamps = config.timestamps; - if timestamps == true then + if timestamps == nil or timestamps == true then timestamps = default_timestamp; -- Default format end -- cgit v1.2.3 From 08391171c3d3f104cd1bc7e855936b04870e81e1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 28 Jul 2009 17:43:46 +0100 Subject: hostmanager: Warn when user puts port configuration under vhost section --- core/hostmanager.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/hostmanager.lua b/core/hostmanager.lua index c7b975d1..ba363273 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -41,6 +41,11 @@ function activate(host, host_config) or (configmanager.get(host, "core", "anonymous_login") and (configmanager.get(host, "core", "disallow_s2s") ~= false)) }; + for option_name in pairs(host_config.core) do + if option_name:match("_ports$") then + log("warn", "%s: Option '%s' has no effect for virtual hosts - put it in global Host \"*\" instead", host, option_name); + end + end log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host); eventmanager.fire_event("host-activated", host, host_config); end -- cgit v1.2.3 From 57f4a5c837c5039eee6edd83d9516bca9a82c9d0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 28 Jul 2009 18:02:11 +0100 Subject: configmanager: Default options appearing before Host "*" to global (fixes potential traceback) --- core/configmanager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/core/configmanager.lua b/core/configmanager.lua index 7fc6aa13..b7ee605f 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -113,6 +113,7 @@ do set(env.__currenthost or "*", "core", k, v); end}); + rawset(env, "__currenthost", "*") -- Default is global function env.Host(name) rawset(env, "__currenthost", name); -- Needs at least one setting to logically exist :) -- cgit v1.2.3 From 9e4f7f3b3aff49a164f94b074a7eb8b7cce98aeb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 28 Jul 2009 18:47:59 +0100 Subject: mod_console: Finally add in the missing 'help' command \o/ --- plugins/mod_console.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index 3e978900..a3ed9499 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -156,6 +156,51 @@ commands["!"] = function (session, data) session.print("Sorry, not sure what you want"); end +function commands.help(session, data) + local print = session.print; + local section = data:match("^help (%w+)"); + if not section then + print [[Commands are divided into multiple sections. For help on a particular section, ]] + print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] + print [[]] + print [[c2s - Commands to manage local client-to-server sessions]] + print [[s2s - Commands to manage sessions between this server and others]] + print [[module - Commands to load/reload/unload modules/plugins]] + print [[server - Uptime, version, shutting down, etc.]] + print [[console - Help regarding the console itself]] + elseif section == "c2s" then + print [[c2s:show(jid) - Show all client sessions with the specified JID (or all if no JID given)]] + print [[c2s:show_insecure() - Show all unencrypted client connections]] + print [[c2s:show_secure() - Show all encrypted client connections]] + print [[c2s:close(jid) - Close all sessions for the specified JID]] + elseif section == "s2s" then + print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]] + print [[s2s:close(from, to) - Close a connection from one domain to another]] + elseif section == "module" then + print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]] + print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]] + print [[module:unload(module, host) - The same, but just unloads the module from memory]] + elseif section == "server" then + print [[server:version() - Show the server's version number]] + print [[server:uptime() - Show how long the server has been running]] + --print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] + elseif section == "console" then + print [[Hey! Welcome to Prosody's admin console.]] + print [[First thing, if you're ever wondering how to get out, simply type 'quit'.]] + print [[Secondly, note that we don't support the full telnet protocol yet (it's coming)]] + print [[so you may have trouble using the arrow keys, etc. depending on your system.]] + print [[]] + print [[For now we offer a couple of handy shortcuts:]] + print [[!! - Repeat the last command]] + print [[!old!new! - repeat the last command, but with 'old' replaced by 'new']] + print [[]] + print [[For those well-versed in Prosody's internals, or taking instruction from those who are,]] + print [[you can prefix a command with > to escape the console sandbox, and access everything in]] + print [[the running server. Great fun, but be careful not to break anything :)]] + end + print [[]] +end + -- Session environment -- -- Anything in def_env will be accessible within the session as a global variable -- cgit v1.2.3 From 8ad65c2824d2ee3bd52175df34fdd7bd9d393231 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 28 Jul 2009 19:15:29 +0100 Subject: xmpp{client,server,component]_listener: Open stream if sending an error and it isn't already open. Fixes #120 --- net/xmppclient_listener.lua | 5 +++++ net/xmppcomponent_listener.lua | 5 +++++ net/xmppserver_listener.lua | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 35838692..ce7788c7 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -69,9 +69,14 @@ end local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; +local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:gsub("%|[^|]+$", ""), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; local function session_close(session, reason) local log = session.log or log; if session.conn then + if session.notopen then + session.send(""); + session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); + end if reason then if type(reason) == "string" then -- assume stream error log("info", "Disconnecting client, is: %s", reason); diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index e62bb810..36d74579 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -87,9 +87,14 @@ end --- Closing a component connection local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; +local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:gsub("%|[^|]+$", ""), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; local function session_close(session, reason) local log = session.log or log; if session.conn then + if session.notopen then + session.send(""); + session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); + end if reason then if type(reason) == "string" then -- assume stream error log("info", "Disconnecting component, is: %s", reason); diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index 3cfcfe86..81d26526 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -69,9 +69,14 @@ end local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; +local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:gsub("%|[^|]+$", ""), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; local function session_close(session, reason) local log = session.log or log; if session.conn then + if session.notopen then + session.sends2s(""); + session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag()); + end if reason then if type(reason) == "string" then -- assume stream error log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, reason); -- cgit v1.2.3