sessionmanager: Make session.send() return true unless there really is an error ...
[prosody.git] / util / dependencies.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 module("dependencies", package.seeall)
10
11 function softreq(...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil, lib; end end
12
13 -- Required to be able to find packages installed with luarocks
14 if not softreq "luarocks.loader" then -- LuaRocks 2.x
15         softreq "luarocks.require"; -- LuaRocks <1.x
16 end
17
18 function missingdep(name, sources, msg)
19         print("");
20         print("**************************");
21         print("Prosody was unable to find "..tostring(name));
22         print("This package can be obtained in the following ways:");
23         print("");
24         local longest_platform = 0;
25         for platform in pairs(sources) do
26                 longest_platform = math.max(longest_platform, #platform);
27         end
28         for platform, source in pairs(sources) do
29                 print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source);
30         end
31         print("");
32         print(msg or (name.." is required for Prosody to run, so we will now exit."));
33         print("More help can be found on our website, at http://prosody.im/doc/depends");
34         print("**************************");
35         print("");
36 end
37
38 -- COMPAT w/pre-0.8 Debian: The Debian config file used to use 
39 -- util.ztact, which has been removed from Prosody in 0.8. This
40 -- is to log an error for people who still use it, so they can
41 -- update their configs.
42 package.preload["util.ztact"] = function ()
43         if not package.loaded["core.loggingmanager"] then
44                 error("util.ztact has been removed from Prosody and you need to fix your config "
45                     .."file. More information can be found at http://prosody.im/doc/packagers#ztact", 0);
46         else
47                 error("module 'util.ztact' has been deprecated in Prosody 0.8.");
48         end
49 end;
50
51 function check_dependencies()
52         if _VERSION ~= "Lua 5.1" then
53                 print "***********************************"
54                 print("Unsupported Lua version: ".._VERSION);
55                 print("Only Lua 5.1 is supported.");
56                 print "***********************************"
57                 return false;
58         end
59
60         local fatal;
61         
62         local lxp = softreq "lxp"
63         
64         if not lxp then
65                 missingdep("luaexpat", {
66                                 ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-expat0";
67                                 ["luarocks"] = "luarocks install luaexpat";
68                                 ["Source"] = "http://www.keplerproject.org/luaexpat/";
69                         });
70                 fatal = true;
71         end
72         
73         local socket = softreq "socket"
74         
75         if not socket then
76                 missingdep("luasocket", {
77                                 ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-socket2";
78                                 ["luarocks"] = "luarocks install luasocket";
79                                 ["Source"] = "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/";
80                         });
81                 fatal = true;
82         end
83         
84         local lfs, err = softreq "lfs"
85         if not lfs then
86                 missingdep("luafilesystem", {
87                                 ["luarocks"] = "luarocks install luafilesystem";
88                                 ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-filesystem0";
89                                 ["Source"] = "http://www.keplerproject.org/luafilesystem/";
90                         });
91                 fatal = true;
92         end
93         
94         local ssl = softreq "ssl"
95         
96         if not ssl then
97                 missingdep("LuaSec", {
98                                 ["Debian/Ubuntu"] = "http://prosody.im/download/start#debian_and_ubuntu";
99                                 ["luarocks"] = "luarocks install luasec";
100                                 ["Source"] = "http://www.inf.puc-rio.br/~brunoos/luasec/";
101                         }, "SSL/TLS support will not be available");
102         end
103         
104         local encodings, err = softreq "util.encodings"
105         if not encodings then
106                 if err:match("not found") then
107                         missingdep("util.encodings", { ["Windows"] = "Make sure you have encodings.dll from the Prosody distribution in util/";
108                                                 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so";
109                                         });
110                 else
111                         print "***********************************"
112                         print("util/encodings couldn't be loaded. Check that you have a recent version of libidn");
113                         print ""
114                         print("The full error was:");
115                         print(err)
116                         print "***********************************"
117                 end
118                 fatal = true;
119         end
120
121         local hashes, err = softreq "util.hashes"
122         if not hashes then
123                 if err:match("not found") then
124                         missingdep("util.hashes", { ["Windows"] = "Make sure you have hashes.dll from the Prosody distribution in util/";
125                                                 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so";
126                                         });
127                 else
128                         print "***********************************"
129                         print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)");
130                         print ""
131                         print("The full error was:");
132                         print(err)
133                         print "***********************************"
134                 end
135                 fatal = true;
136         end
137         return not fatal;
138 end
139
140 function log_warnings()
141         if ssl then
142                 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)");
143                 if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then
144                         log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends");
145                 end
146         end
147         if lxp then
148                 if not pcall(lxp.new, { StartDoctypeDecl = false }) then
149                         log("error", "The version of LuaExpat on your system leaves Prosody "
150                                 .."vulnerable to denial-of-service attacks. You should upgrade to "
151                                 .."LuaExpat 1.3.0 or higher as soon as possible. See "
152                                 .."http://prosody.im/doc/depends#luaexpat for more information.");
153                 end
154                 if not lxp.new({}).getcurrentbytecount then
155                         log("error", "The version of LuaExpat on your system does not support "
156                                 .."stanza size limits, which may leave servers on untrusted "
157                                 .."networks (e.g. the internet) vulnerable to denial-of-service "
158                                 .."attacks. You should upgrade to LuaExpat 1.3.0 or higher as "
159                                 .."soon as possible. See "
160                                 .."http://prosody.im/doc/depends#luaexpat for more information.");
161                 end
162         end
163 end
164
165 return _M;