plugins/mod_version.lua

changeset 3483
443139c396c5
parent 3421
d3852a4d37e2
equal deleted inserted replaced
3482:e1a4f7b15caf 3483:443139c396c5
8 8
9 local st = require "util.stanza"; 9 local st = require "util.stanza";
10 10
11 module:add_feature("jabber:iq:version"); 11 module:add_feature("jabber:iq:version");
12 12
13 local version = "the best operating system ever!"; 13 local version;
14 14
15 local query = st.stanza("query", {xmlns = "jabber:iq:version"}) 15 local query = st.stanza("query", {xmlns = "jabber:iq:version"})
16 :tag("name"):text("Prosody"):up() 16 :tag("name"):text("Prosody"):up()
17 :tag("version"):text(prosody.version):up(); 17 :tag("version"):text(prosody.version):up();
18 18
19 if not module:get_option("hide_os_type") then 19 if not module:get_option("hide_os_type") then
20 if os.getenv("WINDIR") then 20 if os.getenv("WINDIR") then
21 version = "Windows"; 21 version = "Windows";
22 else 22 else
23 local uname = io.popen(module:get_option("os_version_command") or "uname"); 23 local os_version_command = module:get_option("os_version_command");
24 if uname then 24 local ok pposix = pcall(require, "pposix");
25 version = uname:read("*a"); 25 if not os_version_command and (ok and pposix and pposix.uname) then
26 else 26 version = pposix.uname().sysname;
27 version = "an OS"; 27 end
28 if not version then
29 local uname = io.popen(os_version_command or "uname");
30 if uname then
31 version = uname:read("*a");
32 end
33 uname:close();
28 end 34 end
29 end 35 end
30 version = version:match("^%s*(.-)%s*$") or version; 36 if version then
31 query:tag("os"):text(version):up(); 37 version = version:match("^%s*(.-)%s*$") or version;
38 query:tag("os"):text(version):up();
39 end
32 end 40 end
33 41
34 module:hook("iq/host/jabber:iq:version:query", function(event) 42 module:hook("iq/host/jabber:iq:version:query", function(event)
35 local stanza = event.stanza; 43 local stanza = event.stanza;
36 if stanza.attr.type == "get" and stanza.attr.to == module.host then 44 if stanza.attr.type == "get" and stanza.attr.to == module.host then

mercurial