+-- Prosody IM v0.2
+-- Copyright (C) 2008 Matthew Wild
+-- Copyright (C) 2008 Waqas Hussain
+--
+-- This program is free software; you can redistribute it and/or
+-- modify it under the terms of the GNU General Public License
+-- as published by the Free Software Foundation; either version 2
+-- of the License, or (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+--
+
+
\r
local connlisteners_register = require "net.connlisteners".register;\r
\r
local console_listener = { default_port = 5582; default_mode = "*l"; };\r
\r
local commands = {};\r
-local default_env = {};\r
-local default_env_mt = { __index = default_env };\r
+local def_env = {};\r
+local default_env_mt = { __index = def_env };\r
\r
console = {};\r
\r
function console:new_session(conn)\r
local w = conn.write;\r
- return { conn = conn;\r
+ local session = { conn = conn;\r
send = function (t) w(tostring(t)); end;\r
print = function (t) w("| "..tostring(t).."\n"); end;\r
disconnect = function () conn.close(); end;\r
- env = setmetatable({}, default_env_mt);\r
};\r
+ session.env = setmetatable({}, default_env_mt);\r
+ \r
+ -- Load up environment with helper objects\r
+ for name, t in pairs(def_env) do\r
+ if type(t) == "table" then\r
+ session.env[name] = setmetatable({ session = session }, { __index = t });\r
+ end\r
+ end\r
+ \r
+ return session;\r
end\r
\r
local sessions = {};\r
-- Handle new connection\r
session = console:new_session(conn);\r
sessions[conn] = session;\r
- session.print("Welcome to the lxmppd admin console!");\r
+ printbanner(session);\r
end\r
if data then\r
-- Handle data\r
end\r
\r
-- Session environment --\r
--- Anything in default_env will be accessible within the session as a global variable\r
+-- Anything in def_env will be accessible within the session as a global variable\r
\r
-default_env.server = {};\r
-function default_env.server.reload()\r
- dofile "main.lua"\r
+def_env.server = {};\r
+function def_env.server:reload()\r
+ dofile "prosody"\r
return true, "Server reloaded";\r
end\r
\r
-default_env.module = {};\r
-function default_env.module.load(name)\r
+def_env.module = {};\r
+function def_env.module:load(name, host, config)\r
local mm = require "modulemanager";\r
- local ok, err = mm.load(name);\r
+ local ok, err = mm.load(host or self.env.host, name, config);\r
if not ok then\r
return false, err or "Unknown error loading module";\r
end\r
return true, "Module loaded";\r
end\r
\r
-default_env.config = {};\r
-function default_env.config.load(filename, format)\r
- local cfgm_load = require "core.configmanager".load;\r
- local ok, err = cfgm_load(filename, format);\r
+function def_env.module:unload(name, host)\r
+ local mm = require "modulemanager";\r
+ local ok, err = mm.unload(host or self.env.host, name);\r
+ if not ok then\r
+ return false, err or "Unknown error unloading module";\r
+ end\r
+ return true, "Module unloaded";\r
+end\r
+\r
+def_env.config = {};\r
+function def_env.config:load(filename, format)\r
+ local config_load = require "core.configmanager".load;\r
+ local ok, err = config_load(filename, format);\r
if not ok then\r
return false, err or "Unknown error loading config";\r
end\r
return true, "Config loaded";\r
end\r
+\r
+function def_env.config:get(host, section, key)\r
+ local config_get = require "core.configmanager".get\r
+ return true, tostring(config_get(host, section, key));\r
+end\r
+\r
+def_env.hosts = {};\r
+function def_env.hosts:list()\r
+ for host, host_session in pairs(hosts) do\r
+ self.session.print(host);\r
+ end\r
+ return true, "Done";\r
+end\r
+\r
+function def_env.hosts:add(name)\r
+end\r
+\r
+-------------\r
+\r
+function printbanner(session)\r
+session.print [[\r
+ ____ \ / _ \r
+ | _ \ _ __ ___ ___ _-_ __| |_ _ \r
+ | |_) | '__/ _ \/ __|/ _ \ / _` | | | |\r
+ | __/| | | (_) \__ \ |_| | (_| | |_| |\r
+ |_| |_| \___/|___/\___/ \__,_|\__, |\r
+ A study in simplicity |___/ \r
+\r
+]]\r
+session.print("Welcome to the Prosody administration console. For a list of commands, type: help");\r
+session.print("You may find more help on using this console in our online documentation at ");\r
+session.print("http://prosody.im/doc/console\n");\r
+end\r