comparison plugins/mod_admin_shell.lua @ 13999:5ad86978ae78 13.0

mod_admin_shell: Ensure JIDs are normalized in xmpp:ping()
author Kim Alvefur <zash@zash.se>
date Fri, 05 Dec 2025 17:53:10 +0100
parents 8d90a83603d6
children 071779f7645c 2aeb5dcb36bf
comparison
equal deleted inserted replaced
13996:8d90a83603d6 13999:5ad86978ae78
2052 def_env.xmpp = new_section("Commands for sending XMPP stanzas"); 2052 def_env.xmpp = new_section("Commands for sending XMPP stanzas");
2053 2053
2054 describe_command [[xmpp:ping(localjid, remotejid) - Sends a ping to an XMPP entity and reports the response]] 2054 describe_command [[xmpp:ping(localjid, remotejid) - Sends a ping to an XMPP entity and reports the response]]
2055 local new_id = require "prosody.util.id".medium; 2055 local new_id = require "prosody.util.id".medium;
2056 function def_env.xmpp:ping(localjid, remotejid, timeout) 2056 function def_env.xmpp:ping(localjid, remotejid, timeout)
2057 local localhost, localresource = select(2, jid_split(localjid)); 2057 local localnode, localhost, localresource = jid_split(localjid);
2058 local remotehost = select(2, jid_split(remotejid)); 2058 local remotenode, remotehost, remoteresource = jid_split(remotejid);
2059 if not localhost then 2059 if not localhost then
2060 return nil, "Invalid sender JID"; 2060 return nil, "Invalid sender JID";
2061 elseif not prosody.hosts[localhost] then 2061 elseif not prosody.hosts[localhost] then
2062 return nil, "No such local host"; 2062 return nil, "No such local host";
2063 elseif localresource then 2063 elseif localresource then
2064 return nil, "Server can't send ping from local resource"; -- Would require creating a temporary session with bound resource and everything 2064 return nil, "Server can't send ping from local resource"; -- Would require creating a temporary session with bound resource and everything
2065 end 2065 end
2066 if not remotehost then 2066 if not remotehost then
2067 return nil, "Invalid destination JID"; 2067 return nil, "Invalid destination JID";
2068 end 2068 end
2069 local iq = st.iq{ from=localjid, to=remotejid, type="get", id=new_id()} 2069 local iq = st.iq { from = jid_join(localnode, localhost); to = jid_join(remotenode, remotehost, remoteresource); type = "get"; id = new_id() }
2070 :tag("ping", {xmlns="urn:xmpp:ping"}); 2070 :tag("ping", {xmlns="urn:xmpp:ping"});
2071 local time_start = time.now(); 2071 local time_start = time.now();
2072 local print = self.session.print; 2072 local print = self.session.print;
2073 local function onchange(what) 2073 local function onchange(what)
2074 return function(event) 2074 return function(event)