aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_admin_telnet.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_admin_telnet.lua')
-rw-r--r--plugins/mod_admin_telnet.lua58
1 files changed, 47 insertions, 11 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index d378edf4..c5e423da 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -76,22 +76,22 @@ end
function console_listener.onincoming(conn, data)
local session = sessions[conn];
- -- Handle data
- (function(session, data)
+ -- Handle data (loop allows us to break to add \0 after response)
+ repeat
local useglobalenv;
-
+
if data:match("^>") then
data = data:gsub("^>", "");
useglobalenv = true;
elseif data == "\004" then
commands["bye"](session, data);
- return;
+ break;
else
local command = data:lower();
command = data:match("^%w+") or data:match("%p");
if commands[command] then
commands[command](session, data);
- return;
+ break;
end
end
@@ -106,7 +106,7 @@ function console_listener.onincoming(conn, data)
err = err:gsub("^:%d+: ", "");
err = err:gsub("'<eof>'", "the end of the line");
session.print("Sorry, I couldn't understand that... "..err);
- return;
+ break;
end
end
@@ -116,26 +116,26 @@ function console_listener.onincoming(conn, data)
if not (ranok or message or useglobalenv) and commands[data:lower()] then
commands[data:lower()](session, data);
- return;
+ break;
end
if not ranok then
session.print("Fatal error while running command, it did not complete");
session.print("Error: "..taskok);
- return;
+ break;
end
if not message then
session.print("Result: "..tostring(taskok));
- return;
+ break;
elseif (not taskok) and message then
session.print("Command completed with a problem");
session.print("Message: "..tostring(message));
- return;
+ break;
end
session.print("OK: "..tostring(message));
- end)(session, data);
+ until true
session.send(string.char(0));
end
@@ -187,6 +187,7 @@ function commands.help(session, data)
print [[s2s - Commands to manage sessions between this server and others]]
print [[module - Commands to load/reload/unload modules/plugins]]
print [[host - Commands to activate, deactivate and list virtual hosts]]
+ print [[user - Commands to create and delete users, and change their passwords]]
print [[server - Uptime, version, shutting down, etc.]]
print [[config - Reloading the configuration, etc.]]
print [[console - Help regarding the console itself]]
@@ -208,6 +209,10 @@ function commands.help(session, data)
print [[host:activate(hostname) - Activates the specified host]]
print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]]
print [[host:list() - List the currently-activated hosts]]
+ elseif section == "user" then
+ print [[user:create(jid, password) - Create the specified user account]]
+ print [[user:password(jid, password) - Set the password for the specified user account]]
+ print [[user:delete(jid, password) - Permanently remove the specified user account]]
elseif section == "server" then
print [[server:version() - Show the server's version number]]
print [[server:uptime() - Show how long the server has been running]]
@@ -891,6 +896,37 @@ function def_env.muc:room(room_jid)
return setmetatable({ room = room_obj }, console_room_mt);
end
+def_env.user = {};
+function def_env.user:create(jid, password)
+ local username, host = jid_split(jid);
+ local ok, err = um.create_user(username, password, host);
+ if ok then
+ return true, "User created";
+ else
+ return nil, "Could not create user: "..err;
+ end
+end
+
+function def_env.user:delete(jid)
+ local username, host = jid_split(jid);
+ local ok, err = um.delete_user(username, host);
+ if ok then
+ return true, "User deleted";
+ else
+ return nil, "Could not delete user: "..err;
+ end
+end
+
+function def_env.user:passwd(jid, password)
+ local username, host = jid_split(jid);
+ local ok, err = um.set_password(username, password, host);
+ if ok then
+ return true, "User created";
+ else
+ return nil, "Could not change password for user: "..err;
+ end
+end
+
-------------
function printbanner(session)