Merge with 0.5
authorMatthew Wild <mwild1@gmail.com>
Tue, 28 Jul 2009 18:17:09 +0000 (19:17 +0100)
committerMatthew Wild <mwild1@gmail.com>
Tue, 28 Jul 2009 18:17:09 +0000 (19:17 +0100)
1  2 
net/xmppclient_listener.lua
net/xmppserver_listener.lua
plugins/mod_console.lua

index e882546f265cbf256ccd76d1deb24f61e713983f,ce7788c76d97d70286d6a1d7ecad61d99719f576..dcc561f373dd844af220b04382a3d472b7dc06b6
@@@ -61,7 -61,6 +61,7 @@@ local function session_reset_stream(ses
                function session.data(conn, data)
                        local ok, err = parser:parse(data);
                        if ok then return; end
 +                      log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
                        session:close("xml-not-well-formed");
                end
                
@@@ -70,9 -69,14 +70,14 @@@ en
  
  
  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("<?xml version='1.0'?>");
+                       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, <stream:error> is: %s", reason);
                end
                session.send("</stream:stream>");
                session.conn.close();
 -              xmppclient.disconnect(session.conn, (reason and reason.condition) or reason or "session closed");
 +              xmppclient.disconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed");
        end
  end
  
index 2e70145d1d99f3dff4393235f64e6e785aeb32a1,81d26526db0a523f3aa721c8a9b5bb33136eea12..1f27d841721cd4b6a1f5b5fabb18c1cb14405d20
@@@ -61,7 -61,6 +61,7 @@@ local function session_reset_stream(ses
                function session.data(conn, data)
                        local ok, err = parser:parse(data);
                        if ok then return; end
 +                      log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
                        session:close("xml-not-well-formed");
                end
                
@@@ -70,9 -69,14 +70,14 @@@ en
  
  
  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("<?xml version='1.0'?>");
+                       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], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason);
diff --combined plugins/mod_console.lua
index 8b881c982f72307df1a6dfbebdb1e516d1e042eb,a3ed94999abe906ce3085d096edf8e9497822f1b..3a18ec0eb92944194f43013bb5d7352f4e0fd387
@@@ -156,12 -156,56 +156,57 @@@ 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
  
  def_env.server = {};
 -function def_env.server:reload()
 +
 +function def_env.server:insane_reload()
        prosody.unlock_globals();
        dofile "prosody"
        prosody = _G.prosody;
@@@ -186,11 -230,6 +231,11 @@@ function def_env.server:uptime(
                minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
  end
  
 +function def_env.server:shutdown(reason)
 +      prosody.shutdown(reason);
 +      return true, "Shutdown initiated";
 +end
 +
  def_env.module = {};
  
  local function get_hosts_set(hosts, module)
@@@ -294,11 -333,6 +339,11 @@@ function def_env.config:get(host, secti
        return true, tostring(config_get(host, section, key));
  end
  
 +function def_env.config:reload()
 +      local ok, err = prosody.reload_config();
 +      return ok, (ok and "Config reloaded (you may need to reload modules to take effect)") or tostring(err);
 +end
 +
  def_env.hosts = {};
  function def_env.hosts:list()
        for host, host_session in pairs(hosts) do
@@@ -325,19 -359,10 +370,19 @@@ en
  
  function def_env.c2s:show(match_jid)
        local print, count = self.session.print, 0;
 -      show_c2s(function (jid)
 +      show_c2s(function (jid, session)
                if (not match_jid) or jid:match(match_jid) then
                        count = count + 1;
 -                      print(jid);
 +                      local status, priority = "unavailable", tostring(session.priority or "-");
 +                      if session.presence then
 +                              status = session.presence:child_with_name("show");
 +                              if status then
 +                                      status = status:get_text() or "[invalid!]";
 +                              else
 +                                      status = "available";
 +                              end
 +                      end
 +                      print(jid.." - "..status.."("..priority..")");
                end             
        end);
        return true, "Total: "..count.." clients";