aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2025-02-13 13:04:37 +0000
committerMatthew Wild <mwild1@gmail.com>2025-02-13 13:04:37 +0000
commit91e846ee71323f1dddab59d8bb9ad035f897d619 (patch)
tree4ca1e5bf445c2648088a6561c6e9aa549705aec7 /plugins
parent94385af697fe46454bee2adf4c75bc0c48ddac33 (diff)
downloadprosody-91e846ee71323f1dddab59d8bb9ad035f897d619.tar.gz
prosody-91e846ee71323f1dddab59d8bb9ad035f897d619.zip
mod_invites: Add shell commands to list, show and delete pending invitations
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_invites.lua140
1 files changed, 140 insertions, 0 deletions
diff --git a/plugins/mod_invites.lua b/plugins/mod_invites.lua
index de836358..1e6ef861 100644
--- a/plugins/mod_invites.lua
+++ b/plugins/mod_invites.lua
@@ -289,6 +289,146 @@ module:add_item("shell-command", {
end;
});
+module:add_item("shell-command", {
+ section = "invite";
+ section_desc = "Create and manage invitations";
+ name = "show";
+ desc = "Show details of an account invitation token";
+ args = { { name = "host", type = "string" }, { name = "token", type = "string" } };
+ host_selector = "host";
+
+ handler = function (self, host, token) --luacheck: ignore 212/self 212/host
+ local invite, err = get_account_invite_info(token);
+ if not invite then return nil, err; end
+
+ local print = self.session.print;
+
+ if invite.type == "roster" then
+ print("Invitation to register and become a contact of "..invite.jid);
+ elseif invite.type == "register" then
+ local jid_user, jid_host = jid_split(invite.jid);
+ if invite.additional_data and invite.additional_data.allow_reset then
+ print("Password reset for "..invite.additional_data.allow_reset.."@"..jid_host);
+ elseif jid_user then
+ print("Invitation to register on "..jid_host.." with username '"..jid_user.."'");
+ else
+ print("Invitation to register on "..jid_host);
+ end
+ else
+ print("Unknown invitation type");
+ end
+
+ if invite.inviter then
+ print("Creator:", invite.inviter);
+ end
+
+ print("Created:", os.date("%Y-%m-%d %T", invite.created_at));
+ print("Expires:", os.date("%Y-%m-%d %T", invite.expires));
+
+ print("");
+
+ if invite.uri then
+ print("XMPP URI:", invite.uri);
+ end
+
+ if invite.landing_page then
+ print("Web link:", invite.landing_page);
+ end
+
+ if invite.additional_data then
+ print("");
+ if invite.additional_data.roles then
+ if invite.additional_data.roles[1] then
+ print("Role:", invite.additional_data.roles[1]);
+ end
+ if invite.additional_data.roles[2] then
+ print("Secondary roles:", table.concat(invite.additional_data.roles, ", ", 2, #invite.additional_data.roles));
+ end
+ end
+ if invite.additional_data.groups then
+ print("Groups:", table.concat(invite.additional_data.groups, ", "));
+ end
+ if invite.additional_data.note then
+ print("Comment:", invite.additional_data.note);
+ end
+ end
+
+ return true, "Invitation valid";
+ end;
+});
+
+module:add_item("shell-command", {
+ section = "invite";
+ section_desc = "Create and manage invitations";
+ name = "delete";
+ desc = "Delete/revoke an invitation token";
+ args = { { name = "host", type = "string" }, { name = "token", type = "string" } };
+ host_selector = "host";
+
+ handler = function (self, host, token) --luacheck: ignore 212/self 212/host
+ local invite, err = delete_account_invite(token);
+ if not invite then return nil, err; end
+ return true, "Invitation deleted";
+ end;
+});
+
+module:add_item("shell-command", {
+ section = "invite";
+ section_desc = "Create and manage invitations";
+ name = "list";
+ desc = "List pending invitations which allow account registration";
+ args = { { name = "host", type = "string" } };
+ host_selector = "host";
+
+ handler = function (self, host) -- luacheck: ignore 212/host
+ local print_row = human_io.table({
+ {
+ title = "Token";
+ key = "invite";
+ width = 24;
+ mapper = function (invite)
+ return invite.token;
+ end;
+ };
+ {
+ title = "Expires";
+ key = "invite";
+ width = 20;
+ mapper = function (invite)
+ return os.date("%Y-%m-%dT%T", invite.expires);
+ end;
+ };
+ {
+ title = "Description";
+ key = "invite";
+ width = "100%";
+ mapper = function (invite)
+ if invite.type == "roster" then
+ return "Contact with "..invite.jid;
+ elseif invite.type == "register" then
+ local jid_user, jid_host = jid_split(invite.jid);
+ if invite.additional_data and invite.additional_data.allow_reset then
+ return "Password reset for "..invite.additional_data.allow_reset.."@"..jid_host;
+ end
+ if jid_user then
+ return "Register on "..jid_host.." with username "..jid_user;
+ end
+ return "Register on "..jid_host;
+ end
+ end;
+ };
+ }, self.session.width);
+
+ self.session.print(print_row());
+ local count = 0;
+ for _, invite in pending_account_invites() do
+ count = count + 1;
+ self.session.print(print_row({ invite = invite }));
+ end
+ return true, ("%d pending invites"):format(count);
+ end;
+});
+
local subcommands = {};
--- prosodyctl command