Mercurial > prosody-hg
comparison plugins/mod_admin_adhoc.lua @ 12910:5c90862e39aa
mod_admin_adhoc: Add XEP-0133 commands to Disable and Re-Enable users
Enables UI in clients supporting XEP-0050
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 23 Feb 2023 18:39:02 +0100 |
| parents | ffff0d8a9c68 |
| children | 74b9e05af71e |
comparison
equal
deleted
inserted
replaced
| 12909:ce508097b2c8 | 12910:5c90862e39aa |
|---|---|
| 16 | 16 |
| 17 local keys = require "util.iterators".keys; | 17 local keys = require "util.iterators".keys; |
| 18 local usermanager_user_exists = require "core.usermanager".user_exists; | 18 local usermanager_user_exists = require "core.usermanager".user_exists; |
| 19 local usermanager_create_user = require "core.usermanager".create_user; | 19 local usermanager_create_user = require "core.usermanager".create_user; |
| 20 local usermanager_delete_user = require "core.usermanager".delete_user; | 20 local usermanager_delete_user = require "core.usermanager".delete_user; |
| 21 local usermanager_disable_user = require "core.usermanager".disable_user; | |
| 22 local usermanager_enable_user = require "core.usermanager".enable_user; | |
| 21 local usermanager_set_password = require "core.usermanager".set_password; | 23 local usermanager_set_password = require "core.usermanager".set_password; |
| 22 local hostmanager_activate = require "core.hostmanager".activate; | 24 local hostmanager_activate = require "core.hostmanager".activate; |
| 23 local hostmanager_deactivate = require "core.hostmanager".deactivate; | 25 local hostmanager_deactivate = require "core.hostmanager".deactivate; |
| 24 local rm_load_roster = require "core.rostermanager".load_roster; | 26 local rm_load_roster = require "core.rostermanager".load_roster; |
| 25 local st, jid = require "util.stanza", require "util.jid"; | 27 local st, jid = require "util.stanza", require "util.jid"; |
| 148 end | 150 end |
| 149 return {status = "completed", info = (#succeeded ~= 0 and | 151 return {status = "completed", info = (#succeeded ~= 0 and |
| 150 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "").. | 152 "The following accounts were successfully deleted:\n"..t_concat(succeeded, "\n").."\n" or "").. |
| 151 (#failed ~= 0 and | 153 (#failed ~= 0 and |
| 152 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") }; | 154 "The following accounts could not be deleted:\n"..t_concat(failed, "\n") or "") }; |
| 155 end); | |
| 156 | |
| 157 local disable_user_layout = dataforms_new{ | |
| 158 title = "Disabling a User"; | |
| 159 instructions = "Fill out this form to disable a user."; | |
| 160 | |
| 161 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | |
| 162 { name = "accountjids", type = "jid-multi", required = true, label = "The Jabber ID(s) to disable" }; | |
| 163 }; | |
| 164 | |
| 165 local disable_user_command_handler = adhoc_simple(disable_user_layout, function(fields, err, data) | |
| 166 if err then | |
| 167 return generate_error_message(err); | |
| 168 end | |
| 169 local failed = {}; | |
| 170 local succeeded = {}; | |
| 171 for _, aJID in ipairs(fields.accountjids) do | |
| 172 local username, host = jid.split(aJID); | |
| 173 if (host == module_host) and usermanager_user_exists(username, host) and usermanager_disable_user(username, host) then | |
| 174 module:log("info", "User %s has been disabled by %s", aJID, jid.bare(data.from)); | |
| 175 succeeded[#succeeded+1] = aJID; | |
| 176 else | |
| 177 module:log("debug", "Tried to disable non-existent user %s", aJID); | |
| 178 failed[#failed+1] = aJID; | |
| 179 end | |
| 180 end | |
| 181 return {status = "completed", info = (#succeeded ~= 0 and | |
| 182 "The following accounts were successfully disabled:\n"..t_concat(succeeded, "\n").."\n" or "").. | |
| 183 (#failed ~= 0 and | |
| 184 "The following accounts could not be disabled:\n"..t_concat(failed, "\n") or "") }; | |
| 185 end); | |
| 186 | |
| 187 local enable_user_layout = dataforms_new{ | |
| 188 title = "Re-Enable a User"; | |
| 189 instructions = "Fill out this form to enable a user."; | |
| 190 | |
| 191 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; | |
| 192 { name = "accountjids", type = "jid-multi", required = true, label = "The Jabber ID(s) to re-enable" }; | |
| 193 }; | |
| 194 | |
| 195 local enable_user_command_handler = adhoc_simple(enable_user_layout, function(fields, err, data) | |
| 196 if err then | |
| 197 return generate_error_message(err); | |
| 198 end | |
| 199 local failed = {}; | |
| 200 local succeeded = {}; | |
| 201 for _, aJID in ipairs(fields.accountjids) do | |
| 202 local username, host = jid.split(aJID); | |
| 203 if (host == module_host) and usermanager_user_exists(username, host) and usermanager_enable_user(username, host) then | |
| 204 module:log("info", "User %s has been enabled by %s", aJID, jid.bare(data.from)); | |
| 205 succeeded[#succeeded+1] = aJID; | |
| 206 else | |
| 207 module:log("debug", "Tried to enable non-existent user %s", aJID); | |
| 208 failed[#failed+1] = aJID; | |
| 209 end | |
| 210 end | |
| 211 return {status = "completed", info = (#succeeded ~= 0 and | |
| 212 "The following accounts were successfully enabled:\n"..t_concat(succeeded, "\n").."\n" or "").. | |
| 213 (#failed ~= 0 and | |
| 214 "The following accounts could not be enabled:\n"..t_concat(failed, "\n") or "") }; | |
| 153 end); | 215 end); |
| 154 | 216 |
| 155 -- Ending a user's session | 217 -- Ending a user's session |
| 156 local function disconnect_user(match_jid) | 218 local function disconnect_user(match_jid) |
| 157 local node, hostname, givenResource = jid.split(match_jid); | 219 local node, hostname, givenResource = jid.split(match_jid); |
| 802 | 864 |
| 803 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); | 865 local add_user_desc = adhoc_new("Add User", "http://jabber.org/protocol/admin#add-user", add_user_command_handler, "admin"); |
| 804 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); | 866 local change_user_password_desc = adhoc_new("Change User Password", "http://jabber.org/protocol/admin#change-user-password", change_user_password_command_handler, "admin"); |
| 805 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin"); | 867 local config_reload_desc = adhoc_new("Reload configuration", "http://prosody.im/protocol/config#reload", config_reload_handler, "global_admin"); |
| 806 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin"); | 868 local delete_user_desc = adhoc_new("Delete User", "http://jabber.org/protocol/admin#delete-user", delete_user_command_handler, "admin"); |
| 869 local disable_user_desc = adhoc_new("Disable User", "http://jabber.org/protocol/admin#disable-user", disable_user_command_handler, "admin"); | |
| 870 local enable_user_desc = adhoc_new("Re-Enable User", "http://jabber.org/protocol/admin#reenable-user", enable_user_command_handler, "admin"); | |
| 807 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin"); | 871 local end_user_session_desc = adhoc_new("End User Session", "http://jabber.org/protocol/admin#end-user-session", end_user_session_handler, "admin"); |
| 808 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin"); | 872 local get_user_roster_desc = adhoc_new("Get User Roster","http://jabber.org/protocol/admin#get-user-roster", get_user_roster_handler, "admin"); |
| 809 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin"); | 873 local get_user_stats_desc = adhoc_new("Get User Statistics","http://jabber.org/protocol/admin#user-stats", get_user_stats_handler, "admin"); |
| 810 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users-list", get_online_users_command_handler, "admin"); | 874 local get_online_users_desc = adhoc_new("Get List of Online Users", "http://jabber.org/protocol/admin#get-online-users-list", get_online_users_command_handler, "admin"); |
| 811 local list_s2s_this_desc = adhoc_new("List S2S connections", "http://prosody.im/protocol/s2s#list", list_s2s_this_handler, "admin"); | 875 local list_s2s_this_desc = adhoc_new("List S2S connections", "http://prosody.im/protocol/s2s#list", list_s2s_this_handler, "admin"); |
| 822 | 886 |
| 823 module:provides("adhoc", add_user_desc); | 887 module:provides("adhoc", add_user_desc); |
| 824 module:provides("adhoc", change_user_password_desc); | 888 module:provides("adhoc", change_user_password_desc); |
| 825 module:provides("adhoc", config_reload_desc); | 889 module:provides("adhoc", config_reload_desc); |
| 826 module:provides("adhoc", delete_user_desc); | 890 module:provides("adhoc", delete_user_desc); |
| 891 module:provides("adhoc", disable_user_desc); | |
| 892 module:provides("adhoc", enable_user_desc); | |
| 827 module:provides("adhoc", end_user_session_desc); | 893 module:provides("adhoc", end_user_session_desc); |
| 828 module:provides("adhoc", get_user_roster_desc); | 894 module:provides("adhoc", get_user_roster_desc); |
| 829 module:provides("adhoc", get_user_stats_desc); | 895 module:provides("adhoc", get_user_stats_desc); |
| 830 module:provides("adhoc", get_online_users_desc); | 896 module:provides("adhoc", get_online_users_desc); |
| 831 module:provides("adhoc", list_s2s_this_desc); | 897 module:provides("adhoc", list_s2s_this_desc); |
