Annotate

mod_proxy65/mod_proxy65.lua @ 65:a35eb0764ac6

mod_proxy65: tcp connection of initiator and target are established
author Thilo Cestonaro <thilo@cestona.ro>
date Wed, 28 Oct 2009 00:03:28 +0100
parent 64:853c3c7e9936
child 66:b86ae5e21a56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 --
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
6
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
7 if module:get_host_type() ~= "component" then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
8 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
9 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
10
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
11
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
12 local jid_split = require "util.jid".split;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
13 local st = require "util.stanza";
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
14 local component_register = require "core.componentmanager".register_component;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
15 local component_deregister = require "core.componentmanager".deregister_component;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
16 local configmanager = require "core.configmanager";
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
17 local config_get = require "core.configmanager".get;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
18 local connlisteners_register = require "net.connlisteners".register;
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
19 local connlisteners_start = require "net.connlisteners".start;
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
20 local connlisteners_deregister = require "net.connlisteners".deregister;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
21 local adns, dns = require "net.adns", require "net.dns";
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
22 local add_task = require "util.timer".add_task;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
23 local max_dns_depth = config.get("*", "core", "dns_max_depth") or 3;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
24 local dns_timeout = config.get("*", "core", "dns_timeout") or 60;
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
25 local serialize = require "util.serialization".serialize;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
26 local sha1 = require "util.hashes".sha1;
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
27
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
28 local replies_cache = {};
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
29 local _host = module:get_host();
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
30 local _name = "SOCKS5 Bytestreams Service";
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
31 local connlistener = {registered=false};
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
32 local _config = {};
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
33 local sessions = {};
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
34 local transfers = {};
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
35 local component;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
36
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
37 _config.port = config_get(_host, "core", "port");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
38 _config.interface = config_get(_host, "core", "interface");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
39
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
40 if _config.port == nil then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
41 _config.port = 5000;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
42 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
43
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
44 local function bin2hex(bin)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
45 return bin:gsub(".", function (c) return ("%02x"):format(c:byte()); 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
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
48 function new_session(conn)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
49 local w = function(s) conn.write(s:gsub("\n", "\r\n")); end;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
50 local session = { conn = conn;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
51 send = function (t) w(tostring(t)); end;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
52 print = function (t) w("| "..tostring(t).."\n"); end;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
53 disconnect = function () conn.close(); end;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
54 };
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
55
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
56 return session;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
57 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
58
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
59 function connlistener.listener(conn, data)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
60 module:log("debug", "listener called....")
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
61 local session = sessions[conn];
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
62
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
63 if data ~= nil then module:log("debug", bin2hex(data)); end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
64 if not session and data ~= nil and data:byte() == string.char(5):byte() and data:len() > 2 then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
65 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
66 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
67 local supported = false;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
68 for i=1, nmethods, 1 do
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
69 if(methods:sub(i):byte() == string.char(0):byte()) then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
70 supported = true;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
71 break;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
72 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
73 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
74 if(supported) then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
75 module:log("debug", "new session found ... ")
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
76 session = new_session(conn);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
77 sessions[conn] = session;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
78 session.send(string.char(5, 0));
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
79 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
80 elseif data ~= nil and data:len() > 6 and
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
81 data:sub(1):byte() == string.char(5):byte() and -- SOCKS5 has 5 in first byte
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
82 data:sub(2):byte() == string.char(1):byte() and -- CMD must be 1
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
83 data:sub(3):byte() == string.char(0):byte() and -- RSV must be 0
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
84 data:sub(4):byte() == string.char(3):byte() and -- ATYP must be 3
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
85 data:sub(-2):byte() == string.char(0):byte() and data:sub(-1):byte() == string.char(0):byte() -- PORT must be 0, size 2 byte
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
86 then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
87 local sha = data:sub(6, data:len() - 2);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
88 module:log("debug", "gotten sha: >%s<", sha);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
89 if transfers[sha] == nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
90 transfers[sha] = {};
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
91 transfers[sha].target = conn;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
92 module:log("debug", "target connected ... ");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
93 elseif transfers[sha].target ~= nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
94 transfers[sha].initiator = conn;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
95 module:log("debug", "initiator connected ... ");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
96 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
97 session.send(string.char(5, 0, 0, 3, 40) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
98 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
99 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
100
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
101 function connlistener.disconnect(conn, err)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
102
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
103 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
104
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
105 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
106 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
107 if reply == nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
108 reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#info")
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
109 :tag("identity", {category='proxy', type='bytestreams', name=_name}):up()
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
110 :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
111 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
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 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
115 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
116 return reply;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
117 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
118
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
119 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
120 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
121 if reply == nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
122 reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#items");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
123 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
124 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
125
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
126 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
127 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
128 return reply;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
129 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
130
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
131 local function get_stream_host(stanza)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
132 local reply = replies_cache.stream_host;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
133 local 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
134 if reply == nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
135 reply = st.iq({type="result", from=_host})
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
136 :query("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
137 :tag("streamhost", {jid=_host, host=_config.interface, port=_config.port}); -- TODO get the correct data
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
138 replies_cache.stream_host = reply;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
139 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
140
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
141 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
142 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
143 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
144 return reply;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
145 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
146
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
147 module.unload = function()
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
148 component_deregister(_host);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
149 connlisteners_deregister("proxy65");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
150 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
151
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
152 local function set_activation(stanza)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
153 local from = nil;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
154 local to = nil;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
155 local sid = nil;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
156 local reply = nil;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
157 if stanza.attr ~= nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
158 from = stanza.attr.from;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
159 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
160 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
161 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
162 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
163 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
164 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
165 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
166 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
167 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
168 if from ~= nil and to ~= nil and sid ~= nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
169 reply = st.iq({type="result", from=_host});
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
170 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
171 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
172 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
173 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
174
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
175 local function forward(initiator, target)
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
176 module:log("debug", "forward it ....");
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
177 end
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
178
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
179
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
180 local function register()
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
181 connlistener.default_port = _config.port;
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
182 connlistener.default_interface = "*";
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
183 connlistener.default_mode = "*a";
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
184 connlistener.registered = connlisteners_register('proxy65', connlistener);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
185 if(connlistener.registered == false) then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
186 error("Proxy65: Could not establish a connection listener. Check your configuration please.");
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
187 else
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
188 connlistener.handler = connlisteners_start('proxy65');
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
189 module:log("debug", "Connection listener registered ... ")
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
190 module:add_item("proxy65", {jid=_host, name=_name})
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
191 component = component_register(_host, function(origin, stanza)
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
192 local to_node, to_host, to_resource = jid_split(stanza.attr.to);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
193 if to_node == nil then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
194 local type = stanza.attr.type;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
195 if type == "error" or type == "result" then return; end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
196 if stanza.name == "iq" and type == "get" then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
197 local xmlns = stanza.tags[1].attr.xmlns
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
198 if xmlns == "http://jabber.org/protocol/disco#info" then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
199 origin.send(get_disco_info(stanza));
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
200 return true;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
201 elseif xmlns == "http://jabber.org/protocol/disco#items" then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
202 origin.send(get_disco_items(stanza));
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
203 return true;
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
204 elseif xmlns == "http://jabber.org/protocol/bytestreams" then
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
205 origin.send(get_stream_host(stanza));
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
206 return true;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
207 end
65
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
208 elseif stanza.name == "iq" and type == "set" then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
209 local reply, from, to, sid = set_activation(stanza);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
210 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
211 module:log("debug", "need to build sha1 of data: from: %s, to: %s, sid: %s", from, to, sid);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
212 local sha = sha1(sid .. from .. to, true);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
213 module:log("debug", "generated sha: %s", sha);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
214 if(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
215 origin.send(reply);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
216 forward(transfers[sha].initiator, transfers[sha].target);
a35eb0764ac6 mod_proxy65: tcp connection of initiator and target are established
Thilo Cestonaro <thilo@cestona.ro>
parents: 64
diff changeset
217 transfers[sha] = nil;
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
64
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
220 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
221 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
222 return;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
223 end);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
224 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
225 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
226
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
227 local function getDefaultIP(host)
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
228 local handle;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
229 handle = adns.lookup(function (reply)
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
230 handle = nil;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
231
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
232 -- COMPAT: This is a compromise for all you CNAME-(ab)users :)
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
233 if not (reply and reply[#reply] and reply[#reply].a) then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
234 local count = max_dns_depth;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
235 reply = dns.peek(host, "CNAME", "IN");
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
236 while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
237 module:log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
238 reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN");
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
239 count = count - 1;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
240 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
241 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
242 -- end of CNAME resolving
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
243
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
244 if reply and reply[#reply] and reply[#reply].a then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
245 module:log("debug", "DNS reply for %s gives us %s", host, reply[#reply].a);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
246 _config.interface = reply[#reply].a
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
247 return register();
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
248 else
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
249 module:log("debug", "DNS lookup failed to get a response for %s", host);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
250 if host:find(".") ~= nil then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
251 host = host:gsub("^[^%.]*%.", "");
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
252 if host:find(".") ~= nil then -- still one dot left?
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
253 return getDefaultIP(host);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
254 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
255 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
256 error("Proxy65: Could not get an interface to bind to. Please configure one.");
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
257 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
258 end, host, "A", "IN");
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
259
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
260 -- Set handler for DNS timeout
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
261 add_task(dns_timeout, function ()
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
262 if handle then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
263 adns.cancel(handle, true);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
264 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
265 end);
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
266 return true;
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
267 end
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
268
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
269 if _config.interface ~= nil then
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
270 register();
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
271 else
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
272 getDefaultIP(_host); -- try to DNS lookup module:host()
853c3c7e9936 mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
273 end