mod_console: Add module:list() command to show modules loaded on a host
authorMatthew Wild <mwild1@gmail.com>
Mon, 5 Oct 2009 13:40:01 +0000 (14:40 +0100)
committerMatthew Wild <mwild1@gmail.com>
Mon, 5 Oct 2009 13:40:01 +0000 (14:40 +0100)
plugins/mod_console.lua

index e8d31cebe22024d8004a8695523b57d6113ddca9..112d24929c6d9c0de6de794b730e7dcd16ae202e 100644 (file)
@@ -70,9 +70,6 @@ function console_listener.listener(conn, data)
                        if data:match("^>") then
                                data = data:gsub("^>", "");
                                useglobalenv = true;
-                       elseif data == "\004" then
-                               commands["bye"](session, data);
-                               return;
                        else
                                local command = data:lower();
                                command = data:match("^%w+") or data:match("%p");
@@ -208,8 +205,7 @@ end
 -- Anything in def_env will be accessible within the session as a global variable
 
 def_env.server = {};
-
-function def_env.server:insane_reload()
+function def_env.server:reload()
        prosody.unlock_globals();
        dofile "prosody"
        prosody = _G.prosody;
@@ -234,11 +230,6 @@ 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)
@@ -327,6 +318,31 @@ function def_env.module:reload(name, hosts)
        return ok, (ok and "Module reloaded on "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err));
 end
 
+function def_env.module:list(hosts)
+       if hosts == nil then
+               hosts = array.collect(keys(prosody.hosts));
+       end
+       if type(hosts) == "string" then
+               hosts = { hosts };
+       end
+       if type(hosts) ~= "table" then
+               return false, "Please supply a host or a list of hosts you would like to see";
+       end
+       
+       local print = self.session.print;
+       for _, host in ipairs(hosts) do
+               print(host..":");
+               local modules = array.collect(keys(prosody.hosts[host].modules or {})):sort();
+               if #modules == 0 then
+                       print("    No modules loaded");
+               else
+                       for _, name in ipairs(modules) do
+                               print("    "..name);
+                       end
+               end
+       end
+end
+
 def_env.config = {};
 function def_env.config:load(filename, format)
        local config_load = require "core.configmanager".load;
@@ -342,11 +358,6 @@ function def_env.config:get(host, section, key)
        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
@@ -373,12 +384,7 @@ end
 
 function def_env.c2s:show(match_jid)
        local print, count = self.session.print, 0;
-       local curr_host;
        show_c2s(function (jid, session)
-               if curr_host ~= session.host then
-                       curr_host = session.host;
-                       print(curr_host);
-               end
                if (not match_jid) or jid:match(match_jid) then
                        count = count + 1;
                        local status, priority = "unavailable", tostring(session.priority or "-");
@@ -390,7 +396,7 @@ function def_env.c2s:show(match_jid)
                                        status = "available";
                                end
                        end
-                       print("   "..jid.." - "..status.."("..priority..")");
+                       print(jid.." - "..status.."("..priority..")");
                end             
        end);
        return true, "Total: "..count.." clients";