Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 5128:834ab74585ec
mod_admin_telnet: Fix user:*, correct names, docs, do validation
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 15 Sep 2012 23:00:59 +0200 |
parent | 5030:9962fc19f9e9 |
child | 5133:1443d1c37c6c |
comparison
equal
deleted
inserted
replaced
5126:a0673b644f05 | 5128:834ab74585ec |
---|---|
225 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] | 225 print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] |
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, password) - Permanently remove the specified user account]] | 230 print [[user:delete(jid) - Permanently remove the specified user account]] |
231 elseif section == "server" then | 231 elseif section == "server" then |
232 print [[server:version() - Show the server's version number]] | 232 print [[server:version() - Show the server's version number]] |
233 print [[server:uptime() - Show how long the server has been running]] | 233 print [[server:uptime() - Show how long the server has been running]] |
234 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] | 234 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] |
235 elseif section == "config" then | 235 elseif section == "config" then |
913 local um = require"core.usermanager"; | 913 local um = require"core.usermanager"; |
914 | 914 |
915 def_env.user = {}; | 915 def_env.user = {}; |
916 function def_env.user:create(jid, password) | 916 function def_env.user:create(jid, password) |
917 local username, host = jid_split(jid); | 917 local username, host = jid_split(jid); |
918 if um.user_exists(username, host) then | |
919 return nil, "User exists"; | |
920 end | |
918 local ok, err = um.create_user(username, password, host); | 921 local ok, err = um.create_user(username, password, host); |
919 if ok then | 922 if ok then |
920 return true, "User created"; | 923 return true, "User created"; |
921 else | 924 else |
922 return nil, "Could not create user: "..err; | 925 return nil, "Could not create user: "..err; |
923 end | 926 end |
924 end | 927 end |
925 | 928 |
926 function def_env.user:delete(jid) | 929 function def_env.user:delete(jid) |
927 local username, host = jid_split(jid); | 930 local username, host = jid_split(jid); |
931 if not um.user_exists(username, host) then | |
932 return nil, "No such user"; | |
933 end | |
928 local ok, err = um.delete_user(username, host); | 934 local ok, err = um.delete_user(username, host); |
929 if ok then | 935 if ok then |
930 return true, "User deleted"; | 936 return true, "User deleted"; |
931 else | 937 else |
932 return nil, "Could not delete user: "..err; | 938 return nil, "Could not delete user: "..err; |
933 end | 939 end |
934 end | 940 end |
935 | 941 |
936 function def_env.user:passwd(jid, password) | 942 function def_env.user:password(jid, password) |
937 local username, host = jid_split(jid); | 943 local username, host = jid_split(jid); |
944 if not um.user_exists(username, host) then | |
945 return nil, "No such user"; | |
946 end | |
938 local ok, err = um.set_password(username, password, host); | 947 local ok, err = um.set_password(username, password, host); |
939 if ok then | 948 if ok then |
940 return true, "User created"; | 949 return true, "User password changed"; |
941 else | 950 else |
942 return nil, "Could not change password for user: "..err; | 951 return nil, "Could not change password for user: "..err; |
943 end | 952 end |
944 end | 953 end |
945 | 954 |