Comparison

plugins/mod_admin_telnet.lua @ 7722:82333dfdfaff

mod_admin_telnet: Use the module:send() API for xmpp:ping command
author Kim Alvefur <zash@zash.se>
date Fri, 18 Nov 2016 14:08:38 +0100
parent 7474:701989ab904f
child 7723:488fddf88ffd
child 7911:e528d848a185
comparison
equal deleted inserted replaced
7721:92f771147de8 7722:82333dfdfaff
30 local has_pposix, pposix = pcall(require, "util.pposix"); 30 local has_pposix, pposix = pcall(require, "util.pposix");
31 31
32 local commands = module:shared("commands") 32 local commands = module:shared("commands")
33 local def_env = module:shared("env"); 33 local def_env = module:shared("env");
34 local default_env_mt = { __index = def_env }; 34 local default_env_mt = { __index = def_env };
35 local core_post_stanza = prosody.core_post_stanza;
36 35
37 local function redirect_output(_G, session) 36 local function redirect_output(_G, session)
38 local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end }); 37 local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end });
39 env.dofile = function(name) 38 env.dofile = function(name)
40 local f, err = envloadfile(name, env); 39 local f, err = envloadfile(name, env);
1060 def_env.xmpp = {}; 1059 def_env.xmpp = {};
1061 1060
1062 local st = require "util.stanza"; 1061 local st = require "util.stanza";
1063 function def_env.xmpp:ping(localhost, remotehost) 1062 function def_env.xmpp:ping(localhost, remotehost)
1064 if hosts[localhost] then 1063 if hosts[localhost] then
1065 core_post_stanza(hosts[localhost], 1064 module:send(st.iq{ from=localhost, to=remotehost, type="get", id="ping" }
1066 st.iq{ from=localhost, to=remotehost, type="get", id="ping" } 1065 :tag("ping", {xmlns="urn:xmpp:ping"}), hosts[localhost]);
1067 :tag("ping", {xmlns="urn:xmpp:ping"}));
1068 return true, "Sent ping"; 1066 return true, "Sent ping";
1069 else 1067 else
1070 return nil, "No such host"; 1068 return nil, "No such host";
1071 end 1069 end
1072 end 1070 end