comparison plugins/mod_admin_shell.lua @ 13998:d539016e6b21

mod_admin_shell: Also relax JID requirements in debug:ping()
author Kim Alvefur <zash@zash.se>
date Fri, 05 Dec 2025 17:51:21 +0100
parents 015c8c75f8cf
children 071779f7645c
comparison
equal deleted inserted replaced
13997:015c8c75f8cf 13998:d539016e6b21
2508 2508
2509 return true, ("Showing %d certificates in %s"):format(c, path); 2509 return true, ("Showing %d certificates in %s"):format(c, path);
2510 end 2510 end
2511 2511
2512 describe_command [[debug:ping(localhost, remotehost) - Sends a ping to a remote XMPP server while printing debug logs]] 2512 describe_command [[debug:ping(localhost, remotehost) - Sends a ping to a remote XMPP server while printing debug logs]]
2513 function def_env.debug:ping(localhost, remotehost, timeout) 2513 function def_env.debug:ping(localjid, remotejid, timeout)
2514 localhost = select(2, jid_split(localhost)); 2514 local localnode, localhost, localresource = jid_split(localjid);
2515 remotehost = select(2, jid_split(remotehost)); 2515 local remotenode, remotehost, remoteresource = jid_split(remotejid);
2516 if not localhost then 2516 if not localhost then
2517 return nil, "Invalid sender hostname"; 2517 return nil, "Invalid sender JID";
2518 elseif not prosody.hosts[localhost] then 2518 elseif not prosody.hosts[localhost] then
2519 return nil, "No such local host"; 2519 return nil, "No such local host";
2520 elseif localresource then
2521 return nil, "Server can't send ping from local resource"; -- Would require creating a temporary session with bound resource and everything
2520 end 2522 end
2521 if not remotehost then 2523 if not remotehost then
2522 return nil, "Invalid destination hostname"; 2524 return nil, "Invalid destination JID";
2523 elseif prosody.hosts[remotehost] then 2525 end
2524 return nil, "Both hosts are local"; 2526 local iq = st.iq { from = jid_join(localnode, localhost); to = jid_join(remotenode, remotehost, remoteresource); type = "get"; id = new_id() }
2525 end
2526
2527 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
2528 :tag("ping", {xmlns="urn:xmpp:ping"}); 2527 :tag("ping", {xmlns="urn:xmpp:ping"});
2528
2529 local time_start = time.now(); 2529 local time_start = time.now();
2530 local print = self.session.print; 2530 local print = self.session.print;
2531 2531
2532 local writing = false; 2532 local writing = false;
2533 local sink = logger.add_simple_sink(function (source, level, message) 2533 local sink = logger.add_simple_sink(function (source, level, message)