Software /
code /
prosody-modules
Annotate
mod_srvinjection/mod_srvinjection.lua @ 96:c1f4edf3bea7
mod_srvinjection: Initial commit.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 23 Nov 2009 21:38:43 +0500 |
child | 99:2d03350613c4 |
rev | line source |
---|---|
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 module.host = "*"; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local adns = require "net.adns"; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 local map = module:get_option("srvinjection") or {}; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 for host, mapping in pairs(map) do |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 if type(mapping) == "table" and type(mapping[1]) == "string" and (type(mapping[2]) == "number") then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local connecthost, connectport = mapping[1], mapping[2] or 5269; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 map[host] = {{ |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 srv = { |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 target = connecthost.."."; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 port = connectport; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 priority = 1; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 weight = 0; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 }; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 }}; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 else |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 module:log("warn", "Ignoring invalid SRV injection for host '%s'", host); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 map[host] = nil; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local original_lookup = adns.lookup; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 function adns.lookup(handler, qname, qtype, qclass) |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 if qtype == "SRV" then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local host = qname:match("^_xmpp%-server%._tcp%.(.*)%.$"); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 local mapping = map[host]; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 if mapping then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 handler(mapping); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 return; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 return original_lookup(handler, qname, qtype, qclass); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 function module.unload() |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 adns.lookup = original_lookup; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 end |