Comparison

plugins/mod_admin_telnet.lua @ 5168:46fc0eff10b4

mod_admin_telnet: user:list(): Allow filtering the set of users
author Kim Alvefur <zash@zash.se>
date Fri, 12 Oct 2012 18:49:22 +0200
parent 5167:ecd9e300ec94
child 5186:ad898e50b8f3
comparison
equal deleted inserted replaced
5167:ecd9e300ec94 5168:46fc0eff10b4
226 print [[host:list() - List the currently-activated hosts]] 226 print [[host:list() - List the currently-activated hosts]]
227 elseif section == "user" then 227 elseif section == "user" then
228 print [[user:create(jid, password) - Create the specified user account]] 228 print [[user:create(jid, password) - Create the specified user account]]
229 print [[user:password(jid, password) - Set the password for the specified user account]] 229 print [[user:password(jid, password) - Set the password for the specified user account]]
230 print [[user:delete(jid) - Permanently remove the specified user account]] 230 print [[user:delete(jid) - Permanently remove the specified user account]]
231 print [[user:list(hostname) - List users on the specified host]] 231 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
232 elseif section == "server" then 232 elseif section == "server" then
233 print [[server:version() - Show the server's version number]] 233 print [[server:version() - Show the server's version number]]
234 print [[server:uptime() - Show how long the server has been running]] 234 print [[server:uptime() - Show how long the server has been running]]
235 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] 235 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
236 elseif section == "config" then 236 elseif section == "config" then
951 else 951 else
952 return nil, "Could not change password for user: "..err; 952 return nil, "Could not change password for user: "..err;
953 end 953 end
954 end 954 end
955 955
956 function def_env.user:list(host) 956 function def_env.user:list(host, pat)
957 if not host then 957 if not host then
958 return nil, "No host given"; 958 return nil, "No host given";
959 elseif not hosts[host] then 959 elseif not hosts[host] then
960 return nil, "No such host"; 960 return nil, "No such host";
961 end 961 end
962 local print = self.session.print; 962 local print = self.session.print;
963 local count = 0;
963 for user in um.users(host) do 964 for user in um.users(host) do
964 print(user.."@"..host); 965 if not pat or user:match(pat) then
965 end 966 print(user.."@"..host);
966 return true; 967 end
968 count = count + 1;
969 end
970 return true, count .. " users total";
967 end 971 end
968 972
969 def_env.xmpp = {}; 973 def_env.xmpp = {};
970 974
971 local st = require "util.stanza"; 975 local st = require "util.stanza";