plugins/mod_version.lua

1
-- Prosody IM
2
-- Copyright (C) 2008-2010 Matthew Wild
3
-- Copyright (C) 2008-2010 Waqas Hussain
4
-- 
5
-- This project is MIT/X11 licensed. Please see the
6
-- COPYING file in the source package for more information.
7
--
8
 
9
local st = require "util.stanza";
10
 
11
module:add_feature("jabber:iq:version");
12
 
13
local version;
14
 
15
local query = st.stanza("query", {xmlns = "jabber:iq:version"})
16
	:tag("name"):text("Prosody"):up()
17
	:tag("version"):text(prosody.version):up();
18
 
19
if not module:get_option("hide_os_type") then
20
	if os.getenv("WINDIR") then
21
		version = "Windows";
22
	else
23
		local os_version_command = module:get_option("os_version_command");
24
		local ok pposix = pcall(require, "pposix");
25
		if not os_version_command and (ok and pposix and pposix.uname) then
26
			version = pposix.uname().sysname;
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();
34
		end
35
	end
36
	if version then
37
		version = version:match("^%s*(.-)%s*$") or version;
38
		query:tag("os"):text(version):up();
39
	end
40
end
41
 
42
module:hook("iq/host/jabber:iq:version:query", function(event)
43
	local stanza = event.stanza;
44
	if stanza.attr.type == "get" and stanza.attr.to == module.host then
45
		event.origin.send(st.reply(stanza):add_child(query));
46
		return true;
47
	end
48
end);