Comparison

plugins/mod_admin_shell.lua @ 12209:3fe2e5da05c3

mod_admin_shell: Add command to show current user roles
author Kim Alvefur <zash@zash.se>
date Sun, 23 Jan 2022 20:06:50 +0100
parent 12208:3edf1a38fb15
child 12224:2b348d65cd69
comparison
equal deleted inserted replaced
12208:3edf1a38fb15 12209:3fe2e5da05c3
249 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] 249 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]]
250 print [[host:list() - List the currently-activated hosts]] 250 print [[host:list() - List the currently-activated hosts]]
251 elseif section == "user" then 251 elseif section == "user" then
252 print [[user:create(jid, password, roles) - Create the specified user account]] 252 print [[user:create(jid, password, roles) - Create the specified user account]]
253 print [[user:password(jid, password) - Set the password for the specified user account]] 253 print [[user:password(jid, password) - Set the password for the specified user account]]
254 print [[user:showroles(jid, host) - Show current roles for an user]]
254 print [[user:roles(jid, host, roles) - Set roles for an user (see 'help roles')]] 255 print [[user:roles(jid, host, roles) - Set roles for an user (see 'help roles')]]
255 print [[user:delete(jid) - Permanently remove the specified user account]] 256 print [[user:delete(jid) - Permanently remove the specified user account]]
256 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]] 257 print [[user:list(hostname, pattern) - List users on the specified host, optionally filtering with a pattern]]
257 elseif section == "roles" then 258 elseif section == "roles" then
258 print [[Roles may grant access or restrict users from certain operations]] 259 print [[Roles may grant access or restrict users from certain operations]]
1345 else 1346 else
1346 return nil, "Could not change password for user: "..err; 1347 return nil, "Could not change password for user: "..err;
1347 end 1348 end
1348 end 1349 end
1349 1350
1351 function def_env.user:showroles(jid, host)
1352 local username, userhost = jid_split(jid);
1353 if host == nil then host = userhost; end
1354 if host ~= "*" and not prosody.hosts[host] then
1355 return nil, "No such host: "..host;
1356 elseif prosody.hosts[userhost] and not um.user_exists(username, userhost) then
1357 return nil, "No such user";
1358 end
1359 local roles = um.get_roles(jid, host);
1360 if not roles then return true, "No roles"; end
1361 local count = 0;
1362 local print = self.session.print;
1363 for role in pairs(roles) do
1364 count = count + 1;
1365 print(role);
1366 end
1367 return true, count == 1 and "1 role" or count.." roles";
1368 end
1369
1350 -- user:roles("someone@example.com", "example.com", {"prosody:admin"}) 1370 -- user:roles("someone@example.com", "example.com", {"prosody:admin"})
1351 -- user:roles("someone@example.com", {"prosody:admin"}) 1371 -- user:roles("someone@example.com", {"prosody:admin"})
1352 function def_env.user:roles(jid, host, new_roles) 1372 function def_env.user:roles(jid, host, new_roles)
1353 local username, userhost = jid_split(jid); 1373 local username, userhost = jid_split(jid);
1354 if new_roles == nil then host, new_roles = userhost, host; end 1374 if new_roles == nil then host, new_roles = userhost, host; end