diff plugins/mod_admin_shell.lua @ 13997:015c8c75f8cf

Merge 13.0->trunk
author Kim Alvefur <zash@zash.se>
date Fri, 05 Dec 2025 17:29:53 +0100
parents d520cee2bbdb 8d90a83603d6
children d539016e6b21
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Thu Dec 04 14:07:41 2025 +0000
+++ b/plugins/mod_admin_shell.lua	Fri Dec 05 17:29:53 2025 +0100
@@ -2094,22 +2094,22 @@
 
 def_env.xmpp = new_section("Commands for sending XMPP stanzas");
 
-describe_command [[xmpp:ping(localhost, remotehost) - Sends a ping to a remote XMPP server and reports the response]]
+describe_command [[xmpp:ping(localjid, remotejid) - Sends a ping to an XMPP entity and reports the response]]
 local new_id = require "prosody.util.id".medium;
-function def_env.xmpp:ping(localhost, remotehost, timeout)
-	localhost = select(2, jid_split(localhost));
-	remotehost = select(2, jid_split(remotehost));
+function def_env.xmpp:ping(localjid, remotejid, timeout)
+	local localhost, localresource = select(2, jid_split(localjid));
+	local remotehost = select(2, jid_split(remotejid));
 	if not localhost then
-		return nil, "Invalid sender hostname";
+		return nil, "Invalid sender JID";
 	elseif not prosody.hosts[localhost] then
 		return nil, "No such local host";
+	elseif localresource then
+		return nil, "Server can't send ping from local resource"; -- Would require creating a temporary session with bound resource and everything
 	end
 	if not remotehost then
-		return nil, "Invalid destination hostname";
-	elseif prosody.hosts[remotehost] then
-		return nil, "Both hosts are local";
+		return nil, "Invalid destination JID";
 	end
-	local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
+	local iq = st.iq{ from=localjid, to=remotejid, type="get", id=new_id()}
 			:tag("ping", {xmlns="urn:xmpp:ping"});
 	local time_start = time.now();
 	local print = self.session.print;
@@ -2126,6 +2126,12 @@
 			end
 		end
 	end
+	if localhost == remotehost or prosody.hosts[remotehost] then
+		-- No s2s connections will be triggered
+		return module:context(localhost):send_iq(iq, nil, timeout):next(function(pong)
+			return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start);
+		end);
+	end
 	local onconnected = onchange("connected");
 	local onauthenticated = onchange("authenticated");
 	local onestablished = onchange("established");