Software / code / prosody-modules
Comparison
mod_version_spoofed/mod_version_spoofed.lua @ 6344:eb834f754f57 draft default tip
Merge update
| author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
|---|---|
| date | Fri, 18 Jul 2025 20:45:38 +0700 |
| parent | 6315:cc42d3548452 |
comparison
equal
deleted
inserted
replaced
| 6309:342f88e8d522 | 6344:eb834f754f57 |
|---|---|
| 1 -- Prosody IM | |
| 2 -- Copyright (C) 2025-2025 Nicholas George | |
| 3 -- Original mod_version copyright | |
| 4 -- Copyright (C) 2008-2010 Matthew Wild | |
| 5 -- Copyright (C) 2008-2010 Waqas Hussain | |
| 6 -- | |
| 7 -- This project is MIT/X11 licensed. Please see the | |
| 8 -- COPYING file in the source package for more information. | |
| 9 -- | |
| 10 -- This is a fork of mod_version that implements the ability to spoof server information. | |
| 11 -- This should replace mod_version in the modules_enabled list. Do not load both as they | |
| 12 -- will conflict. | |
| 13 | |
| 14 local st = require "util.stanza"; | |
| 15 | |
| 16 module:add_feature("jabber:iq:version"); | |
| 17 | |
| 18 local query = st.stanza("query", {xmlns = "jabber:iq:version"}) | |
| 19 :text_tag("name", module:get_option_string("server_name", "Prosody")) | |
| 20 :text_tag("version", module:get_option_string("server_version", prosody.version)); | |
| 21 | |
| 22 if not module:get_option_boolean("hide_os_type") then | |
| 23 local platform; | |
| 24 local spoofed_platform = module:get_option_string("server_platform", nil); | |
| 25 if not spoofed_platform then | |
| 26 if os.getenv("WINDIR") then | |
| 27 platform = "Windows"; | |
| 28 else | |
| 29 local os_version_command = module:get_option_string("os_version_command"); | |
| 30 local ok, pposix = pcall(require, "prosody.util.pposix"); | |
| 31 if not os_version_command and (ok and pposix and pposix.uname) then | |
| 32 local uname, err = pposix.uname(); | |
| 33 if not uname then | |
| 34 module:log("debug", "Could not retrieve OS name: %s", err); | |
| 35 else | |
| 36 platform = uname.sysname; | |
| 37 end | |
| 38 end | |
| 39 if not platform then | |
| 40 local uname = io.popen(os_version_command or "uname"); | |
| 41 if uname then | |
| 42 platform = uname:read("*a"); | |
| 43 end | |
| 44 uname:close(); | |
| 45 end | |
| 46 end | |
| 47 if platform then | |
| 48 platform = platform:match("^%s*(.-)%s*$") or platform; | |
| 49 query:text_tag("os", platform); | |
| 50 end | |
| 51 else | |
| 52 query:text_tag("os", spoofed_platform); | |
| 53 end | |
| 54 end | |
| 55 | |
| 56 module:hook("iq-get/host/jabber:iq:version:query", function(event) | |
| 57 local origin, stanza = event.origin, event.stanza; | |
| 58 origin.send(st.reply(stanza):add_child(query)); | |
| 59 return true; | |
| 60 end); |