Software / code / prosody-modules
Comparison
mod_client_management/mod_client_management.lua @ 6263:10a1016d1c3a
Merge update
| author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
|---|---|
| date | Sun, 01 Jun 2025 11:43:16 +0700 |
| parent | 6246:96dda21fba75 |
comparison
equal
deleted
inserted
replaced
| 6262:a72388da5cd4 | 6263:10a1016d1c3a |
|---|---|
| 428 end); | 428 end); |
| 429 | 429 |
| 430 | 430 |
| 431 -- Command | 431 -- Command |
| 432 | 432 |
| 433 module:on_ready(function () | 433 module:add_item("shell-command", { |
| 434 local console_env = module:shared("/*/admin_shell/env"); | 434 section = "user"; |
| 435 if not console_env.user then return; end -- admin_shell probably not loaded | 435 name = "clients"; |
| 436 | 436 desc = "List a user's clients"; |
| 437 function console_env.user:clients(user_jid) | 437 args = { |
| 438 local username, host = jid.split(user_jid); | 438 { name = "jid"; type = "string" } |
| 439 local mod = prosody.hosts[host] and prosody.hosts[host].modules.client_management; | 439 }; |
| 440 if not mod then | 440 host_selector = "jid"; |
| 441 return false, ("Host does not exist on this server, or does not have mod_client_management loaded"); | 441 handler = function(self, user_jid) |
| 442 end | 442 local username = jid.split(user_jid); |
| 443 | 443 |
| 444 local clients = mod.get_active_clients(username); | 444 local clients = get_active_clients(username); |
| 445 if not clients or #clients == 0 then | 445 if not clients or #clients == 0 then |
| 446 return true, "No clients associated with this account"; | 446 return true, "No clients associated with this account"; |
| 447 end | 447 end |
| 448 | 448 |
| 449 local function date_or_time(last_seen) | 449 local function date_or_time(last_seen) |
| 514 print(row(client)); | 514 print(row(client)); |
| 515 end | 515 end |
| 516 print(string.rep("-", self.session.width)); | 516 print(string.rep("-", self.session.width)); |
| 517 return true, ("%d clients"):format(#clients); | 517 return true, ("%d clients"):format(#clients); |
| 518 end | 518 end |
| 519 | 519 }); |
| 520 function console_env.user:revoke_client(user_jid, selector) -- luacheck: ignore 212/self | 520 |
| 521 local username, host = jid.split(user_jid); | 521 module:add_item("shell-command", { |
| 522 local mod = prosody.hosts[host] and prosody.hosts[host].modules.client_management; | 522 section = "user"; |
| 523 if not mod then | 523 name = "revoke_client"; |
| 524 return false, ("Host does not exist on this server, or does not have mod_client_management loaded"); | 524 desc = "Revoke access from a user's client"; |
| 525 end | 525 args = { |
| 526 | 526 { name = "jid"; type = "string" }; |
| 527 local revoked, err = revocation_errors.coerce(mod.revoke_client_access(username, selector)); | 527 { name = "selector"; type = "string" }; |
| 528 }; | |
| 529 host_selector = "jid"; | |
| 530 handler = function(self, user_jid, selector) -- luacheck: ignore 212/self | |
| 531 local username = jid.split(user_jid); | |
| 532 | |
| 533 local revoked, err = revocation_errors.coerce(revoke_client_access(username, selector)); | |
| 528 if not revoked then | 534 if not revoked then |
| 529 return false, err.text or err; | 535 return false, err.text or err; |
| 530 end | 536 end |
| 531 return true, "Client access revoked"; | 537 return true, "Client access revoked"; |
| 532 end | 538 end |
| 533 end); | 539 }); |