Mercurial > prosody-hg
comparison plugins/mod_external_services.lua @ 13902:7e6deed12e03
mod_external_services: Add shell command to list external services on a host
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 26 Jun 2025 13:04:40 +0100 |
| parents | 18f560dcc9e3 |
| children | 79ae4821c05e |
comparison
equal
deleted
inserted
replaced
| 13901:cc406878209d | 13902:7e6deed12e03 |
|---|---|
| 240 -- COMPAT XEP-0215 v0.6 | 240 -- COMPAT XEP-0215 v0.6 |
| 241 -- Those still on the old version gets to deal with undefined attributes until they upgrade. | 241 -- Those still on the old version gets to deal with undefined attributes until they upgrade. |
| 242 module:add_feature("urn:xmpp:extdisco:1"); | 242 module:add_feature("urn:xmpp:extdisco:1"); |
| 243 module:hook("iq-get/host/urn:xmpp:extdisco:1:services", handle_services); | 243 module:hook("iq-get/host/urn:xmpp:extdisco:1:services", handle_services); |
| 244 module:hook("iq-get/host/urn:xmpp:extdisco:1:credentials", handle_credentials); | 244 module:hook("iq-get/host/urn:xmpp:extdisco:1:credentials", handle_credentials); |
| 245 | |
| 246 | |
| 247 module:add_item("shell-command", { | |
| 248 section = "services"; | |
| 249 section_desc = "Inspect external services"; | |
| 250 name = "list"; | |
| 251 desc = "List all external services for a host"; | |
| 252 args = { | |
| 253 { name = "host", type = "string" }; | |
| 254 { name = "service", type = "string" }; | |
| 255 }; | |
| 256 host_selector = "host"; | |
| 257 handler = function (shell, host, service_type) --luacheck: ignore 212/host | |
| 258 local c = 0; | |
| 259 local print = shell.session.print; | |
| 260 local services = get_services(); | |
| 261 for _, srv in ipairs(services) do | |
| 262 if not service_type or service_type:lower() == srv.type:lower() then | |
| 263 c = c + 1; | |
| 264 print(srv.type.." ("..srv.transport..")", srv.host..(srv.port and (":"..srv.port) or "")); | |
| 265 for _, prop in ipairs({ "username", "password", "expires" }) do | |
| 266 local val = srv[prop]; | |
| 267 if val then | |
| 268 if prop == "expires" then | |
| 269 val = dt.datetime(val); | |
| 270 end | |
| 271 print(" "..prop..":", val); | |
| 272 end | |
| 273 end | |
| 274 if srv.restricted then | |
| 275 print(" restricted:", "yes"); | |
| 276 end | |
| 277 print(""); | |
| 278 end | |
| 279 end | |
| 280 return true, ("%d services"):format(c); | |
| 281 end; | |
| 282 }); |
