Mercurial > prosody-modules
annotate mod_proxy65/mod_proxy65.lua @ 585:ce2798a1bc56
mod_carbons: Don't try to send carbons for entirely offline users.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 28 Jan 2012 15:10:04 +0100 |
parents | a54cc7bca826 |
children |
rev | line source |
---|---|
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
1 -- Copyright (C) 2009 Thilo Cestonaro |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
2 -- |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
3 -- This project is MIT/X11 licensed. Please see the |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
4 -- COPYING file in the source package for more information. |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
5 -- |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
6 --[[ |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
7 * to restart the proxy in the console: e.g. |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
8 module:unload("proxy65"); |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
9 > server.removeserver(<proxy65_port>); |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
10 module:load("proxy65", <proxy65_jid>); |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
11 ]]-- |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
12 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
13 if module:get_host_type() ~= "component" then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
14 error("proxy65 should be loaded as a component, please see http://prosody.im/doc/components", 0); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
15 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
16 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
17 local jid_split = require "util.jid".split; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
18 local st = require "util.stanza"; |
70
d3afb1403aa7
mod_proxy65: Remove unused bin2hex function, and compact more code. Finally down <200 lines :)
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
19 local componentmanager = require "core.componentmanager"; |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
20 local config_get = require "core.configmanager".get; |
70
d3afb1403aa7
mod_proxy65: Remove unused bin2hex function, and compact more code. Finally down <200 lines :)
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
21 local connlisteners = require "net.connlisteners"; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
22 local sha1 = require "util.hashes".sha1; |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
23 |
70
d3afb1403aa7
mod_proxy65: Remove unused bin2hex function, and compact more code. Finally down <200 lines :)
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
24 local host, name = module:get_host(), "SOCKS5 Bytestreams Service"; |
72
2bf6c7c590a1
mod_proxy65: component register and deregister are with "_component" appended
Thilo Cestonaro <thilo@cestona.ro>
parents:
70
diff
changeset
|
25 local sessions, transfers, component, replies_cache = {}, {}, nil, {}; |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
26 |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
27 local proxy_port = config_get(host, "core", "proxy65_port") or 5000; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
28 local proxy_interface = config_get(host, "core", "proxy65_interface") or "*"; |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
29 local proxy_address = config_get(host, "core", "proxy65_address") or (proxy_interface ~= "*" and proxy_interface) or host; |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
30 local proxy_acl = config_get(host, "core", "proxy65_acl"); |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
31 |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
32 local connlistener = { default_port = proxy_port, default_interface = proxy_interface, default_mode = "*a" }; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
33 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
34 function connlistener.listener(conn, data) |
70
d3afb1403aa7
mod_proxy65: Remove unused bin2hex function, and compact more code. Finally down <200 lines :)
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
35 local session = sessions[conn] or {}; |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
36 |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
37 if session.setup == nil and data ~= nil and data:sub(1):byte() == 0x05 and data:len() > 2 then |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
38 local nmethods = data:sub(2):byte(); |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
39 local methods = data:sub(3); |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
40 local supported = false; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
41 for i=1, nmethods, 1 do |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
42 if(methods:sub(i):byte() == 0x00) then -- 0x00 == method: NO AUTH |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
43 supported = true; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
44 break; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
45 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
46 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
47 if(supported) then |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
48 module:log("debug", "new session found ... ") |
70
d3afb1403aa7
mod_proxy65: Remove unused bin2hex function, and compact more code. Finally down <200 lines :)
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
49 session.setup = true; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
50 sessions[conn] = session; |
69
87dfd34dceb2
mod_proxy65: removed unneeded var and session stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
68
diff
changeset
|
51 conn.write(string.char(5, 0)); |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
52 end |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
53 return; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
54 end |
70
d3afb1403aa7
mod_proxy65: Remove unused bin2hex function, and compact more code. Finally down <200 lines :)
Matthew Wild <mwild1@gmail.com>
parents:
69
diff
changeset
|
55 if session.setup then |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
56 if session.sha ~= nil and transfers[session.sha] ~= nil then |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
57 local sha = session.sha; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
58 if transfers[sha].activated == true and transfers[sha].initiator == conn and transfers[sha].target ~= nil then |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
59 transfers[sha].target.write(data); |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
60 return; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
61 end |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
62 end |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
63 if data ~= nil and data:len() == 0x2F and -- 40 == length of SHA1 HASH, and 7 other bytes => 47 => 0x2F |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
64 data:sub(1):byte() == 0x05 and -- SOCKS5 has 5 in first byte |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
65 data:sub(2):byte() == 0x01 and -- CMD must be 1 |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
66 data:sub(3):byte() == 0x00 and -- RSV must be 0 |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
67 data:sub(4):byte() == 0x03 and -- ATYP must be 3 |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
68 data:sub(5):byte() == 40 and -- SHA1 HASH length must be 40 (0x28) |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
69 data:sub(-2):byte() == 0x00 and -- PORT must be 0, size 2 byte |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
70 data:sub(-1):byte() == 0x00 |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
71 then |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
72 local sha = data:sub(6, 45); -- second param is not count! it's the ending index (included!) |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
73 if transfers[sha] == nil then |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
74 transfers[sha] = {}; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
75 transfers[sha].activated = false; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
76 transfers[sha].target = conn; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
77 session.sha = sha; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
78 module:log("debug", "target connected ... "); |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
79 elseif transfers[sha].target ~= nil then |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
80 transfers[sha].initiator = conn; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
81 session.sha = sha; |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
82 module:log("debug", "initiator connected ... "); |
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
83 end |
69
87dfd34dceb2
mod_proxy65: removed unneeded var and session stuff
Thilo Cestonaro <thilo@cestona.ro>
parents:
68
diff
changeset
|
84 conn.write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
85 else |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
86 log:module("warn", "Neither data transfer nor initial connect of a participator of a transfer.") |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
87 conn.close(); |
66
b86ae5e21a56
mod_proxy65: done! Who wants to test? :)
Thilo Cestonaro <thilo@cestona.ro>
parents:
65
diff
changeset
|
88 end |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
89 else |
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
90 if data ~= nil then |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
91 module:log("warn", "unknown connection with no authentication data -> closing it"); |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
92 conn.close(); |
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
93 end |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
94 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
95 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
96 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
97 function connlistener.disconnect(conn, err) |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
98 local session = sessions[conn]; |
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
99 if session then |
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
100 if session.sha and transfers[session.sha] then |
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
101 local initiator, target = transfers[session.sha].initiator, transfers[session.sha].target; |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
102 if initiator == conn and target ~= nil then |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
103 target.close(); |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
104 elseif target == conn and initiator ~= nil then |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
105 initiator.close(); |
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
106 end |
95
e704834c5613
mod_proxy65: hopefully remove a memory leak (thx waqas!)
Thilo Cestonaro <thilo@cestona.ro>
parents:
83
diff
changeset
|
107 transfers[session.sha] = nil; |
77
85b8622ccffd
mod_proxy65: close unknown connection with no authentication data, close target if initator hangs up and vica versa
Thilo Cestonaro <thilo@cestona.ro>
parents:
74
diff
changeset
|
108 end |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
109 -- Clean up any session-related stuff here |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
110 sessions[conn] = nil; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
111 end |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
112 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
113 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
114 local function get_disco_info(stanza) |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
115 local reply = replies_cache.disco_info; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
116 if reply == nil then |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
117 reply = st.iq({type='result', from=host}):query("http://jabber.org/protocol/disco#info") |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
118 :tag("identity", {category='proxy', type='bytestreams', name=name}):up() |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
119 :tag("feature", {var="http://jabber.org/protocol/bytestreams"}); |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
120 replies_cache.disco_info = reply; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
121 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
122 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
123 reply.attr.id = stanza.attr.id; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
124 reply.attr.to = stanza.attr.from; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
125 return reply; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
126 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
127 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
128 local function get_disco_items(stanza) |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
129 local reply = replies_cache.disco_items; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
130 if reply == nil then |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
131 reply = st.iq({type='result', from=host}):query("http://jabber.org/protocol/disco#items"); |
79
34f5818c90e9
mod_proxy65: answer with correct disco#info data on a disco#info request
Thilo Cestonaro <thilo@cestona.ro>
parents:
77
diff
changeset
|
132 replies_cache.disco_items = reply; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
133 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
134 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
135 reply.attr.id = stanza.attr.id; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
136 reply.attr.to = stanza.attr.from; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
137 return reply; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
138 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
139 |
82
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
140 local function _jid_join(node, host, resource) |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
141 local ret = host; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
142 if ret then |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
143 if node then |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
144 ret = node .. "@" .. ret; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
145 end |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
146 if resource then |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
147 ret = ret .. "/" .. resource; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
148 end |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
149 end |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
150 return ret; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
151 end |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
152 |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
153 local function get_stream_host(origin, stanza) |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
154 local reply = replies_cache.stream_host; |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
155 local err_reply = replies_cache.stream_host_err; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
156 local sid = stanza.tags[1].attr.sid; |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
157 local allow = false; |
82
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
158 local jid_node, jid_host, jid_resource = jid_split(stanza.attr.from); |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
159 |
82
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
160 if stanza.attr.from == nil then |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
161 jid_node = origin.username; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
162 jid_host = origin.host; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
163 jid_resource = origin.resource; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
164 end |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
165 |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
166 if proxy_acl and #proxy_acl > 0 then |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
167 if host ~= nil then -- at least a domain is needed. |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
168 for _, acl in ipairs(proxy_acl) do |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
169 local acl_node, acl_host, acl_resource = jid_split(acl); |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
170 if ((acl_node ~= nil and acl_node == jid_node) or acl_node == nil) and |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
171 ((acl_host ~= nil and acl_host == jid_host) or acl_host == nil) and |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
172 ((acl_resource ~= nil and acl_resource == jid_resource) or acl_resource == nil) then |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
173 allow = true; |
608dc38b6580
mod_proxy65: never use global varnames as local varnames, it can break your brain!
Thilo Cestonaro <thilo@cestona.ro>
parents:
80
diff
changeset
|
174 end |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
175 end |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
176 end |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
177 else |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
178 allow = true; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
179 end |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
180 if allow == true then |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
181 if reply == nil then |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
182 reply = st.iq({type="result", from=host}) |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
183 :query("http://jabber.org/protocol/bytestreams") |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
184 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port}); |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
185 replies_cache.stream_host = reply; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
186 end |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
187 else |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
188 module:log("warn", "Denying use of proxy for %s", tostring(_jid_join(jid_node, jid_host, jid_resource))); |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
189 if err_reply == nil then |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
190 err_reply = st.iq({type="error", from=host}) |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
191 :query("http://jabber.org/protocol/bytestreams") |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
192 :tag("error", {code='403', type='auth'}) |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
193 :tag("forbidden", {xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'}); |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
194 replies_cache.stream_host_err = err_reply; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
195 end |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
196 reply = err_reply; |
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
197 end |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
198 reply.attr.id = stanza.attr.id; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
199 reply.attr.to = stanza.attr.from; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
200 reply.tags[1].attr.sid = sid; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
201 return reply; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
202 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
203 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
204 module.unload = function() |
72
2bf6c7c590a1
mod_proxy65: component register and deregister are with "_component" appended
Thilo Cestonaro <thilo@cestona.ro>
parents:
70
diff
changeset
|
205 componentmanager.deregister_component(host); |
74
d70813f7d90a
mod_proxy65: make it work again
Thilo Cestonaro <thilo@cestona.ro>
parents:
73
diff
changeset
|
206 connlisteners.deregister(module.host .. ':proxy65'); |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
207 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
208 |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
209 local function set_activation(stanza) |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
210 local from, to, sid, reply = nil; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
211 from = stanza.attr.from; |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
212 if stanza.tags[1] ~= nil and tostring(stanza.tags[1].name) == "query" then |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
213 if stanza.tags[1].attr ~= nil then |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
214 sid = stanza.tags[1].attr.sid; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
215 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
216 if stanza.tags[1].tags[1] ~= nil and tostring(stanza.tags[1].tags[1].name) == "activate" then |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
217 to = stanza.tags[1].tags[1][1]; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
218 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
219 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
220 if from ~= nil and to ~= nil and sid ~= nil then |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
221 reply = st.iq({type="result", from=host, to=from}); |
65
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
222 reply.attr.id = stanza.attr.id; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
223 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
224 return reply, from, to, sid; |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
225 end |
a35eb0764ac6
mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents:
64
diff
changeset
|
226 |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
227 function handle_to_domain(origin, stanza) |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
228 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
229 if to_node == nil then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
230 local type = stanza.attr.type; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
231 if type == "error" or type == "result" then return; end |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
232 if stanza.name == "iq" and type == "get" then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
233 local xmlns = stanza.tags[1].attr.xmlns |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
234 if xmlns == "http://jabber.org/protocol/disco#info" then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
235 origin.send(get_disco_info(stanza)); |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
236 return true; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
237 elseif xmlns == "http://jabber.org/protocol/disco#items" then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
238 origin.send(get_disco_items(stanza)); |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
239 return true; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
240 elseif xmlns == "http://jabber.org/protocol/bytestreams" then |
80
bed9a6b40fae
mod_proxy65: basic white list - access control list
Thilo Cestonaro <thilo@cestona.ro>
parents:
79
diff
changeset
|
241 origin.send(get_stream_host(origin, stanza)); |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
242 return true; |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
243 end |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
244 elseif stanza.name == "iq" and type == "set" then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
245 local reply, from, to, sid = set_activation(stanza); |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
246 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
247 local sha = sha1(sid .. from .. to, true); |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
248 if transfers[sha] == nil then |
98
a54cc7bca826
mod_proxy65: correct log level, be more descriptive
Thilo Cestonaro <thilo@cestona.ro>
parents:
95
diff
changeset
|
249 module:log("warn", "Recieved request to activate transfer with no participants"); |
a54cc7bca826
mod_proxy65: correct log level, be more descriptive
Thilo Cestonaro <thilo@cestona.ro>
parents:
95
diff
changeset
|
250 module:log("debug", "The sha1 of the transfer which should be activated was: %s", sha); |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
251 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
252 origin.send(reply); |
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
253 transfers[sha].activated = true; |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
254 end |
83
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
255 else |
9d92db30235f
mod_proxy65: make it work from external initiators, too
Thilo Cestonaro <thilo@cestona.ro>
parents:
82
diff
changeset
|
256 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
257 end |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
258 end |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
259 end |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
260 return; |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
261 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
262 |
73
adb9d1b879c2
mod_proxy65: changed the listener name to be unique on a per component basis and display a good error description when connlistener register fails
Thilo Cestonaro <thilo@cestona.ro>
parents:
72
diff
changeset
|
263 if not connlisteners.register(module.host .. ':proxy65', connlistener) then |
68
0df3e4d1f1a3
mod_proxy65: Reviewed and re-factored the code, added proxy_address to specify the address which the proxy advertises for clients to connect to
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
264 error("mod_proxy65: Could not establish a connection listener. Check your configuration please."); |
73
adb9d1b879c2
mod_proxy65: changed the listener name to be unique on a per component basis and display a good error description when connlistener register fails
Thilo Cestonaro <thilo@cestona.ro>
parents:
72
diff
changeset
|
265 error(" one possible cause for this would be that two proxy65 components share the same port."); |
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
266 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
267 |
74
d70813f7d90a
mod_proxy65: make it work again
Thilo Cestonaro <thilo@cestona.ro>
parents:
73
diff
changeset
|
268 connlisteners.start(module.host .. ':proxy65'); |
72
2bf6c7c590a1
mod_proxy65: component register and deregister are with "_component" appended
Thilo Cestonaro <thilo@cestona.ro>
parents:
70
diff
changeset
|
269 component = componentmanager.register_component(host, handle_to_domain); |