Annotate

mod_s2s_blackwhitelist/mod_s2s_blackwhitelist.lua @ 415:3ba1a5b9d657

mod_addressing: Add partial implementation of Extended Stanza Addressing, XEP-33.
author Kim Alvefur <zash@zash.se>
date Sat, 03 Sep 2011 01:36:05 +0200
parent 215:281db5eefcb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
215
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
1
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
2 local s2smanager = require "core.s2smanager";
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
3 local config = require "core.configmanager";
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
4 local nameprep = require "util.encodings".stringprep.nameprep;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
5
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
6 local s2s_blacklist = module:get_option_array("s2s_blacklist");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
7 local s2s_whitelist = module:get_option_array("s2s_whitelist");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
8 local s2s_enable_blackwhitelist = module:get_option_string("s2s_enable_blackwhitelist");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
9 local is_blacklist_enabled = false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
10 local is_whitelist_enabled = false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
11
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
12 if s2s_enable_blackwhitelist == "blacklist" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
13 if type(s2s_blacklist) == "table" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
14 is_blacklist_enabled = true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
15 module:log("debug", "s2s-blacklist is enabled");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
16 local count=#s2s_blacklist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
17 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
18 module:log("debug", "s2s-blacklist adding [%s]", s2s_blacklist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
19 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
20 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
21 elseif s2s_enable_blackwhitelist == "whitelist" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
22 if type(s2s_whitelist) == "table" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
23 is_whitelist_enabled = true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
24 module:log("debug", "s2s-whitelist is enabled");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
25 local count=#s2s_whitelist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
26 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
27 module:log("debug", "s2s-whitelist adding [%s]", s2s_whitelist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
28 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
29 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
30 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
31
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
32 local function reload_list()
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
33 s2s_blacklist = module:get_option_array("s2s_blacklist");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
34 s2s_whitelist = module:get_option_array("s2s_whitelist");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
35 s2s_enable_blackwhitelist = module:get_option_string("s2s_enable_blackwhitelist");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
36
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
37 if s2s_enable_blackwhitelist == "blacklist" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
38 if type(s2s_blacklist) == "table" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
39 is_blacklist_enabled = true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
40 module:log("debug", "s2s-blacklist is enabled");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
41 local count=#s2s_blacklist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
42 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
43 module:log("debug", "s2s-blacklist adding [%s]", s2s_blacklist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
44 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
45 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
46 elseif s2s_enable_blackwhitelist == "whitelist" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
47 if type(s2s_whitelist) == "table" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
48 is_whitelist_enabled = true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
49 module:log("debug", "s2s-whitelist is enabled");
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
50 local count=#s2s_whitelist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
51 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
52 module:log("debug", "s2s-whitelist adding [%s]", s2s_whitelist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
53 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
54 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
55 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
56 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
57
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
58 local _make_connect = s2smanager.make_connect;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
59 function s2smanager.make_connect(session, connect_host, connect_port)
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
60 local host = session.to_host;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
61 if not session.s2sValidation then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
62 if (host and is_blacklist_enabled == true) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
63 local count=#s2s_blacklist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
64 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
65 if s2s_blacklist[i] == host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
66 module:log ("error", "blacklisted host received %s", s2s_blacklist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
67 s2smanager.destroy_session(session, "This host does not serve "..host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
68 return false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
69 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
70 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
71 elseif (host and is_whitelist_enabled == true) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
72 local count=#s2s_whitelist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
73 local found=false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
74 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
75 if s2s_whitelist[i] == host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
76 found=true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
77 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
78 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
79 if found == false then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
80 module:log ("error", "host %s couldn't be found in whitelist", host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
81 s2smanager.destroy_session(session, "This host does not serve "..host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
82 return false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
83 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
84 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
85 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
86 return _make_connect(session, connect_host, connect_port);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
87 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
88
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
89 local _stream_opened = s2smanager.streamopened;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
90 function s2smanager.streamopened(session, attr)
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
91 local host = attr.from and nameprep(attr.from);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
92 if not host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
93 session.s2sValidation = false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
94 else
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
95 session.s2sValidation = true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
96 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
97
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
98 if (host and is_blacklist_enabled == true) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
99 local count=#s2s_blacklist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
100 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
101 if s2s_blacklist[i] == host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
102 module:log ("error", "blacklisted host received %s", s2s_blacklist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
103 session:close({condition = "host-unknown", text = "This host does not serve " .. host});
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
104 return;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
105 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
106 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
107 elseif (host and is_whitelist_enabled == true) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
108 local count=#s2s_whitelist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
109 local found=false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
110 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
111 if s2s_whitelist[i] == host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
112 found=true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
113 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
114 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
115 if found == false then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
116 module:log ("error", "host %s couldn't be found in whitelist", host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
117 session:close({condition = "host-unknown", text = "This host does not serve " .. host});
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
118 return;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
119 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
120 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
121 _stream_opened(session, attr);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
122 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
123
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
124
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
125 local function server_dialback_result_hook (event)
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
126 local origin, stanza = event.origin, event.stanza;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
127
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
128 if origin.type == "s2sin" or origin.type == "s2sin_unauthed" then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
129
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
130 local host = stanza.attr.from;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
131
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
132 if (host and is_blacklist_enabled == true) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
133 local count=#s2s_blacklist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
134 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
135 if s2s_blacklist[i] == host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
136 module:log ("error", "blacklisted host received %s", s2s_blacklist[i]);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
137 origin:close({condition = "host-unknown", text = "This host does not serve " .. host});
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
138 return true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
139 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
140 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
141 elseif (host and is_whitelist_enabled == true) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
142 local count=#s2s_whitelist;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
143 local found=false;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
144 for i=1,count do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
145 if s2s_whitelist[i] == host then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
146 found=true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
147 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
148 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
149 if found == false then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
150 module:log ("error", "host %s couldn't be found in whitelist", host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
151 origin:close({condition = "host-unknown", text = "This host does not serve " .. host});
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
152 return true;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
153 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
154 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
155
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
156 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
157
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
158 return nil;
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
159 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
160
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
161 local function handle_activated_host (host)
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
162 if (hosts[host] and hosts[host].events) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
163 hosts[host].events.add_handler("stanza/jabber:server:dialback:result", server_dialback_result_hook, 100);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
164 module:log ("debug", "adding hook for %s", host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
165 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
166 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
167
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
168 local function handle_deactivated_host (host)
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
169 if (hosts[host] and hosts[host].events) then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
170 hosts[host].events.remove_handler("stanza/jabber:server:dialback:result", server_dialback_result_hook);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
171 module:log ("debug", "removing hook for %s", host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
172 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
173 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
174
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
175 prosody.events.add_handler("host-activated", handle_activated_host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
176 prosody.events.add_handler("component-activated", handle_activated_host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
177 prosody.events.add_handler("host-deactivated", handle_deactivated_host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
178 prosody.events.add_handler("component-deactivated", handle_deactivated_host);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
179 prosody.events.add_handler("config-reloaded", reload_list);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
180
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
181 for name, host in pairs(hosts) do
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
182 if host and host.events then
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
183 host.events.add_handler("stanza/jabber:server:dialback:result", server_dialback_result_hook, 100);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
184 module:log ("debug", "adding hook for %s", name);
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
185 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
186 end
281db5eefcb4 mod_s2s_blackwhitelist: adding blacklist and whitelist plugin for s2s connections
Gaurav <gauravsri@gmail.com>
parents:
diff changeset
187