comparison 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
comparison
equal deleted inserted replaced
13995:30d457b2b0c4 13997:015c8c75f8cf
2092 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users"; 2092 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users";
2093 end 2093 end
2094 2094
2095 def_env.xmpp = new_section("Commands for sending XMPP stanzas"); 2095 def_env.xmpp = new_section("Commands for sending XMPP stanzas");
2096 2096
2097 describe_command [[xmpp:ping(localhost, remotehost) - Sends a ping to a remote XMPP server and reports the response]] 2097 describe_command [[xmpp:ping(localjid, remotejid) - Sends a ping to an XMPP entity and reports the response]]
2098 local new_id = require "prosody.util.id".medium; 2098 local new_id = require "prosody.util.id".medium;
2099 function def_env.xmpp:ping(localhost, remotehost, timeout) 2099 function def_env.xmpp:ping(localjid, remotejid, timeout)
2100 localhost = select(2, jid_split(localhost)); 2100 local localhost, localresource = select(2, jid_split(localjid));
2101 remotehost = select(2, jid_split(remotehost)); 2101 local remotehost = select(2, jid_split(remotejid));
2102 if not localhost then 2102 if not localhost then
2103 return nil, "Invalid sender hostname"; 2103 return nil, "Invalid sender JID";
2104 elseif not prosody.hosts[localhost] then 2104 elseif not prosody.hosts[localhost] then
2105 return nil, "No such local host"; 2105 return nil, "No such local host";
2106 elseif localresource then
2107 return nil, "Server can't send ping from local resource"; -- Would require creating a temporary session with bound resource and everything
2106 end 2108 end
2107 if not remotehost then 2109 if not remotehost then
2108 return nil, "Invalid destination hostname"; 2110 return nil, "Invalid destination JID";
2109 elseif prosody.hosts[remotehost] then 2111 end
2110 return nil, "Both hosts are local"; 2112 local iq = st.iq{ from=localjid, to=remotejid, type="get", id=new_id()}
2111 end
2112 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
2113 :tag("ping", {xmlns="urn:xmpp:ping"}); 2113 :tag("ping", {xmlns="urn:xmpp:ping"});
2114 local time_start = time.now(); 2114 local time_start = time.now();
2115 local print = self.session.print; 2115 local print = self.session.print;
2116 local function onchange(what) 2116 local function onchange(what)
2117 return function(event) 2117 return function(event)
2123 time.now() - time_start)); 2123 time.now() - time_start));
2124 elseif s2s_session.type == "s2sin_unauthed" and s2s_session.to_host == nil and s2s_session.from_host == nil then 2124 elseif s2s_session.type == "s2sin_unauthed" and s2s_session.to_host == nil and s2s_session.from_host == nil then
2125 print(("Session %s %s (%gs)"):format(s2s_session.id, what, time.now() - time_start)); 2125 print(("Session %s %s (%gs)"):format(s2s_session.id, what, time.now() - time_start));
2126 end 2126 end
2127 end 2127 end
2128 end
2129 if localhost == remotehost or prosody.hosts[remotehost] then
2130 -- No s2s connections will be triggered
2131 return module:context(localhost):send_iq(iq, nil, timeout):next(function(pong)
2132 return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start);
2133 end);
2128 end 2134 end
2129 local onconnected = onchange("connected"); 2135 local onconnected = onchange("connected");
2130 local onauthenticated = onchange("authenticated"); 2136 local onauthenticated = onchange("authenticated");
2131 local onestablished = onchange("established"); 2137 local onestablished = onchange("established");
2132 local ondestroyed = onchange("destroyed"); 2138 local ondestroyed = onchange("destroyed");