Update poltergeist's presence with identity information. (#2650)
This commit is contained in:
parent
e5596c3cd5
commit
6cc8800016
|
@ -6,6 +6,7 @@ local parse = neturl.parseQuery;
|
||||||
local st = require "util.stanza";
|
local st = require "util.stanza";
|
||||||
local get_room_from_jid = module:require "util".get_room_from_jid;
|
local get_room_from_jid = module:require "util".get_room_from_jid;
|
||||||
local wrap_async_run = module:require "util".wrap_async_run;
|
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 timer = require "util.timer";
|
||||||
local MUC_NS = "http://jabber.org/protocol/muc";
|
local MUC_NS = "http://jabber.org/protocol/muc";
|
||||||
|
|
||||||
|
@ -114,8 +115,9 @@ end
|
||||||
-- @param token the token we received
|
-- @param token the token we received
|
||||||
-- @param room_name the room name
|
-- @param room_name the room name
|
||||||
-- @param group name of the group (optional)
|
-- @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
|
-- @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
|
if disableTokenVerification then
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
|
@ -129,7 +131,6 @@ function verify_token(token, room_name, group)
|
||||||
return false;
|
return false;
|
||||||
end
|
end
|
||||||
|
|
||||||
local session = {};
|
|
||||||
session.auth_token = token;
|
session.auth_token = token;
|
||||||
local verified, reason = token_util:process_and_verify_token(session);
|
local verified, reason = token_util:process_and_verify_token(session);
|
||||||
if not verified then
|
if not verified then
|
||||||
|
@ -200,7 +201,8 @@ end);
|
||||||
-- @param name the display name fot the occupant (optional)
|
-- @param name the display name fot the occupant (optional)
|
||||||
-- @param avatar the avatar to use for the new 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)
|
-- @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);
|
log("debug", "create_poltergeist_occupant %s", nick);
|
||||||
-- Join poltergeist occupant to room, with the invited JID as their nick
|
-- Join poltergeist occupant to room, with the invited JID as their nick
|
||||||
local join_presence = st.presence({
|
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);
|
join:tag("password", { xmlns = MUC_NS }):text(room_password);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
update_presence_identity(
|
||||||
|
join_presence,
|
||||||
|
context.user,
|
||||||
|
context.group,
|
||||||
|
context.creator_user,
|
||||||
|
context.creator_group
|
||||||
|
);
|
||||||
|
|
||||||
room:handle_first_presence(
|
room:handle_first_presence(
|
||||||
prosody.hosts[poltergeist_component], join_presence);
|
prosody.hosts[poltergeist_component], join_presence);
|
||||||
|
|
||||||
|
@ -390,8 +400,9 @@ function handle_create_poltergeist (event)
|
||||||
local name = params["name"];
|
local name = params["name"];
|
||||||
local avatar = params["avatar"];
|
local avatar = params["avatar"];
|
||||||
local status = params["status"];
|
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;
|
return 403;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -410,8 +421,16 @@ function handle_create_poltergeist (event)
|
||||||
else
|
else
|
||||||
username = generate_uuid();
|
username = generate_uuid();
|
||||||
store_username(room, user_id, username);
|
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(
|
create_poltergeist_occupant(
|
||||||
room, string.sub(username, 0, 8), name, avatar, status);
|
room, string.sub(username, 0, 8), name, avatar, status, context);
|
||||||
return 200;
|
return 200;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -430,7 +449,7 @@ function handle_update_poltergeist (event)
|
||||||
local group = params["group"];
|
local group = params["group"];
|
||||||
local status = params["status"];
|
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;
|
return 403;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -467,7 +486,7 @@ function handle_remove_poltergeist (event)
|
||||||
local room_name = params["room"];
|
local room_name = params["room"];
|
||||||
local group = params["group"];
|
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;
|
return 403;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local stanza = require "util.stanza";
|
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)
|
-- 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
|
-- 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)
|
function on_message(event)
|
||||||
if event and event["stanza"] then
|
if event and event["stanza"] then
|
||||||
if event.origin and event.origin.jitsi_meet_context_user 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")
|
update_presence_identity(
|
||||||
for k, v in pairs(event.origin.jitsi_meet_context_user) do
|
event.stanza,
|
||||||
event.stanza:tag(k):text(v):up()
|
event.origin.jitsi_meet_context_user,
|
||||||
end
|
event.origin.jitsi_meet_context_group
|
||||||
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
|
|
||||||
|
|
||||||
module:log("debug", "Sending presence with identity inserted %s", tostring(event.stanza))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,8 +73,67 @@ function wrap_async_run(event,handler)
|
||||||
return result;
|
return result;
|
||||||
end
|
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 {
|
return {
|
||||||
get_room_from_jid = get_room_from_jid;
|
get_room_from_jid = get_room_from_jid;
|
||||||
wrap_async_run = wrap_async_run;
|
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;
|
||||||
};
|
};
|
Loading…
Reference in New Issue