Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Update poltergeist's presence with identity information. (#2650)

Дамян Минков6cc880001600
diff --git a/resources/prosody-plugins/mod_muc_poltergeist.lua b/resources/prosody-plugins/mod_muc_poltergeist.lua
index 32a9aac2c6..252800908c 100644
--- a/resources/prosody-plugins/mod_muc_poltergeist.lua
+++ b/resources/prosody-plugins/mod_muc_poltergeist.lua
@@ -6,6 +6,7 @@ local parse = neturl.parseQuery;
local st = require "util.stanza";
local get_room_from_jid = module:require "util".get_room_from_jid;
local wrap_async_run = module:require "util".wrap_async_run;
+local update_presence_identity = module:require "util".update_presence_identity;
local timer = require "util.timer";
local MUC_NS = "http://jabber.org/protocol/muc";
@@ -114,8 +115,9 @@ end
-- @param token the token we received
-- @param room_name the room name
-- @param group name of the group (optional)
+-- @param session the session to use for storing token specific fields
-- @return true if values are ok or false otherwise
-function verify_token(token, room_name, group)
+function verify_token(token, room_name, group, session)
if disableTokenVerification then
return true;
end
@@ -129,7 +131,6 @@ function verify_token(token, room_name, group)
return false;
end
- local session = {};
session.auth_token = token;
local verified, reason = token_util:process_and_verify_token(session);
if not verified then
@@ -200,7 +201,8 @@ end);
-- @param name the display name fot the occupant (optional)
-- @param avatar the avatar to use for the new occupant (optional)
-- @param status the initial status to use for the new occupant (optional)
-function create_poltergeist_occupant(room, nick, name, avatar, status)
+-- @param context the information that we will store for this poltergeist
+function create_poltergeist_occupant(room, nick, name, avatar, status, context)
log("debug", "create_poltergeist_occupant %s", nick);
-- Join poltergeist occupant to room, with the invited JID as their nick
local join_presence = st.presence({
@@ -227,6 +229,14 @@ function create_poltergeist_occupant(room, nick, name, avatar, status)
join:tag("password", { xmlns = MUC_NS }):text(room_password);
end
+ update_presence_identity(
+ join_presence,
+ context.user,
+ context.group,
+ context.creator_user,
+ context.creator_group
+ );
+
room:handle_first_presence(
prosody.hosts[poltergeist_component], join_presence);
@@ -390,8 +400,9 @@ function handle_create_poltergeist (event)
local name = params["name"];
local avatar = params["avatar"];
local status = params["status"];
+ local session = {};
- if not verify_token(params["token"], room_name, group) then
+ if not verify_token(params["token"], room_name, group, session) then
return 403;
end
@@ -410,8 +421,16 @@ function handle_create_poltergeist (event)
else
username = generate_uuid();
store_username(room, user_id, username);
+ local context = {
+ user = {
+ id = user_id;
+ };
+ group = group;
+ creator_user = session.jitsi_meet_context_user;
+ creator_group = session.jitsi_meet_context_group;
+ };
create_poltergeist_occupant(
- room, string.sub(username, 0, 8), name, avatar, status);
+ room, string.sub(username, 0, 8), name, avatar, status, context);
return 200;
end
end
@@ -430,7 +449,7 @@ function handle_update_poltergeist (event)
local group = params["group"];
local status = params["status"];
- if not verify_token(params["token"], room_name, group) then
+ if not verify_token(params["token"], room_name, group, {}) then
return 403;
end
@@ -467,7 +486,7 @@ function handle_remove_poltergeist (event)
local room_name = params["room"];
local group = params["group"];
- if not verify_token(params["token"], room_name, group) then
+ if not verify_token(params["token"], room_name, group, {}) then
return 403;
end
diff --git a/resources/prosody-plugins/mod_presence_identity.lua b/resources/prosody-plugins/mod_presence_identity.lua
index 72ed00ce0f..4db397e841 100644
--- a/resources/prosody-plugins/mod_presence_identity.lua
+++ b/resources/prosody-plugins/mod_presence_identity.lua
@@ -1,4 +1,5 @@
local stanza = require "util.stanza";
+local update_presence_identity = module:require "util".update_presence_identity;
-- For all received presence messages, if the jitsi_meet_context_(user|group)
-- values are set in the session, then insert them into the presence messages
@@ -6,32 +7,13 @@ local stanza = require "util.stanza";
function on_message(event)
if event and event["stanza"] then
if event.origin and event.origin.jitsi_meet_context_user then
- -- First remove any 'identity' element if it already
- -- exists
- event.stanza:maptags(
- function(tag)
- for k, v in pairs(tag) do
- if k == "name" and v == "identity" then
- return nil
- end
- end
- return tag
- end
- )
- module:log("debug", "Presence after previous identity stripped: %s", tostring(event.stanza))
- event.stanza:tag("identity"):tag("user")
- for k, v in pairs(event.origin.jitsi_meet_context_user) do
- event.stanza:tag(k):text(v):up()
- end
- event.stanza:up()
-
- -- Add the group information if it is present
- if event.origin.jitsi_meet_context_group then
- event.stanza:tag("group"):text(event.origin.jitsi_meet_context_group)
- end
+ update_presence_identity(
+ event.stanza,
+ event.origin.jitsi_meet_context_user,
+ event.origin.jitsi_meet_context_group
+ );
- module:log("debug", "Sending presence with identity inserted %s", tostring(event.stanza))
end
end
end
diff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.lua
index 110ac98868..6f7e26b1e7 100644
--- a/resources/prosody-plugins/util.lib.lua
+++ b/resources/prosody-plugins/util.lib.lua
@@ -73,8 +73,67 @@ function wrap_async_run(event,handler)
return result;
end
+--- Updates presence stanza, by adding identity node
+-- @param stanza the presence stanza
+-- @param user the user to which presence we are updating identity
+-- @param group the group of the user to which presence we are updating identity
+-- @param creator_user the user who created the user which presence we
+-- are updating (this is the poltergeist case, where a user creates
+-- a poltergeist), optional.
+-- @param creator_group the group of the user who created the user which
+-- presence we are updating (this is the poltergeist case, where a user creates
+-- a poltergeist), optional.
+function update_presence_identity(
+ stanza, user, group, creator_user, creator_group)
+
+ -- First remove any 'identity' element if it already
+ -- exists, so it cannot be spoofed by a client
+ stanza:maptags(
+ function(tag)
+ for k, v in pairs(tag) do
+ if k == "name" and v == "identity" then
+ return nil
+ end
+ end
+ return tag
+ end
+ )
+ module:log("debug",
+ "Presence after previous identity stripped: %s", tostring(stanza));
+
+ stanza:tag("identity"):tag("user");
+ for k, v in pairs(user) do
+ stanza:tag(k):text(v):up();
+ end
+ stanza:up();
+
+ -- Add the group information if it is present
+ if group then
+ stanza:tag("group"):text(group):up();
+ end
+
+ -- Add the creator user information if it is present
+ if creator_user then
+ stanza:tag("creator_user");
+ for k, v in pairs(creator_user) do
+ stanza:tag(k):text(v):up();
+ end
+ stanza:up();
+
+ -- Add the creator group information if it is present
+ if creator_group then
+ stanza:tag("creator_group"):text(creator_group):up();
+ end
+ stanza:up();
+ end
+
+ module:log("debug",
+ "Presence with identity inserted %s", tostring(stanza))
+end
+
return {
get_room_from_jid = get_room_from_jid;
wrap_async_run = wrap_async_run;
- room_jid_match_rewrite= room_jid_match_rewrite;
+ room_jid_match_rewrite = room_jid_match_rewrite;
+ update_presence_identity = update_presence_identity;
};
\ No newline at end of file