X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fmod_console.lua;h=d6383a780f19eca232e2e8310034d3df68fc942d;hb=67081a9864d45796f59658ccd4b779ffbe0d44e0;hp=5787ad25e87dde8a7193dc2d9321f11e592c5faa;hpb=6d9f97378cd7d73cc22ac102e546c52799bb8615;p=prosody.git diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index 5787ad25..d6383a78 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -1,22 +1,51 @@ +-- 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. +-- + + local connlisteners_register = require "net.connlisteners".register; local console_listener = { default_port = 5582; default_mode = "*l"; }; local commands = {}; -local default_env = {}; -local default_env_mt = { __index = default_env }; +local def_env = {}; +local default_env_mt = { __index = def_env }; console = {}; function console:new_session(conn) local w = conn.write; - return { conn = conn; + local session = { conn = conn; send = function (t) w(tostring(t)); end; print = function (t) w("| "..tostring(t).."\n"); end; disconnect = function () conn.close(); end; - env = setmetatable({}, default_env_mt); }; + session.env = setmetatable({}, default_env_mt); + + -- Load up environment with helper objects + for name, t in pairs(def_env) do + if type(t) == "table" then + session.env[name] = setmetatable({ session = session }, { __index = t }); + end + end + + return session; end local sessions = {}; @@ -28,7 +57,7 @@ function console_listener.listener(conn, data) -- Handle new connection session = console:new_session(conn); sessions[conn] = session; - session.print("Welcome to the lxmppd admin console!"); + printbanner(session); end if data then -- Handle data @@ -111,30 +140,72 @@ commands["!"] = function (session, data) end -- Session environment -- --- Anything in default_env will be accessible within the session as a global variable +-- Anything in def_env will be accessible within the session as a global variable -default_env.server = {}; -function default_env.server.reload() - dofile "main.lua" +def_env.server = {}; +function def_env.server:reload() + dofile "prosody" return true, "Server reloaded"; end -default_env.module = {}; -function default_env.module.load(name) +def_env.module = {}; +function def_env.module:load(name, host, config) local mm = require "modulemanager"; - local ok, err = mm.load(name); + local ok, err = mm.load(host or self.env.host, name, config); if not ok then return false, err or "Unknown error loading module"; end return true, "Module loaded"; end -default_env.config = {}; -function default_env.config.load(filename, format) - local cfgm_load = require "core.configmanager".load; - local ok, err = cfgm_load(filename, format); +function def_env.module:unload(name, host) + local mm = require "modulemanager"; + local ok, err = mm.unload(host or self.env.host, name); + if not ok then + return false, err or "Unknown error unloading module"; + end + return true, "Module unloaded"; +end + +def_env.config = {}; +function def_env.config:load(filename, format) + local config_load = require "core.configmanager".load; + local ok, err = config_load(filename, format); if not ok then return false, err or "Unknown error loading config"; end return true, "Config loaded"; end + +function def_env.config:get(host, section, key) + local config_get = require "core.configmanager".get + return true, tostring(config_get(host, section, key)); +end + +def_env.hosts = {}; +function def_env.hosts:list() + for host, host_session in pairs(hosts) do + self.session.print(host); + end + return true, "Done"; +end + +function def_env.hosts:add(name) +end + +------------- + +function printbanner(session) +session.print [[ + ____ \ / _ + | _ \ _ __ ___ ___ _-_ __| |_ _ + | |_) | '__/ _ \/ __|/ _ \ / _` | | | | + | __/| | | (_) \__ \ |_| | (_| | |_| | + |_| |_| \___/|___/\___/ \__,_|\__, | + A study in simplicity |___/ + +]] +session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); +session.print("You may find more help on using this console in our online documentation at "); +session.print("http://prosody.im/doc/console\n"); +end