|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+local st = require "util.stanza";
|
|
|
2
|
+
|
|
|
3
|
+local token_util = module:require "token/util".new(module);
|
|
|
4
|
+
|
|
|
5
|
+-- no token configuration but required
|
|
|
6
|
+if token_util == nil then
|
|
|
7
|
+ log("error", "no token configuration but it is required");
|
|
|
8
|
+ return;
|
|
|
9
|
+end
|
|
|
10
|
+
|
|
|
11
|
+-- filters rayo iq in case of requested from not jwt authenticated sessions
|
|
|
12
|
+module:hook("pre-iq/full", function(event)
|
|
|
13
|
+ local stanza = event.stanza;
|
|
|
14
|
+ if stanza.name == "iq" then
|
|
|
15
|
+ local dial = stanza:get_child('dial', 'urn:xmpp:rayo:1');
|
|
|
16
|
+ if dial then
|
|
|
17
|
+ local session = event.origin;
|
|
|
18
|
+ local token = session.auth_token;
|
|
|
19
|
+
|
|
|
20
|
+ -- find header with attr name 'JvbRoomName' and extract its value
|
|
|
21
|
+ local headerName = 'JvbRoomName';
|
|
|
22
|
+ local roomName;
|
|
|
23
|
+ for _, child in ipairs(dial.tags) do
|
|
|
24
|
+ if (child.name == 'header'
|
|
|
25
|
+ and child.attr.name == headerName) then
|
|
|
26
|
+ roomName = child.attr.value;
|
|
|
27
|
+ break;
|
|
|
28
|
+ end
|
|
|
29
|
+ end
|
|
|
30
|
+
|
|
|
31
|
+ if token == nil
|
|
|
32
|
+ or roomName == nil
|
|
|
33
|
+ or not token_util:verify_room(session, roomName) then
|
|
|
34
|
+ module:log("info",
|
|
|
35
|
+ "Filtering stanza dial, stanza:%s", tostring(stanza));
|
|
|
36
|
+ session.send(st.error_reply(stanza, "auth", "forbidden"));
|
|
|
37
|
+ return true;
|
|
|
38
|
+ end
|
|
|
39
|
+ end
|
|
|
40
|
+ end
|
|
|
41
|
+end);
|