# HG changeset patch # User Matthew Wild # Date 1750939480 -3600 # Node ID 7e6deed12e0314b1a1c48ca0e911c0295eb6b7ad # Parent cc406878209df13ddd3ec6c8c9dfaa4303b30d02 mod_external_services: Add shell command to list external services on a host diff -r cc406878209d -r 7e6deed12e03 plugins/mod_external_services.lua --- a/plugins/mod_external_services.lua Thu Jun 26 13:02:34 2025 +0100 +++ b/plugins/mod_external_services.lua Thu Jun 26 13:04:40 2025 +0100 @@ -242,3 +242,41 @@ module:add_feature("urn:xmpp:extdisco:1"); module:hook("iq-get/host/urn:xmpp:extdisco:1:services", handle_services); module:hook("iq-get/host/urn:xmpp:extdisco:1:credentials", handle_credentials); + + +module:add_item("shell-command", { + section = "services"; + section_desc = "Inspect external services"; + name = "list"; + desc = "List all external services for a host"; + args = { + { name = "host", type = "string" }; + { name = "service", type = "string" }; + }; + host_selector = "host"; + handler = function (shell, host, service_type) --luacheck: ignore 212/host + local c = 0; + local print = shell.session.print; + local services = get_services(); + for _, srv in ipairs(services) do + if not service_type or service_type:lower() == srv.type:lower() then + c = c + 1; + print(srv.type.." ("..srv.transport..")", srv.host..(srv.port and (":"..srv.port) or "")); + for _, prop in ipairs({ "username", "password", "expires" }) do + local val = srv[prop]; + if val then + if prop == "expires" then + val = dt.datetime(val); + end + print(" "..prop..":", val); + end + end + if srv.restricted then + print(" restricted:", "yes"); + end + print(""); + end + end + return true, ("%d services"):format(c); + end; +});