379
|
1 |
local filters = require "util.filters"; |
|
2 |
local config = {} |
|
3 |
config.file = module:get_option_string("crossdomain_file", ""); |
|
4 |
config.string = module:get_option_string("crossdomain_string", [[<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><site-control permitted-cross-domain-policies="master-only"/><allow-access-from domain="*" /></cross-domain-policy>]]); |
|
5 |
local string = '' |
|
6 |
if not config.file ~= '' then |
|
7 |
local f = assert(io.open(config.file)); |
|
8 |
string = f:read("*all"); |
|
9 |
else |
|
10 |
string = config.string |
|
11 |
end |
|
12 |
|
|
13 |
module:log("debug", "crossdomain string: "..string); |
|
14 |
|
|
15 |
module:set_global(); |
|
16 |
|
|
17 |
function filter_policy(data, session) |
|
18 |
-- Since we only want to check the first block of data, remove the filter |
|
19 |
filters.remove_filter(session, "bytes/in", filter_policy); |
|
20 |
if data == "<policy-file-request/>\0" then |
|
21 |
session.send([[<?xml version="1.0"?> |
|
22 |
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"> |
|
23 |
<cross-domain-policy> |
|
24 |
<site-control permitted-cross-domain-policies="master-only"/> |
|
25 |
<allow-access-from domain="livechat.concepts.tim-online.nl" to-ports="5222" /> |
|
26 |
</cross-domain-policy>]].."\0"); |
|
27 |
return nil; -- Drop data to prevent it reaching the XMPP parser |
|
28 |
else |
|
29 |
return data; -- Pass data through, it wasn't a policy request |
|
30 |
end |
|
31 |
|
|
32 |
end |
|
33 |
|
|
34 |
function filter_session(session) |
|
35 |
if session.type == "c2s_unauthed" then |
|
36 |
filters.add_filter(session, "bytes/in", filter_policy, -1); |
|
37 |
end |
|
38 |
end |
|
39 |
|
|
40 |
function module.load() |
|
41 |
filters.add_filter_hook(filter_session); |
|
42 |
end |
|
43 |
|
|
44 |
function module.unload() |
|
45 |
filters.remove_filter_hook(filter_session); |
|
46 |
end |