Annotate

util/prosodyctl/check.lua @ 13854:0b01f40df0f9 13.0

mod_http_file_share: Add media-src 'self' to Content-Security-Policy header This allows certain media files to be loaded when navigated to directly in a web browser. Note that in some browsers (Chrome), the media gets transformed internally into a HTML page with some basic styles, but these are blocked due to our default-src policy of 'none' Although this could be unblocked with style-src unsafe-inline, it is not our plan to fix this, because this would have negative security implications. The reason for our CSP is to prevent the file share service from being used to host malicious HTML/CSS/JS. Yes, CSS can be malicious. Our file share service is for uploading and downloading files, it is not a substitute for website/content hosting.
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Apr 2025 12:25:06 +0100
parent 13841:d01cfbb7fc4f
child 13870:8078eebf5601
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
1 local configmanager = require "prosody.core.configmanager";
13218
e576c6a0d1f8 Merge 0.12->trunk
Kim Alvefur <zash@zash.se>
parents: 13122 13217
diff changeset
2 local moduleapi = require "prosody.core.moduleapi";
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
3 local show_usage = require "prosody.util.prosodyctl".show_usage;
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
4 local show_warning = require "prosody.util.prosodyctl".show_warning;
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
5 local is_prosody_running = require "prosody.util.prosodyctl".isrunning;
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
6 local parse_args = require "prosody.util.argparse".parse;
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
7 local dependencies = require "prosody.util.dependencies";
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local socket = require "socket";
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
9 local socket_url = require "socket.url";
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
10 local jid_split = require "prosody.util.jid".prepped_split;
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
11 local modulemanager = require "prosody.core.modulemanager";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
12 local async = require "prosody.util.async";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
13 local httputil = require "prosody.util.http";
13768
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
14 local human_units = require "prosody.util.human.units";
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
16 local function api(host)
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
17 return setmetatable({ name = "prosodyctl.check"; host = host; log = prosody.log }, { __index = moduleapi })
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
18 end
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
19
11826
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
20 local function check_ojn(check_type, target_host)
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
21 local http = require "prosody.net.http"; -- .new({});
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
22 local json = require "prosody.util.json";
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
23
11826
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
24 local response, err = async.wait_for(http.request(
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
25 ("https://observe.jabber.network/api/v1/check/%s"):format(httputil.urlencode(check_type)),
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
26 {
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
27 method="POST",
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
28 headers={["Accept"] = "application/json"; ["Content-Type"] = "application/json"},
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
29 body=json.encode({target=target_host}),
11826
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
30 }));
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
31
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
32 if not response then
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
33 return false, err;
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
34 end
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
35
11826
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
36 if response.code ~= 200 then
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
37 return false, ("API replied with non-200 code: %d"):format(response.code);
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
38 end
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
39
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
40 local decoded_body, err = json.decode(response.body);
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
41 if decoded_body == nil then
e1c4cc5d0ef8 prosodyctl: Use HTTP client in promise mode for connectivity check
Kim Alvefur <zash@zash.se>
parents: 11807
diff changeset
42 return false, ("Failed to parse API JSON: %s"):format(err)
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
43 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
44
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
45 local success = decoded_body["success"];
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
46 return success == true, nil;
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
47 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
48
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
49 local function check_probe(base_url, probe_module, target)
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
50 local http = require "prosody.net.http"; -- .new({});
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
51 local params = httputil.formencode({ module = probe_module; target = target })
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
52 local response, err = async.wait_for(http.request(base_url .. "?" .. params));
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
53
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
54 if not response then return false, err; end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
55
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
56 if response.code ~= 200 then return false, ("API replied with non-200 code: %d"):format(response.code); end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
57
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
58 for line in response.body:gmatch("[^\r\n]+") do
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
59 local probe_success = line:match("^probe_success%s+(%d+)");
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
60
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
61 if probe_success == "1" then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
62 return true;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
63 elseif probe_success == "0" then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
64 return false;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
65 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
66 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
67 return false, "Probe endpoint did not return a success status";
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
68 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
69
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
70 local function check_turn_service(turn_service, ping_service)
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
71 local ip = require "prosody.util.ip";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
72 local stun = require "prosody.net.stun";
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
73
13580
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
74 local result = { warnings = {} };
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
75
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
76 -- Create UDP socket for communication with the server
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
77 local sock = assert(require "socket".udp());
13580
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
78 do
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
79 local ok, err = sock:setsockname("*", 0);
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
80 if not ok then
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
81 result.error = "Unable to perform TURN test: setsockname: "..tostring(err);
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
82 return result;
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
83 end
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
84 ok, err = sock:setpeername(turn_service.host, turn_service.port);
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
85 if not ok then
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
86 result.error = "Unable to perform TURN test: setpeername: "..tostring(err);
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
87 return result;
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
88 end
836efad8483c util.prosodyctl.check: Improve error handling of UDP socket setup (for #1803)
Matthew Wild <mwild1@gmail.com>
parents: 13465
diff changeset
89 end
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
90 sock:settimeout(10);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
91
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
92 -- Helper function to receive a packet
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
93 local function receive_packet()
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
94 local raw_packet, err = sock:receive();
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
95 if not raw_packet then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
96 return nil, err;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
97 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
98 return stun.new_packet():deserialize(raw_packet);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
99 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
100
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
101 -- Send a "binding" query, i.e. a request for our external IP/port
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
102 local bind_query = stun.new_packet("binding", "request");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
103 bind_query:add_attribute("software", "prosodyctl check turn");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
104 sock:send(bind_query:serialize());
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
105
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
106 local bind_result, err = receive_packet();
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
107 if not bind_result then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
108 result.error = "No STUN response: "..err;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
109 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
110 elseif bind_result:is_err_resp() then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
111 result.error = ("STUN server returned error: %d (%s)"):format(bind_result:get_error());
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
112 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
113 elseif not bind_result:is_success_resp() then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
114 result.error = ("Unexpected STUN response: %d (%s)"):format(bind_result:get_type());
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
115 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
116 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
117
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
118 result.external_ip = bind_result:get_xor_mapped_address();
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
119 if not result.external_ip then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
120 result.error = "STUN server did not return an address";
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
121 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
122 end
12384
53b4549c2209 prosodyctl: check turn: Add check for private IP returned from STUN.
Matthew Wild <mwild1@gmail.com>
parents: 12383
diff changeset
123 if ip.new_ip(result.external_ip.address).private then
53b4549c2209 prosodyctl: check turn: Add check for private IP returned from STUN.
Matthew Wild <mwild1@gmail.com>
parents: 12383
diff changeset
124 table.insert(result.warnings, "STUN returned a private IP! Is the TURN server behind a NAT and misconfigured?");
53b4549c2209 prosodyctl: check turn: Add check for private IP returned from STUN.
Matthew Wild <mwild1@gmail.com>
parents: 12383
diff changeset
125 end
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
126
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
127 -- Send a TURN "allocate" request. Expected to fail due to auth, but
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
128 -- necessary to obtain a valid realm/nonce from the server.
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
129 local pre_request = stun.new_packet("allocate", "request");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
130 sock:send(pre_request:serialize());
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
131
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
132 local pre_result, err = receive_packet();
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
133 if not pre_result then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
134 result.error = "No initial TURN response: "..err;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
135 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
136 elseif pre_result:is_success_resp() then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
137 result.error = "TURN server does not have authentication enabled";
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
138 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
139 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
140
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
141 local realm = pre_result:get_attribute("realm");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
142 local nonce = pre_result:get_attribute("nonce");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
143
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
144 if not realm then
12383
a9b6ed86b573 prosodyctl: check turn: improve warning text to suggest issues
Matthew Wild <mwild1@gmail.com>
parents: 12382
diff changeset
145 table.insert(result.warnings, "TURN server did not return an authentication realm. Is authentication enabled?");
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
146 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
147 if not nonce then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
148 table.insert(result.warnings, "TURN server did not return a nonce");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
149 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
150
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
151 -- Use the configured secret to obtain temporary user/pass credentials
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
152 local turn_user, turn_pass = stun.get_user_pass_from_secret(turn_service.secret);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
153
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
154 -- Send a TURN allocate request, will fail if auth is wrong
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
155 local alloc_request = stun.new_packet("allocate", "request");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
156 alloc_request:add_requested_transport("udp");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
157 alloc_request:add_attribute("username", turn_user);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
158 if realm then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
159 alloc_request:add_attribute("realm", realm);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
160 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
161 if nonce then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
162 alloc_request:add_attribute("nonce", nonce);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
163 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
164 local key = stun.get_long_term_auth_key(realm or turn_service.host, turn_user, turn_pass);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
165 alloc_request:add_message_integrity(key);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
166 sock:send(alloc_request:serialize());
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
167
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
168 -- Check the response
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
169 local alloc_response, err = receive_packet();
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
170 if not alloc_response then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
171 result.error = "TURN server did not response to allocation request: "..err;
12466
9ee41552bca0 util.prosodyctl: check turn: ensure a result is always returned from a check (thanks eTaurus)
Matthew Wild <mwild1@gmail.com>
parents: 12441
diff changeset
172 return result;
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
173 elseif alloc_response:is_err_resp() then
12741
7b3deafb9162 prosodyctl: check turn: More clearly indicate the error is from TURN server
Matthew Wild <mwild1@gmail.com>
parents: 12520
diff changeset
174 result.error = ("TURN server failed to create allocation: %d (%s)"):format(alloc_response:get_error());
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
175 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
176 elseif not alloc_response:is_success_resp() then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
177 result.error = ("Unexpected TURN response: %d (%s)"):format(alloc_response:get_type());
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
178 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
179 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
180
12375
ea5e46601cfb prosodyctl: check turn: show relayed address(es) in verbose mode
Matthew Wild <mwild1@gmail.com>
parents: 12373
diff changeset
181 result.relayed_addresses = alloc_response:get_xor_relayed_addresses();
ea5e46601cfb prosodyctl: check turn: show relayed address(es) in verbose mode
Matthew Wild <mwild1@gmail.com>
parents: 12373
diff changeset
182
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
183 if not ping_service then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
184 -- Success! We won't be running the relay test.
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
185 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
186 end
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
187
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
188 -- Run the relay test - i.e. send a binding request to ping_service
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
189 -- and receive a response.
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
190
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
191 -- Resolve the IP of the ping service
12373
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
192 local ping_host, ping_port = ping_service:match("^([^:]+):(%d+)$");
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
193 if ping_host then
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
194 ping_port = tonumber(ping_port);
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
195 else
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
196 -- Only a hostname specified, use default STUN port
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
197 ping_host, ping_port = ping_service, 3478;
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
198 end
12416
19fd28239e73 prosodyctl: check turn: Fail with error if our own address is supplied for the ping test
Matthew Wild <mwild1@gmail.com>
parents: 12414
diff changeset
199
19fd28239e73 prosodyctl: check turn: Fail with error if our own address is supplied for the ping test
Matthew Wild <mwild1@gmail.com>
parents: 12414
diff changeset
200 if ping_host == turn_service.host then
19fd28239e73 prosodyctl: check turn: Fail with error if our own address is supplied for the ping test
Matthew Wild <mwild1@gmail.com>
parents: 12414
diff changeset
201 result.error = ("Unable to perform ping test: please supply an external STUN server address. See https://prosody.im/doc/turn#prosodyctl-check");
19fd28239e73 prosodyctl: check turn: Fail with error if our own address is supplied for the ping test
Matthew Wild <mwild1@gmail.com>
parents: 12414
diff changeset
202 return result;
19fd28239e73 prosodyctl: check turn: Fail with error if our own address is supplied for the ping test
Matthew Wild <mwild1@gmail.com>
parents: 12414
diff changeset
203 end
19fd28239e73 prosodyctl: check turn: Fail with error if our own address is supplied for the ping test
Matthew Wild <mwild1@gmail.com>
parents: 12414
diff changeset
204
12373
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
205 local ping_service_ip, err = socket.dns.toip(ping_host);
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
206 if not ping_service_ip then
12379
6ac3c580c00d prosodyctl: check turn: Clearer error when unable to resolve external service host
Matthew Wild <mwild1@gmail.com>
parents: 12377
diff changeset
207 result.error = "Unable to resolve ping service hostname: "..err;
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
208 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
209 end
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
210
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
211 -- Ask the TURN server to allow packets from the ping service IP
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
212 local perm_request = stun.new_packet("create-permission");
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
213 perm_request:add_xor_peer_address(ping_service_ip);
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
214 perm_request:add_attribute("username", turn_user);
12382
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
215 if realm then
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
216 perm_request:add_attribute("realm", realm);
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
217 end
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
218 if nonce then
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
219 perm_request:add_attribute("nonce", nonce);
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
220 end
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
221 perm_request:add_message_integrity(key);
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
222 sock:send(perm_request:serialize());
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
223
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
224 local perm_response, err = receive_packet();
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
225 if not perm_response then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
226 result.error = "No response from TURN server when requesting peer permission: "..err;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
227 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
228 elseif perm_response:is_err_resp() then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
229 result.error = ("TURN permission request failed: %d (%s)"):format(perm_response:get_error());
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
230 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
231 elseif not perm_response:is_success_resp() then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
232 result.error = ("Unexpected TURN response: %d (%s)"):format(perm_response:get_type());
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
233 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
234 end
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
235
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
236 -- Ask the TURN server to relay a STUN binding request to the ping server
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
237 local ping_data = stun.new_packet("binding"):serialize();
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
238
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
239 local ping_request = stun.new_packet("send", "indication");
12373
5417ec7e2ee8 prosodyctl: check turn: Allow specifying port for the ping service
Matthew Wild <mwild1@gmail.com>
parents: 12372
diff changeset
240 ping_request:add_xor_peer_address(ping_service_ip, ping_port);
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
241 ping_request:add_attribute("data", ping_data);
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
242 ping_request:add_attribute("username", turn_user);
12382
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
243 if realm then
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
244 ping_request:add_attribute("realm", realm);
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
245 end
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
246 if nonce then
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
247 ping_request:add_attribute("nonce", nonce);
574cf096a426 prosodyctl: check turn: fix traceback when server does not provide realm/nonce
Matthew Wild <mwild1@gmail.com>
parents: 12381
diff changeset
248 end
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
249 ping_request:add_message_integrity(key);
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
250 sock:send(ping_request:serialize());
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
251
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
252 local ping_response, err = receive_packet();
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
253 if not ping_response then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
254 result.error = "No response from ping server ("..ping_service_ip.."): "..err;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
255 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
256 elseif not ping_response:is_indication() or select(2, ping_response:get_method()) ~= "data" then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
257 result.error = ("Unexpected TURN response: %s %s"):format(select(2, ping_response:get_method()), select(2, ping_response:get_type()));
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
258 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
259 end
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
260
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
261 local pong_data = ping_response:get_attribute("data");
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
262 if not pong_data then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
263 result.error = "No data relayed from remote server";
12466
9ee41552bca0 util.prosodyctl: check turn: ensure a result is always returned from a check (thanks eTaurus)
Matthew Wild <mwild1@gmail.com>
parents: 12441
diff changeset
264 return result;
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
265 end
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
266 local pong = stun.new_packet():deserialize(pong_data);
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
267
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
268 result.external_ip_pong = pong:get_xor_mapped_address();
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
269 if not result.external_ip_pong then
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
270 result.error = "Ping server did not return an address";
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
271 return result;
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
272 end
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
273
12390
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
274 local relay_address_found, relay_port_matches;
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
275 for _, relayed_address in ipairs(result.relayed_addresses) do
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
276 if relayed_address.address == result.external_ip_pong.address then
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
277 relay_address_found = true;
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
278 relay_port_matches = result.external_ip_pong.port == relayed_address.port;
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
279 end
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
280 end
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
281 if not relay_address_found then
12383
a9b6ed86b573 prosodyctl: check turn: improve warning text to suggest issues
Matthew Wild <mwild1@gmail.com>
parents: 12382
diff changeset
282 table.insert(result.warnings, "TURN external IP vs relay address mismatch! Is the TURN server behind a NAT and misconfigured?");
12390
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
283 elseif not relay_port_matches then
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
284 table.insert(result.warnings, "External port does not match reported relay port! This is probably caused by a NAT in front of the TURN server.");
12383
a9b6ed86b573 prosodyctl: check turn: improve warning text to suggest issues
Matthew Wild <mwild1@gmail.com>
parents: 12382
diff changeset
285 end
a9b6ed86b573 prosodyctl: check turn: improve warning text to suggest issues
Matthew Wild <mwild1@gmail.com>
parents: 12382
diff changeset
286
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
287 --
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
288
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
289 return result;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
290 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
291
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
292 local function skip_bare_jid_hosts(host)
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
293 if jid_split(host) then
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
294 -- See issue #779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
295 return false;
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
296 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
297 return true;
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
298 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
299
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
300 local check_opts = {
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
301 short_params = {
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
302 h = "help", v = "verbose";
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
303 };
12376
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
304 value_params = {
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
305 ping = true;
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
306 };
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
307 };
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
308
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 local function check(arg)
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
310 if arg[1] == "help" or arg[1] == "--help" then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
311 show_usage([[check]], [[Perform basic checks on your Prosody installation]]);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 return 1;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314 local what = table.remove(arg, 1);
12376
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
315 local opts, opts_err, opts_info = parse_args(arg, check_opts);
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
316 if opts_err == "missing-value" then
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
317 print("Error: Expected a value after '"..opts_info.."'");
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
318 return 1;
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
319 elseif opts_err == "param-not-found" then
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
320 print("Error: Unknown parameter: "..opts_info);
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
321 return 1;
10353ad0ca7a prosodyctl: check: Slightly improved argument handling
Matthew Wild <mwild1@gmail.com>
parents: 12375
diff changeset
322 end
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
323 local array = require "prosody.util.array";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
324 local set = require "prosody.util.set";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
325 local it = require "prosody.util.iterators";
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 local ok = true;
13326
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
327 local function contains_match(hayset, needle) for member in hayset do if member:find(needle) then return true end end end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 local function disabled_hosts(host, conf) return host ~= "*" and conf.enabled ~= false; end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
329 local function is_user_host(host, conf) return host ~= "*" and conf.component_module == nil; end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
330 local function is_component_host(host, conf) return host ~= "*" and conf.component_module ~= nil; end
13706
a988867a5567 util.prosodyctl.check: Sort hosts in iterator for more stable output
Matthew Wild <mwild1@gmail.com>
parents: 13705
diff changeset
331 local function enabled_hosts() return it.filter(disabled_hosts, it.sorted_pairs(configmanager.getconfig())); end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
332 local function enabled_user_hosts() return it.filter(is_user_host, it.sorted_pairs(configmanager.getconfig())); end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
333 local function enabled_components() return it.filter(is_component_host, it.sorted_pairs(configmanager.getconfig())); end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
334
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
335 local checks = {};
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
336 function checks.disabled()
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 local disabled_hosts_set = set.new();
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
338 for host in it.filter("*", pairs(configmanager.getconfig())) do
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
339 if api(host):get_option_boolean("enabled") == false then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340 disabled_hosts_set:add(host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 if not disabled_hosts_set:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 local msg = "Checks will be skipped for these disabled hosts: %s";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 if what then msg = "These hosts are disabled: %s"; end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346 show_warning(msg, tostring(disabled_hosts_set));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347 if what then return 0; end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
348 print""
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
350 end
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
351 function checks.config()
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352 print("Checking config...");
12441
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
353
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
354 if what == "config" then
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
355 local files = configmanager.files();
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
356 print(" The following configuration files have been loaded:");
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
357 print(" - "..table.concat(files, "\n - "));
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
358 end
dc6263625069 prosodyctl: check config: Report paths of loaded configuration files (fixed #1729)
Matthew Wild <mwild1@gmail.com>
parents: 12416
diff changeset
359
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
360 local obsolete = set.new({ --> remove
12118
30d55809d9a6 util.prosodyctl.check: Add some more obsolete settings
Kim Alvefur <zash@zash.se>
parents: 12099
diff changeset
361 "archive_cleanup_interval",
30d55809d9a6 util.prosodyctl.check: Add some more obsolete settings
Kim Alvefur <zash@zash.se>
parents: 12099
diff changeset
362 "dns_timeout",
30d55809d9a6 util.prosodyctl.check: Add some more obsolete settings
Kim Alvefur <zash@zash.se>
parents: 12099
diff changeset
363 "muc_log_cleanup_interval",
30d55809d9a6 util.prosodyctl.check: Add some more obsolete settings
Kim Alvefur <zash@zash.se>
parents: 12099
diff changeset
364 "s2s_dns_resolvers",
30d55809d9a6 util.prosodyctl.check: Add some more obsolete settings
Kim Alvefur <zash@zash.se>
parents: 12099
diff changeset
365 "setgid",
30d55809d9a6 util.prosodyctl.check: Add some more obsolete settings
Kim Alvefur <zash@zash.se>
parents: 12099
diff changeset
366 "setuid",
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
367 });
12159
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
368 local function instead_use(kind, name, value)
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
369 if kind == "option" then
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
370 if value then
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
371 return string.format("instead, use '%s = %q'", name, value);
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
372 else
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
373 return string.format("instead, use '%s'", name);
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
374 end
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
375 elseif kind == "module" then
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
376 return string.format("instead, add %q to '%s'", name, value or "modules_enabled");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
377 elseif kind == "community" then
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
378 return string.format("instead, add %q from %s", name, value or "prosody-modules");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
379 end
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
380 return kind
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
381 end
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
382 local deprecated_replacements = {
12159
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
383 anonymous_login = instead_use("option", "authentication", "anonymous");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
384 daemonize = "instead, use the --daemonize/-D or --foreground/-F command line flags";
13254
a2ba3f06dcf4 util.prosodyctl.check: Correct modern replacement for 'disallow_s2s'
Kim Alvefur <zash@zash.se>
parents: 13219
diff changeset
385 disallow_s2s = instead_use("module", "s2s", "modules_disabled");
12159
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
386 no_daemonize = "instead, use the --daemonize/-D or --foreground/-F command line flags";
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
387 require_encryption = "instead, use 'c2s_require_encryption' and 's2s_require_encryption'";
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
388 vcard_compatibility = instead_use("community", "mod_compat_vcard");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
389 use_libevent = instead_use("option", "network_backend", "event");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
390 whitelist_registration_only = instead_use("option", "allowlist_registration_only");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
391 registration_whitelist = instead_use("option", "registration_allowlist");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
392 registration_blacklist = instead_use("option", "registration_blocklist");
aa299551f8c6 util.prosodyctl.check: Parameterize replacement instructions
Kim Alvefur <zash@zash.se>
parents: 12158
diff changeset
393 blacklist_on_registration_throttle_overload = instead_use("blocklist_on_registration_throttle_overload");
12898
4255db0f8e58 util.prosodyctl.check: Suggest 'http_cors_override' instead of older CORS settings
Kim Alvefur <zash@zash.se>
parents: 12842
diff changeset
394 cross_domain_bosh = "instead, use 'http_cors_override', see https://prosody.im/doc/http#cross-domain-cors-support";
4255db0f8e58 util.prosodyctl.check: Suggest 'http_cors_override' instead of older CORS settings
Kim Alvefur <zash@zash.se>
parents: 12842
diff changeset
395 cross_domain_websocket = "instead, use 'http_cors_override', see https://prosody.im/doc/http#cross-domain-cors-support";
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
396 };
11800
60018637f5d4 util.prosodyctl.check: Nudge towards plural port options
Kim Alvefur <zash@zash.se>
parents: 11799
diff changeset
397 -- FIXME all the singular _port and _interface options are supposed to be deprecated too
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
398 local deprecated_ports = { bosh = "http", legacy_ssl = "c2s_direct_tls" };
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
399 local port_suffixes = set.new({ "port", "ports", "interface", "interfaces", "ssl" });
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
400 for port, replacement in pairs(deprecated_ports) do
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
401 for suffix in port_suffixes do
11800
60018637f5d4 util.prosodyctl.check: Nudge towards plural port options
Kim Alvefur <zash@zash.se>
parents: 11799
diff changeset
402 local rsuffix = (suffix == "port" or suffix == "interface") and suffix.."s" or suffix;
12158
7ff3699c1653 util.prosodyctl.check: Move word to ease future translations
Kim Alvefur <zash@zash.se>
parents: 12157
diff changeset
403 deprecated_replacements[port.."_"..suffix] = "instead, use '"..replacement.."_"..rsuffix.."'"
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
404 end
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
405 end
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
406 local deprecated = set.new(array.collect(it.keys(deprecated_replacements)));
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
407 local known_global_options = set.new({
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
408 "access_control_allow_credentials",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
409 "access_control_allow_headers",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
410 "access_control_allow_methods",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
411 "access_control_max_age",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
412 "admin_socket",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
413 "body_size_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
414 "bosh_max_inactivity",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
415 "bosh_max_polling",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
416 "bosh_max_wait",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
417 "buffer_size_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
418 "c2s_close_timeout",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
419 "c2s_stanza_size_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
420 "c2s_tcp_keepalives",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
421 "c2s_timeout",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
422 "component_stanza_size_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
423 "component_tcp_keepalives",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
424 "consider_bosh_secure",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
425 "consider_websocket_secure",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
426 "console_banner",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
427 "console_prettyprint_settings",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
428 "daemonize",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
429 "gc",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
430 "http_default_host",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
431 "http_errors_always_show",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
432 "http_errors_default_message",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
433 "http_errors_detailed",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
434 "http_errors_messages",
11833
bd86ab8122d9 util.prosodyctl.check: Add two known globals from mod_http
Kim Alvefur <zash@zash.se>
parents: 11827
diff changeset
435 "http_max_buffer_size",
bd86ab8122d9 util.prosodyctl.check: Add two known globals from mod_http
Kim Alvefur <zash@zash.se>
parents: 11827
diff changeset
436 "http_max_content_size",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
437 "installer_plugin_path",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
438 "limits",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
439 "limits_resolution",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
440 "log",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
441 "multiplex_buffer_size",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
442 "network_backend",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
443 "network_default_read_size",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
444 "network_settings",
11940
2d82e4245aa3 util.prosodyctl.check: Add mod_http_openmetrics settings to known globals
Kim Alvefur <zash@zash.se>
parents: 11925
diff changeset
445 "openmetrics_allow_cidr",
2d82e4245aa3 util.prosodyctl.check: Add mod_http_openmetrics settings to known globals
Kim Alvefur <zash@zash.se>
parents: 11925
diff changeset
446 "openmetrics_allow_ips",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
447 "pidfile",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
448 "plugin_paths",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
449 "plugin_server",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
450 "prosodyctl_timeout",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
451 "prosody_group",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
452 "prosody_user",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
453 "run_as_root",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
454 "s2s_close_timeout",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
455 "s2s_insecure_domains",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
456 "s2s_require_encryption",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
457 "s2s_secure_auth",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
458 "s2s_secure_domains",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
459 "s2s_stanza_size_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
460 "s2s_tcp_keepalives",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
461 "s2s_timeout",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
462 "statistics",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
463 "statistics_config",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
464 "statistics_interval",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
465 "tcp_keepalives",
12099
b344edad61d3 core.certmanager: Rename preset option to 'tls_preset'
Kim Alvefur <zash@zash.se>
parents: 11957
diff changeset
466 "tls_profile",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
467 "trusted_proxies",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
468 "umask",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
469 "use_dane",
11634
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
470 "use_ipv4",
a6c87b4c0cdf util.prosodyctl.check: Format, sort option listings into canonical form
Kim Alvefur <zash@zash.se>
parents: 11617
diff changeset
471 "use_ipv6",
11635
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
472 "websocket_frame_buffer_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
473 "websocket_frame_fragment_limit",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
474 "websocket_get_response_body",
1b17b967838e util.prosodyctl.check: Collect options from all global plugins
Kim Alvefur <zash@zash.se>
parents: 11634
diff changeset
475 "websocket_get_response_text",
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
476 });
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
477 local config = configmanager.getconfig();
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
478 local global = api("*");
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
479 -- Check that we have any global options (caused by putting a host at the top)
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
480 if it.count(it.filter("log", pairs(config["*"]))) == 0 then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
481 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
482 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
483 print(" No global options defined. Perhaps you have put a host definition at the top")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
484 print(" of the config file? They should be at the bottom, see https://prosody.im/doc/configure#overview");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
485 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
486 if it.count(enabled_hosts()) == 0 then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
487 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
488 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
489 if it.count(it.filter("*", pairs(config))) == 0 then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
490 print(" No hosts are defined, please add at least one VirtualHost section")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
491 elseif config["*"]["enabled"] == false then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
492 print(" No hosts are enabled. Remove enabled = false from the global section or put enabled = true under at least one VirtualHost section")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
493 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
494 print(" All hosts are disabled. Remove enabled = false from at least one VirtualHost section")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
495 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
496 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
497 if not config["*"].modules_enabled then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
498 print(" No global modules_enabled is set?");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
499 local suggested_global_modules;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
500 for host, options in enabled_hosts() do --luacheck: ignore 213/host
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
501 if not options.component_module and options.modules_enabled then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
502 suggested_global_modules = set.intersection(suggested_global_modules or set.new(options.modules_enabled), set.new(options.modules_enabled));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
503 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
504 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
505 if suggested_global_modules and not suggested_global_modules:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
506 print(" Consider moving these modules into modules_enabled in the global section:")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
507 print(" "..tostring(suggested_global_modules / function (x) return ("%q"):format(x) end));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
508 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
509 print();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
510 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
511
13217
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
512 local function validate_module_list(host, name, modules)
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
513 if modules == nil then
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
514 return -- okay except for global section, checked separately
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
515 end
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
516 local t = type(modules)
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
517 if t ~= "table" then
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
518 print(" The " .. name .. " in the " .. host .. " section should not be a " .. t .. " but a list of strings, e.g.");
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
519 print(" " .. name .. " = { \"name_of_module\", \"another_plugin\", }")
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
520 print()
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
521 ok = false
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
522 return
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
523 end
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
524 for k, v in pairs(modules) do
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
525 if type(k) ~= "number" or type(v) ~= "string" then
13316
a27a329e93ca util.prosodyctl.check: Try to clarify check for misplaced k=v in modules_enabled (thanks aab and Menel)
Kim Alvefur <zash@zash.se>
parents: 13302
diff changeset
526 print(" The " .. name .. " in the " .. host .. " section should be a list of strings, e.g.");
13217
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
527 print(" " .. name .. " = { \"name_of_module\", \"another_plugin\", }")
13316
a27a329e93ca util.prosodyctl.check: Try to clarify check for misplaced k=v in modules_enabled (thanks aab and Menel)
Kim Alvefur <zash@zash.se>
parents: 13302
diff changeset
528 print(" It should not contain key = value pairs, try putting them outside the {} brackets.");
13217
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
529 ok = false
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
530 break
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
531 end
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
532 end
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
533 end
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
534
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
535 for host, options in enabled_hosts() do
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
536 validate_module_list(host, "modules_enabled", options.modules_enabled);
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
537 validate_module_list(host, "modules_disabled", options.modules_disabled);
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
538 end
b264ea91e930 util.prosodyctl.check: Validate format of module list options
Kim Alvefur <zash@zash.se>
parents: 13216
diff changeset
539
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
540 do -- Check for modules enabled both normally and as components
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
541 local modules = global:get_option_set("modules_enabled");
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
542 for host, options in enabled_hosts() do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
543 local component_module = options.component_module;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
544 if component_module and modules:contains(component_module) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
545 print((" mod_%s is enabled both in modules_enabled and as Component %q %q"):format(component_module, host, component_module));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
546 print(" This means the service is enabled on all VirtualHosts as well as the Component.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
547 print(" Are you sure this what you want? It may cause unexpected behaviour.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
548 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
549 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
550 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
551
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
552 -- Check for global options under hosts
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
553 local global_options = set.new(it.to_array(it.keys(config["*"])));
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
554 local obsolete_global_options = set.intersection(global_options, obsolete);
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
555 if not obsolete_global_options:empty() then
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
556 print("");
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
557 print(" You have some obsolete options you can remove from the global section:");
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
558 print(" "..tostring(obsolete_global_options))
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
559 ok = false;
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
560 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
561 local deprecated_global_options = set.intersection(global_options, deprecated);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
562 if not deprecated_global_options:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
563 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
564 print(" You have some deprecated options in the global section:");
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
565 for option in deprecated_global_options do
12158
7ff3699c1653 util.prosodyctl.check: Move word to ease future translations
Kim Alvefur <zash@zash.se>
parents: 12157
diff changeset
566 print((" '%s' -- %s"):format(option, deprecated_replacements[option]));
11798
ba88060fa145 util.prosodyctl.check: Suggest replacements for deprecated options #1684
Kim Alvefur <zash@zash.se>
parents: 11783
diff changeset
567 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
568 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
569 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
570 for host, options in it.filter(function (h) return h ~= "*" end, pairs(configmanager.getconfig())) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
571 local host_options = set.new(it.to_array(it.keys(options)));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
572 local misplaced_options = set.intersection(host_options, known_global_options);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
573 for name in pairs(options) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
574 if name:match("^interfaces?")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
575 or name:match("_ports?$") or name:match("_interfaces?$")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
576 or (name:match("_ssl$") and not name:match("^[cs]2s_ssl$")) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
577 misplaced_options:add(name);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
578 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
579 end
11799
8c9ec2db1d95 util.prosodyctl.check: Fix to not treat some options as misplaced
Kim Alvefur <zash@zash.se>
parents: 11798
diff changeset
580 -- FIXME These _could_ be misplaced, but we would have to check where the corresponding module is loaded to be sure
8c9ec2db1d95 util.prosodyctl.check: Fix to not treat some options as misplaced
Kim Alvefur <zash@zash.se>
parents: 11798
diff changeset
581 misplaced_options:exclude(set.new({ "external_service_port", "turn_external_port" }));
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
582 if not misplaced_options:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
583 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
584 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
585 local n = it.count(misplaced_options);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
586 print(" You have "..n.." option"..(n>1 and "s " or " ").."set under "..host.." that should be");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
587 print(" in the global section of the config file, above any VirtualHost or Component definitions,")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
588 print(" see https://prosody.im/doc/configure#overview for more information.")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
589 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
590 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", "));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
591 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
592 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
593 for host, options in enabled_hosts() do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
594 local host_options = set.new(it.to_array(it.keys(options)));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
595 local subdomain = host:match("^[^.]+");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
596 if not(host_options:contains("component_module")) and (subdomain == "jabber" or subdomain == "xmpp"
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
597 or subdomain == "chat" or subdomain == "im") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
598 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
599 print(" Suggestion: If "..host.. " is a new host with no real users yet, consider renaming it now to");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
600 print(" "..host:gsub("^[^.]+%.", "")..". You can use SRV records to redirect XMPP clients and servers to "..host..".");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
601 print(" For more information see: https://prosody.im/doc/dns");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
602 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
603 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
604 local all_modules = set.new(config["*"].modules_enabled);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
605 local all_options = set.new(it.to_array(it.keys(config["*"])));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
606 for host in enabled_hosts() do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
607 all_options:include(set.new(it.to_array(it.keys(config[host]))));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
608 all_modules:include(set.new(config[host].modules_enabled));
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
609 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
610 for mod in all_modules do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
611 if mod:match("^mod_") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
612 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
613 print(" Modules in modules_enabled should not have the 'mod_' prefix included.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
614 print(" Change '"..mod.."' to '"..mod:match("^mod_(.*)").."'.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
615 elseif mod:match("^auth_") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
616 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
617 print(" Authentication modules should not be added to modules_enabled,");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
618 print(" but be specified in the 'authentication' option.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
619 print(" Remove '"..mod.."' from modules_enabled and instead add");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
620 print(" authentication = '"..mod:match("^auth_(.*)").."'");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
621 print(" For more information see https://prosody.im/doc/authentication");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
622 elseif mod:match("^storage_") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
623 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
624 print(" storage modules should not be added to modules_enabled,");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
625 print(" but be specified in the 'storage' option.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
626 print(" Remove '"..mod.."' from modules_enabled and instead add");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
627 print(" storage = '"..mod:match("^storage_(.*)").."'");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
628 print(" For more information see https://prosody.im/doc/storage");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
629 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
630 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
631 if all_modules:contains("vcard") and all_modules:contains("vcard_legacy") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
632 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
633 print(" Both mod_vcard_legacy and mod_vcard are enabled but they conflict");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
634 print(" with each other. Remove one.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
635 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
636 if all_modules:contains("pep") and all_modules:contains("pep_simple") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
637 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
638 print(" Both mod_pep_simple and mod_pep are enabled but they conflict");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
639 print(" with each other. Remove one.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
640 end
13690
d112eac6a3dc prosodyctl: check: Warn about deprecated mod_posix
Matthew Wild <mwild1@gmail.com>
parents: 13581
diff changeset
641 if all_modules:contains("posix") then
d112eac6a3dc prosodyctl: check: Warn about deprecated mod_posix
Matthew Wild <mwild1@gmail.com>
parents: 13581
diff changeset
642 print("");
d112eac6a3dc prosodyctl: check: Warn about deprecated mod_posix
Matthew Wild <mwild1@gmail.com>
parents: 13581
diff changeset
643 print(" mod_posix is loaded in your configuration file, but it has");
d112eac6a3dc prosodyctl: check: Warn about deprecated mod_posix
Matthew Wild <mwild1@gmail.com>
parents: 13581
diff changeset
644 print(" been deprecated. You can safely remove it.");
d112eac6a3dc prosodyctl: check: Warn about deprecated mod_posix
Matthew Wild <mwild1@gmail.com>
parents: 13581
diff changeset
645 end
13841
d01cfbb7fc4f prosodyctl check config: add recommendation to switch from admin_telnet to shell
Matthew Wild <mwild1@gmail.com>
parents: 13830
diff changeset
646 if all_modules:contains("admin_telnet") then
d01cfbb7fc4f prosodyctl check config: add recommendation to switch from admin_telnet to shell
Matthew Wild <mwild1@gmail.com>
parents: 13830
diff changeset
647 print("");
d01cfbb7fc4f prosodyctl check config: add recommendation to switch from admin_telnet to shell
Matthew Wild <mwild1@gmail.com>
parents: 13830
diff changeset
648 print(" mod_admin_telnet is being replaced by mod_admin_shell (prosodyctl shell).");
d01cfbb7fc4f prosodyctl check config: add recommendation to switch from admin_telnet to shell
Matthew Wild <mwild1@gmail.com>
parents: 13830
diff changeset
649 print(" To update and ensure all commands are available, simply change \"admin_telnet\" to \"admin_shell\"");
d01cfbb7fc4f prosodyctl check config: add recommendation to switch from admin_telnet to shell
Matthew Wild <mwild1@gmail.com>
parents: 13830
diff changeset
650 print(" in your modules_enabled list.");
d01cfbb7fc4f prosodyctl check config: add recommendation to switch from admin_telnet to shell
Matthew Wild <mwild1@gmail.com>
parents: 13830
diff changeset
651 end
13690
d112eac6a3dc prosodyctl: check: Warn about deprecated mod_posix
Matthew Wild <mwild1@gmail.com>
parents: 13581
diff changeset
652
13830
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
653 local load_failures = {};
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
654 for mod_name in all_modules do
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
655 local mod, err = modulemanager.loader:load_resource(mod_name, nil);
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
656 if not mod then
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
657 load_failures[mod_name] = err;
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
658 end
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
659 end
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
660
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
661 if next(load_failures) ~= nil then
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
662 print("");
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
663 print(" The following modules failed to load:");
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
664 print("");
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
665 for mod_name, err in it.sorted_pairs(load_failures) do
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
666 print((" mod_%s: %s"):format(mod_name, err));
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
667 end
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
668 print("")
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
669 print(" Check for typos and remove any obsolete/incompatible modules from your config.");
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
670 end
145b71d1283c prosodyctl check config: List modules which Prosody cannot successfully load
Matthew Wild <mwild1@gmail.com>
parents: 13811
diff changeset
671
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
672 for host, host_config in pairs(config) do --luacheck: ignore 213/host
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
673 if type(rawget(host_config, "storage")) == "string" and rawget(host_config, "default_storage") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
674 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
675 print(" The 'default_storage' option is not needed if 'storage' is set to a string.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
676 break;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
677 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
678 end
13778
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
679
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
680 for host, host_config in pairs(config) do --luacheck: ignore 213/host
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
681 if type(rawget(host_config, "storage")) == "string" and rawget(host_config, "default_storage") then
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
682 print("");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
683 print(" The 'default_storage' option is not needed if 'storage' is set to a string.");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
684 break;
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
685 end
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
686 end
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
687
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
688 local require_encryption = set.intersection(all_options, set.new({
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
689 "require_encryption", "c2s_require_encryption", "s2s_require_encryption"
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
690 })):empty();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
691 local ssl = dependencies.softreq"ssl";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
692 if not ssl then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
693 if not require_encryption then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
694 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
695 print(" You require encryption but LuaSec is not available.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
696 print(" Connections will fail.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
697 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
698 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
699 elseif not ssl.loadcertificate then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
700 if all_options:contains("s2s_secure_auth") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
701 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
702 print(" You have set s2s_secure_auth but your version of LuaSec does ");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
703 print(" not support certificate validation, so all s2s connections will");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
704 print(" fail.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
705 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
706 elseif all_options:contains("s2s_secure_domains") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
707 local secure_domains = set.new();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
708 for host in enabled_hosts() do
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
709 if api(host):get_option_boolean("s2s_secure_auth") then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
710 secure_domains:add("*");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
711 else
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
712 secure_domains:include(api(host):get_option_set("s2s_secure_domains", {}));
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
713 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
714 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
715 if not secure_domains:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
716 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
717 print(" You have set s2s_secure_domains but your version of LuaSec does ");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
718 print(" not support certificate validation, so s2s connections to/from ");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
719 print(" these domains will fail.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
720 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
721 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
722 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
723 elseif require_encryption and not all_modules:contains("tls") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
724 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
725 print(" You require encryption but mod_tls is not enabled.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
726 print(" Connections will fail.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
727 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
728 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
729
12317
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
730 do
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
731 local registration_enabled_hosts = {};
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
732 for host in enabled_hosts() do
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
733 local host_modules, component = modulemanager.get_modules_for_host(host);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
734 local hostapi = api(host);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
735 local allow_registration = hostapi:get_option_boolean("allow_registration", false);
12317
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
736 local mod_register = host_modules:contains("register");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
737 local mod_register_ibr = host_modules:contains("register_ibr");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
738 local mod_invites_register = host_modules:contains("invites_register");
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
739 local registration_invite_only = hostapi:get_option_boolean("registration_invite_only", true);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
740 local is_vhost = not component;
12317
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
741 if is_vhost and (mod_register_ibr or (mod_register and allow_registration))
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
742 and not (mod_invites_register and registration_invite_only) then
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
743 table.insert(registration_enabled_hosts, host);
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
744 end
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
745 end
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
746 if #registration_enabled_hosts > 0 then
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
747 table.sort(registration_enabled_hosts);
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
748 print("");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
749 print(" Public registration is enabled on:");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
750 print(" "..table.concat(registration_enabled_hosts, ", "));
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
751 print("");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
752 print(" If this is intentional, review our guidelines on running a public server");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
753 print(" at https://prosody.im/doc/public_servers - otherwise, consider switching to");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
754 print(" invite-based registration, which is more secure.");
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
755 end
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
756 end
b4f2027ef917 util.prosodyctl: Warn about enabled public registration in 'check config'
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
757
12318
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
758 do
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
759 local orphan_components = {};
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
760 local referenced_components = set.new();
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
761 local enabled_hosts_set = set.new();
13778
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
762 local invalid_disco_items = {};
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
763 for host in it.filter("*", pairs(configmanager.getconfig())) do
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
764 local hostapi = api(host);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
765 if hostapi:get_option_boolean("enabled", true) then
12318
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
766 enabled_hosts_set:add(host);
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
767 for _, disco_item in ipairs(hostapi:get_option_array("disco_items", {})) do
13778
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
768 if type(disco_item[1]) == "string" then
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
769 referenced_components:add(disco_item[1]);
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
770 else
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
771 invalid_disco_items[host] = true;
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
772 end
12318
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
773 end
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
774 end
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
775 end
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
776 for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
777 local is_component = not not select(2, modulemanager.get_modules_for_host(host));
12318
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
778 if is_component then
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
779 local parent_domain = host:match("^[^.]+%.(.+)$");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
780 local is_orphan = not (enabled_hosts_set:contains(parent_domain) or referenced_components:contains(host));
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
781 if is_orphan then
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
782 table.insert(orphan_components, host);
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
783 end
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
784 end
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
785 end
13778
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
786
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
787 if next(invalid_disco_items) ~= nil then
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
788 print("");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
789 print(" Some hosts in your configuration file have an invalid 'disco_items' option.");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
790 print(" This may cause further errors, such as unreferenced components.");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
791 print("");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
792 for host in it.sorted_pairs(invalid_disco_items) do
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
793 print(" - "..host);
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
794 end
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
795 print("");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
796 end
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
797
12318
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
798 if #orphan_components > 0 then
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
799 table.sort(orphan_components);
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
800 print("");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
801 print(" Your configuration contains the following unreferenced components:\n");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
802 print(" "..table.concat(orphan_components, "\n "));
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
803 print("");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
804 print(" Clients may not be able to discover these services because they are not linked to");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
805 print(" any VirtualHost. They are automatically linked if they are direct subdomains of a");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
806 print(" VirtualHost. Alternatively, you can explicitly link them using the disco_items option.");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
807 print(" For more information see https://prosody.im/doc/modules/mod_disco#items");
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
808 end
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
809 end
239ce74aa6a4 util.prosodyctl: check: warn about unreferenced components, suggest disco_items
Matthew Wild <mwild1@gmail.com>
parents: 12317
diff changeset
810
13465
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
811 -- Check hostname validity
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
812 do
13466
5d9ec2e55d74 Merge 0.12->trunk
Matthew Wild <mwild1@gmail.com>
parents: 13327 13465
diff changeset
813 local idna = require "prosody.util.encodings".idna;
13465
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
814 local invalid_hosts = {};
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
815 local alabel_hosts = {};
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
816 for host in it.filter("*", pairs(configmanager.getconfig())) do
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
817 local _, h, _ = jid_split(host);
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
818 if not h or not idna.to_ascii(h) then
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
819 table.insert(invalid_hosts, host);
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
820 else
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
821 for label in h:gmatch("[^%.]+") do
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
822 if label:match("^xn%-%-") then
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
823 table.insert(alabel_hosts, host);
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
824 break;
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
825 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
826 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
827 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
828 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
829
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
830 if #invalid_hosts > 0 then
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
831 table.sort(invalid_hosts);
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
832 print("");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
833 print(" Your configuration contains invalid host names:");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
834 print(" "..table.concat(invalid_hosts, "\n "));
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
835 print("");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
836 print(" Clients may not be able to log in to these hosts, or you may not be able to");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
837 print(" communicate with remote servers.");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
838 print(" Use a valid domain name to correct this issue.");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
839 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
840
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
841 if #alabel_hosts > 0 then
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
842 table.sort(alabel_hosts);
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
843 print("");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
844 print(" Your configuration contains incorrectly-encoded hostnames:");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
845 for _, ahost in ipairs(alabel_hosts) do
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
846 print((" '%s' (should be '%s')"):format(ahost, idna.to_unicode(ahost)));
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
847 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
848 print("");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
849 print(" Clients may not be able to log in to these hosts, or you may not be able to");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
850 print(" communicate with remote servers.");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
851 print(" To correct this issue, use the Unicode version of the domain in Prosody's config file.");
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
852 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
853
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
854 if #invalid_hosts > 0 or #alabel_hosts > 0 then
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
855 print("");
13705
5f1eb8b14923 prosodyctl: check: Fix indentation in warning message
Matthew Wild <mwild1@gmail.com>
parents: 13690
diff changeset
856 print(" WARNING: Changing the name of a VirtualHost in Prosody's config file");
5f1eb8b14923 prosodyctl: check: Fix indentation in warning message
Matthew Wild <mwild1@gmail.com>
parents: 13690
diff changeset
857 print(" WILL NOT migrate any existing data (user accounts, etc.) to the new name.");
13465
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
858 ok = false;
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
859 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
860 end
54a936345aaa prosodyctl check: Warn about invalid domain names in the config file
Matthew Wild <mwild1@gmail.com>
parents: 13254
diff changeset
861
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
862 -- Check features
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
863 do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
864 local missing_features = {};
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
865 for host in enabled_user_hosts() do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
866 local all_features = checks.features(host, true);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
867 if not all_features then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
868 table.insert(missing_features, host);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
869 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
870 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
871 if #missing_features > 0 then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
872 print("");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
873 print(" Some of your hosts may be missing features due to a lack of configuration.");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
874 print(" For more details, use the 'prosodyctl check features' command.");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
875 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
876 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
877
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
878 print("Done.\n");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
879 end
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
880 function checks.dns()
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
881 local dns = require "prosody.net.dns";
10971
3cdb4a7cb406 util.prosodyctl.check: Use net.unbound for DNS if available
Kim Alvefur <zash@zash.se>
parents: 10932
diff changeset
882 pcall(function ()
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
883 local unbound = require"prosody.net.unbound";
11645
3be346c5b940 util.prosodyctl.check: Reload unbound to ensure hosts.txt is ignored
Kim Alvefur <zash@zash.se>
parents: 11635
diff changeset
884 dns = unbound.dns;
10971
3cdb4a7cb406 util.prosodyctl.check: Use net.unbound for DNS if available
Kim Alvefur <zash@zash.se>
parents: 10932
diff changeset
885 end)
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
886 local idna = require "prosody.util.encodings".idna;
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
887 local ip = require "prosody.util.ip";
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
888 local global = api("*");
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
889 local c2s_ports = global:get_option_set("c2s_ports", {5222});
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
890 local s2s_ports = global:get_option_set("s2s_ports", {5269});
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
891 local c2s_tls_ports = global:get_option_set("c2s_direct_tls_ports", {});
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
892 local s2s_tls_ports = global:get_option_set("s2s_direct_tls_ports", {});
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
893
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
894 local global_enabled = set.new();
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
895 for host in enabled_hosts() do
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
896 global_enabled:include(modulemanager.get_modules_for_host(host));
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
897 end
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
898 if global_enabled:contains("net_multiplex") then
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
899 local multiplex_ports = global:get_option_set("ports", {});
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
900 local multiplex_tls_ports = global:get_option_set("ssl_ports", {});
12230
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
901 if not multiplex_ports:empty() then
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
902 c2s_ports = c2s_ports + multiplex_ports;
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
903 s2s_ports = s2s_ports + multiplex_ports;
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
904 end
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
905 if not multiplex_tls_ports:empty() then
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
906 c2s_tls_ports = c2s_tls_ports + multiplex_tls_ports;
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
907 s2s_tls_ports = s2s_tls_ports + multiplex_tls_ports;
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
908 end
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
909 end
f590058d8d99 util.prosodyctl.check: Include multiplexed ports in DNS checks #1704
Kim Alvefur <zash@zash.se>
parents: 12218
diff changeset
910
11776
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
911 local c2s_srv_required, s2s_srv_required, c2s_tls_srv_required, s2s_tls_srv_required;
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
912 if not c2s_ports:contains(5222) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
913 c2s_srv_required = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
914 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
915 if not s2s_ports:contains(5269) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
916 s2s_srv_required = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
917 end
11615
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
918 if not c2s_tls_ports:empty() then
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
919 c2s_tls_srv_required = true;
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
920 end
11776
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
921 if not s2s_tls_ports:empty() then
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
922 s2s_tls_srv_required = true;
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
923 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
924
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
925 local problem_hosts = set.new();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
926
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
927 local external_addresses, internal_addresses = set.new(), set.new();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
928
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
929 local fqdn = socket.dns.tohostname(socket.dns.gethostname());
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
930 if fqdn then
13121
332e95f75dbb util.prosodyctl.check: Fix error where hostname can't be turned into A label
Kim Alvefur <zash@zash.se>
parents: 12898
diff changeset
931 local fqdn_a = idna.to_ascii(fqdn);
332e95f75dbb util.prosodyctl.check: Fix error where hostname can't be turned into A label
Kim Alvefur <zash@zash.se>
parents: 12898
diff changeset
932 if fqdn_a then
332e95f75dbb util.prosodyctl.check: Fix error where hostname can't be turned into A label
Kim Alvefur <zash@zash.se>
parents: 12898
diff changeset
933 local res = dns.lookup(fqdn_a, "A");
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
934 if res then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
935 for _, record in ipairs(res) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
936 external_addresses:add(record.a);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
937 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
938 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
939 end
13121
332e95f75dbb util.prosodyctl.check: Fix error where hostname can't be turned into A label
Kim Alvefur <zash@zash.se>
parents: 12898
diff changeset
940 if fqdn_a then
332e95f75dbb util.prosodyctl.check: Fix error where hostname can't be turned into A label
Kim Alvefur <zash@zash.se>
parents: 12898
diff changeset
941 local res = dns.lookup(fqdn_a, "AAAA");
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
942 if res then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
943 for _, record in ipairs(res) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
944 external_addresses:add(record.aaaa);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
945 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
946 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
947 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
948 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
949
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
950 local local_addresses = require"prosody.util.net".local_addresses() or {};
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
951
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
952 for addr in it.values(local_addresses) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
953 if not ip.new_ip(addr).private then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
954 external_addresses:add(addr);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
955 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
956 internal_addresses:add(addr);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
957 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
958 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
959
12320
f0be98bab9dd prosodyctl: check dns: Allow admin to specify undiscoverable external IPs in config
Matthew Wild <mwild1@gmail.com>
parents: 12319
diff changeset
960 -- Allow admin to specify additional (e.g. undiscoverable) IP addresses in the config
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
961 for _, address in ipairs(global:get_option_array("external_addresses", {})) do
12320
f0be98bab9dd prosodyctl: check dns: Allow admin to specify undiscoverable external IPs in config
Matthew Wild <mwild1@gmail.com>
parents: 12319
diff changeset
962 external_addresses:add(address);
f0be98bab9dd prosodyctl: check dns: Allow admin to specify undiscoverable external IPs in config
Matthew Wild <mwild1@gmail.com>
parents: 12319
diff changeset
963 end
f0be98bab9dd prosodyctl: check dns: Allow admin to specify undiscoverable external IPs in config
Matthew Wild <mwild1@gmail.com>
parents: 12319
diff changeset
964
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
965 if external_addresses:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
966 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
967 print(" Failed to determine the external addresses of this server. Checks may be inaccurate.");
13219
22763b30e458 util.prosodyctl.check: Hint about the 'external_addresses' config option
Kim Alvefur <zash@zash.se>
parents: 13217
diff changeset
968 print(" If you know the correct external addresses you can specify them in the config like:")
22763b30e458 util.prosodyctl.check: Hint about the 'external_addresses' config option
Kim Alvefur <zash@zash.se>
parents: 13217
diff changeset
969 print(" external_addresses = { \"192.0.2.34\", \"2001:db8::abcd:1234\" }")
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
970 c2s_srv_required, s2s_srv_required = true, true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
971 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
972
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
973 local v6_supported = not not socket.tcp6;
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
974 local use_ipv4 = global:get_option_boolean("use_ipv4", true);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
975 local use_ipv6 = global:get_option_boolean("use_ipv6", true);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
976
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
977 local function trim_dns_name(n)
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
978 return (n:gsub("%.$", ""));
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
979 end
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
980
12319
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
981 local unknown_addresses = set.new();
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
982
13708
9f8e9aabc00b prosodyctl: check: Skip DNS checks for known invalid domains (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents: 13707
diff changeset
983 local function is_valid_domain(domain)
9f8e9aabc00b prosodyctl: check: Skip DNS checks for known invalid domains (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents: 13707
diff changeset
984 return idna.to_ascii(domain) ~= nil;
9f8e9aabc00b prosodyctl: check: Skip DNS checks for known invalid domains (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents: 13707
diff changeset
985 end
9f8e9aabc00b prosodyctl: check: Skip DNS checks for known invalid domains (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents: 13707
diff changeset
986
9f8e9aabc00b prosodyctl: check: Skip DNS checks for known invalid domains (fixes traceback)
Matthew Wild <mwild1@gmail.com>
parents: 13707
diff changeset
987 for jid in it.filter(is_valid_domain, enabled_hosts()) do
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
988 local all_targets_ok, some_targets_ok = true, false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
989 local node, host = jid_split(jid);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
990
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
991 local modules, component_module = modulemanager.get_modules_for_host(host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
992 if component_module then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
993 modules:add(component_module);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
994 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
995
12842
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
996 -- TODO Refactor these DNS SRV checks since they are very similar
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
997 -- FIXME Suggest concrete actionable steps to correct issues so that
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
998 -- users don't have to copy-paste the message into the support chat and
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
999 -- ask what to do about it.
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1000 local is_component = not not component_module;
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1001 print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."...");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1002 if node then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1003 print("Only the domain part ("..host..") is used in DNS.")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1004 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1005 local target_hosts = set.new();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1006 if modules:contains("c2s") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1007 local res = dns.lookup("_xmpp-client._tcp."..idna.to_ascii(host)..".", "SRV");
11613
c8a9f77d48fd util.prosodyctl.check: Fix for net.dns vs unbound API difference
Kim Alvefur <zash@zash.se>
parents: 11612
diff changeset
1008 if res and #res > 0 then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1009 for _, record in ipairs(res) do
10932
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1010 if record.srv.target == "." then -- TODO is this an error if mod_c2s is enabled?
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1011 print(" 'xmpp-client' service disabled by pointing to '.'"); -- FIXME Explain better what this is
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1012 break;
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1013 end
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1014 local target = trim_dns_name(record.srv.target);
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1015 target_hosts:add(target);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1016 if not c2s_ports:contains(record.srv.port) then
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1017 print(" SRV target "..target.." contains unknown client port: "..record.srv.port);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1018 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1019 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1020 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1021 if c2s_srv_required then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1022 print(" No _xmpp-client SRV record found for "..host..", but it looks like you need one.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1023 all_targets_ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1024 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1025 target_hosts:add(host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1026 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1027 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1028 end
12842
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
1029 if modules:contains("c2s") then
11615
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1030 local res = dns.lookup("_xmpps-client._tcp."..idna.to_ascii(host)..".", "SRV");
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1031 if res and #res > 0 then
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1032 for _, record in ipairs(res) do
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1033 if record.srv.target == "." then -- TODO is this an error if mod_c2s is enabled?
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1034 print(" 'xmpps-client' service disabled by pointing to '.'"); -- FIXME Explain better what this is
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1035 break;
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1036 end
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1037 local target = trim_dns_name(record.srv.target);
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1038 target_hosts:add(target);
11615
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1039 if not c2s_tls_ports:contains(record.srv.port) then
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1040 print(" SRV target "..target.." contains unknown Direct TLS client port: "..record.srv.port);
11615
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1041 end
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1042 end
12842
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
1043 elseif c2s_tls_srv_required then
11615
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1044 print(" No _xmpps-client SRV record found for "..host..", but it looks like you need one.");
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1045 all_targets_ok = false;
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1046 end
8e16fd976c57 util.prosodyctl.check: Add support for checking Direct TLS SRV records
Kim Alvefur <zash@zash.se>
parents: 11613
diff changeset
1047 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1048 if modules:contains("s2s") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1049 local res = dns.lookup("_xmpp-server._tcp."..idna.to_ascii(host)..".", "SRV");
11613
c8a9f77d48fd util.prosodyctl.check: Fix for net.dns vs unbound API difference
Kim Alvefur <zash@zash.se>
parents: 11612
diff changeset
1050 if res and #res > 0 then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1051 for _, record in ipairs(res) do
10932
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1052 if record.srv.target == "." then -- TODO Is this an error if mod_s2s is enabled?
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1053 print(" 'xmpp-server' service disabled by pointing to '.'"); -- FIXME Explain better what this is
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1054 break;
ea4a7619058f util.prosodyctl.check: Fix traceback by handling SRV '.' target to
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
1055 end
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1056 local target = trim_dns_name(record.srv.target);
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1057 target_hosts:add(target);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1058 if not s2s_ports:contains(record.srv.port) then
11655
bbf50525faa5 util.prosodyctl.check: Normalize away trailing dot in some messages too
Kim Alvefur <zash@zash.se>
parents: 11654
diff changeset
1059 print(" SRV target "..target.." contains unknown server port: "..record.srv.port);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1060 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1061 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1062 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1063 if s2s_srv_required then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1064 print(" No _xmpp-server SRV record found for "..host..", but it looks like you need one.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1065 all_targets_ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1066 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1067 target_hosts:add(host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1068 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1069 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1070 end
12842
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
1071 if modules:contains("s2s") then
11776
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1072 local res = dns.lookup("_xmpps-server._tcp."..idna.to_ascii(host)..".", "SRV");
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1073 if res and #res > 0 then
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1074 for _, record in ipairs(res) do
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1075 if record.srv.target == "." then -- TODO is this an error if mod_s2s is enabled?
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1076 print(" 'xmpps-server' service disabled by pointing to '.'"); -- FIXME Explain better what this is
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1077 break;
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1078 end
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1079 local target = trim_dns_name(record.srv.target);
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1080 target_hosts:add(target);
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1081 if not s2s_tls_ports:contains(record.srv.port) then
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1082 print(" SRV target "..target.." contains unknown Direct TLS server port: "..record.srv.port);
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1083 end
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1084 end
12842
3edd39c55a8a prosodyctl check dns: Check for Direct TLS SRV records even if not configured (fix #1793)
Kim Alvefur <zash@zash.se>
parents: 12520
diff changeset
1085 elseif s2s_tls_srv_required then
11776
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1086 print(" No _xmpps-server SRV record found for "..host..", but it looks like you need one.");
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1087 all_targets_ok = false;
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1088 end
1132a1f1ca5a util.prosodyctl.check: Check for server-to-server Direct TLS records
Kim Alvefur <zash@zash.se>
parents: 11655
diff changeset
1089 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1090 if target_hosts:empty() then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1091 target_hosts:add(host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1092 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1093
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1094 if target_hosts:contains("localhost") then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1095 print(" Target 'localhost' cannot be accessed from other servers");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1096 target_hosts:remove("localhost");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1097 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1098
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1099 local function check_address(target)
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1100 local A, AAAA = dns.lookup(idna.to_ascii(target), "A"), dns.lookup(idna.to_ascii(target), "AAAA");
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1101 local prob = {};
12231
ca8453129ade util.prosodyctl.check: Fix A/AAAA check for proxy65 and http
Kim Alvefur <zash@zash.se>
parents: 12230
diff changeset
1102 if use_ipv4 and not (A and #A > 0) then table.insert(prob, "A"); end
ca8453129ade util.prosodyctl.check: Fix A/AAAA check for proxy65 and http
Kim Alvefur <zash@zash.se>
parents: 12230
diff changeset
1103 if use_ipv6 and not (AAAA and #AAAA > 0) then table.insert(prob, "AAAA"); end
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1104 return prob;
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1105 end
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1106
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1107 if modules:contains("proxy65") then
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1108 local proxy65_target = api(host):get_option_string("proxy65_address", host);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1109 if type(proxy65_target) == "string" then
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1110 local prob = check_address(proxy65_target);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1111 if #prob > 0 then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1112 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1113 .." record. Create one or set 'proxy65_address' to the correct host/IP.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1114 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1115 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1116 print(" proxy65_address for "..host.." should be set to a string, unable to perform DNS check");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1117 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1118 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1119
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1120 local known_http_modules = set.new { "bosh"; "http_files"; "http_file_share"; "http_openmetrics"; "websocket" };
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1121
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1122 if modules:contains("http") or not set.intersection(modules, known_http_modules):empty()
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1123 or contains_match(modules, "^http_") or contains_match(modules, "_web$") then
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1124
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1125 local http_host = api(host):get_option_string("http_host", host);
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1126 local http_internal_host = http_host;
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1127 local http_url = api(host):get_option_string("http_external_url");
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1128 if http_url then
12218
0795e1ccf3d8 util.prosodyctl.check: Fix use of LuaSocket URL parser
Kim Alvefur <zash@zash.se>
parents: 12217
diff changeset
1129 local url_parse = require "socket.url".parse;
12217
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1130 local external_url_parts = url_parse(http_url);
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1131 if external_url_parts then
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1132 http_host = external_url_parts.host;
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1133 else
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1134 print(" The 'http_external_url' setting is not a valid URL");
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1135 end
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1136 end
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1137
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1138 local prob = check_address(http_host);
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1139 if #prob > 1 then
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1140 print(" HTTP service " .. http_host .. " has no " .. table.concat(prob, "/") .. " record. Create one or change "
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1141 .. (http_url and "'http_external_url'" or "'http_host'").." to the correct host.");
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1142 end
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1143
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1144 if http_host ~= http_internal_host then
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1145 print(" Ensure the reverse proxy sets the HTTP Host header to '" .. http_internal_host .. "'");
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1146 end
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1147 end
39043233de04 util.prosodyctl.check: Add HTTP related DNS checks
Kim Alvefur <zash@zash.se>
parents: 12159
diff changeset
1148
11652
887d7b15e21b util.prosodyctl.check: Warn if both use_ipv4 and use_ipv6 are set to false
Kim Alvefur <zash@zash.se>
parents: 11651
diff changeset
1149 if not use_ipv4 and not use_ipv6 then
887d7b15e21b util.prosodyctl.check: Warn if both use_ipv4 and use_ipv6 are set to false
Kim Alvefur <zash@zash.se>
parents: 11651
diff changeset
1150 print(" Both IPv6 and IPv4 are disabled, Prosody will not listen on any ports");
887d7b15e21b util.prosodyctl.check: Warn if both use_ipv4 and use_ipv6 are set to false
Kim Alvefur <zash@zash.se>
parents: 11651
diff changeset
1151 print(" nor be able to connect to any remote servers.");
887d7b15e21b util.prosodyctl.check: Warn if both use_ipv4 and use_ipv6 are set to false
Kim Alvefur <zash@zash.se>
parents: 11651
diff changeset
1152 all_targets_ok = false;
887d7b15e21b util.prosodyctl.check: Warn if both use_ipv4 and use_ipv6 are set to false
Kim Alvefur <zash@zash.se>
parents: 11651
diff changeset
1153 end
887d7b15e21b util.prosodyctl.check: Warn if both use_ipv4 and use_ipv6 are set to false
Kim Alvefur <zash@zash.se>
parents: 11651
diff changeset
1154
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1155 for target_host in target_hosts do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1156 local host_ok_v4, host_ok_v6;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1157 do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1158 local res = dns.lookup(idna.to_ascii(target_host), "A");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1159 if res then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1160 for _, record in ipairs(res) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1161 if external_addresses:contains(record.a) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1162 some_targets_ok = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1163 host_ok_v4 = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1164 elseif internal_addresses:contains(record.a) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1165 host_ok_v4 = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1166 some_targets_ok = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1167 print(" "..target_host.." A record points to internal address, external connections might fail");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1168 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1169 print(" "..target_host.." A record points to unknown address "..record.a);
12319
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1170 unknown_addresses:add(record.a);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1171 all_targets_ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1172 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1173 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1174 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1175 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1176 do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1177 local res = dns.lookup(idna.to_ascii(target_host), "AAAA");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1178 if res then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1179 for _, record in ipairs(res) do
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1180 if external_addresses:contains(record.aaaa) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1181 some_targets_ok = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1182 host_ok_v6 = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1183 elseif internal_addresses:contains(record.aaaa) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1184 host_ok_v6 = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1185 some_targets_ok = true;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1186 print(" "..target_host.." AAAA record points to internal address, external connections might fail");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1187 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1188 print(" "..target_host.." AAAA record points to unknown address "..record.aaaa);
12319
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1189 unknown_addresses:add(record.aaaa);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1190 all_targets_ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1191 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1192 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1193 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1194 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1195
11653
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1196 if host_ok_v4 and not use_ipv4 then
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1197 print(" Host "..target_host.." does seem to resolve to this server but IPv4 has been disabled");
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1198 all_targets_ok = false;
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1199 end
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1200
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1201 if host_ok_v6 and not use_ipv6 then
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1202 print(" Host "..target_host.." does seem to resolve to this server but IPv6 has been disabled");
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1203 all_targets_ok = false;
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1204 end
51141309ffc4 util.prosodyctl.check: Point out if A/AAAA exists despite disabled IPvX
Kim Alvefur <zash@zash.se>
parents: 11652
diff changeset
1205
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1206 local bad_protos = {}
11651
c9f46d28ed7e util.prosodyctl.check: Silence IP protocol mismatches when disabled
Kim Alvefur <zash@zash.se>
parents: 11645
diff changeset
1207 if use_ipv4 and not host_ok_v4 then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1208 table.insert(bad_protos, "IPv4");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1209 end
11651
c9f46d28ed7e util.prosodyctl.check: Silence IP protocol mismatches when disabled
Kim Alvefur <zash@zash.se>
parents: 11645
diff changeset
1210 if use_ipv6 and not host_ok_v6 then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1211 table.insert(bad_protos, "IPv6");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1212 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1213 if #bad_protos > 0 then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1214 print(" Host "..target_host.." does not seem to resolve to this server ("..table.concat(bad_protos, "/")..")");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1215 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1216 if host_ok_v6 and not v6_supported then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1217 print(" Host "..target_host.." has AAAA records, but your version of LuaSocket does not support IPv6.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1218 print(" Please see https://prosody.im/doc/ipv6 for more information.");
11925
3e0d03a74285 util.prosodyctl.check: Highlight inconsistency of AAAA records and use_ipv6=false
Kim Alvefur <zash@zash.se>
parents: 11924
diff changeset
1219 elseif host_ok_v6 and not use_ipv6 then
3e0d03a74285 util.prosodyctl.check: Highlight inconsistency of AAAA records and use_ipv6=false
Kim Alvefur <zash@zash.se>
parents: 11924
diff changeset
1220 print(" Host "..target_host.." has AAAA records, but IPv6 is disabled.");
3e0d03a74285 util.prosodyctl.check: Highlight inconsistency of AAAA records and use_ipv6=false
Kim Alvefur <zash@zash.se>
parents: 11924
diff changeset
1221 -- TODO Tell them to drop the AAAA records or enable IPv6?
3e0d03a74285 util.prosodyctl.check: Highlight inconsistency of AAAA records and use_ipv6=false
Kim Alvefur <zash@zash.se>
parents: 11924
diff changeset
1222 print(" Please see https://prosody.im/doc/ipv6 for more information.");
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1223 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1224 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1225 if not all_targets_ok then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1226 print(" "..(some_targets_ok and "Only some" or "No").." targets for "..host.." appear to resolve to this server.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1227 if is_component then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1228 print(" DNS records are necessary if you want users on other servers to access this component.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1229 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1230 problem_hosts:add(host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1231 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1232 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1233 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1234 if not problem_hosts:empty() then
12319
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1235 if not unknown_addresses:empty() then
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1236 print("");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1237 print("Some of your DNS records point to unknown IP addresses. This may be expected if your server");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1238 print("is behind a NAT or proxy. The unrecognized addresses were:");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1239 print("");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1240 print(" Unrecognized: "..tostring(unknown_addresses));
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1241 print("");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1242 print("The addresses we found on this system are:");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1243 print("");
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1244 print(" Internal: "..tostring(internal_addresses));
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1245 print(" External: "..tostring(external_addresses));
13219
22763b30e458 util.prosodyctl.check: Hint about the 'external_addresses' config option
Kim Alvefur <zash@zash.se>
parents: 13217
diff changeset
1246 print("")
22763b30e458 util.prosodyctl.check: Hint about the 'external_addresses' config option
Kim Alvefur <zash@zash.se>
parents: 13217
diff changeset
1247 print("If the list of external external addresses is incorrect you can specify correct addresses in the config:")
22763b30e458 util.prosodyctl.check: Hint about the 'external_addresses' config option
Kim Alvefur <zash@zash.se>
parents: 13217
diff changeset
1248 print(" external_addresses = { \"192.0.2.34\", \"2001:db8::abcd:1234\" }")
12319
8fc3c06f922d prosodyctl: check dns: List discovered addresses for diagnostic purposes
Matthew Wild <mwild1@gmail.com>
parents: 12318
diff changeset
1249 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1250 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1251 print("For more information about DNS configuration please see https://prosody.im/doc/dns");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1252 print("");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1253 ok = false;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1254 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1255 end
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1256 function checks.certs()
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1257 local cert_ok;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1258 print"Checking certificates..."
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
1259 local x509_verify_identity = require"prosody.util.x509".verify_identity;
13302
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1260 local use_dane = configmanager.get("*", "use_dane");
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1261 local pem2der = require"prosody.util.x509".pem2der;
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1262 local sha256 = require"prosody.util.hashes".sha256;
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12899
diff changeset
1263 local create_context = require "prosody.core.certmanager".create_context;
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1264 local ssl = dependencies.softreq"ssl";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1265 -- local datetime_parse = require"util.datetime".parse_x509;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1266 local load_cert = ssl and ssl.loadcertificate;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1267 -- or ssl.cert_from_pem
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1268 if not ssl then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1269 print("LuaSec not available, can't perform certificate checks")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1270 if what == "certs" then cert_ok = false end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1271 elseif not load_cert then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1272 print("This version of LuaSec (" .. ssl._VERSION .. ") does not support certificate checking");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1273 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1274 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1275 for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do
13324
6f371066d6e0 util.prosodyctl.check: Simplify conditions for c2s and s2s cert checks
Kim Alvefur <zash@zash.se>
parents: 13316
diff changeset
1276 local modules = modulemanager.get_modules_for_host(host);
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1277 print("Checking certificate for "..host);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1278 -- First, let's find out what certificate this host uses.
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1279 local host_ssl_config = configmanager.rawget(host, "ssl")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1280 or configmanager.rawget(host:match("%.(.*)"), "ssl");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1281 local global_ssl_config = configmanager.rawget("*", "ssl");
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1282 local ctx_ok, err, ssl_config = create_context(host, "server", host_ssl_config, global_ssl_config);
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1283 if not ctx_ok then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1284 print(" Error: "..err);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1285 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1286 elseif not ssl_config.certificate then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1287 print(" No 'certificate' found for "..host)
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1288 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1289 elseif not ssl_config.key then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1290 print(" No 'key' found for "..host)
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1291 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1292 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1293 local key, err = io.open(ssl_config.key); -- Permissions check only
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1294 if not key then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1295 print(" Could not open "..ssl_config.key..": "..err);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1296 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1297 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1298 key:close();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1299 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1300 local cert_fh, err = io.open(ssl_config.certificate); -- Load the file.
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1301 if not cert_fh then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1302 print(" Could not open "..ssl_config.certificate..": "..err);
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1303 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1304 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1305 print(" Certificate: "..ssl_config.certificate)
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1306 local cert = load_cert(cert_fh:read"*a"); cert_fh:close();
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1307 if not cert:validat(os.time()) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1308 print(" Certificate has expired.")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1309 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1310 elseif not cert:validat(os.time() + 86400) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1311 print(" Certificate expires within one day.")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1312 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1313 elseif not cert:validat(os.time() + 86400*7) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1314 print(" Certificate expires within one week.")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1315 elseif not cert:validat(os.time() + 86400*31) then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1316 print(" Certificate expires within one month.")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1317 end
13324
6f371066d6e0 util.prosodyctl.check: Simplify conditions for c2s and s2s cert checks
Kim Alvefur <zash@zash.se>
parents: 13316
diff changeset
1318 if modules:contains("c2s") and not x509_verify_identity(host, "_xmpp-client", cert) then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1319 print(" Not valid for client connections to "..host..".")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1320 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1321 end
13325
f32faaea3461 util.prosodyctl.check: Update conditions for s2s cert checks
Kim Alvefur <zash@zash.se>
parents: 13324
diff changeset
1322 local anon = api(host):get_option_string("authentication", "internal_hashed") == "anonymous";
f32faaea3461 util.prosodyctl.check: Update conditions for s2s cert checks
Kim Alvefur <zash@zash.se>
parents: 13324
diff changeset
1323 local anon_s2s = api(host):get_option_boolean("allow_anonymous_s2s", false);
f32faaea3461 util.prosodyctl.check: Update conditions for s2s cert checks
Kim Alvefur <zash@zash.se>
parents: 13324
diff changeset
1324 if modules:contains("s2s") and (anon_s2s or not anon) and not x509_verify_identity(host, "_xmpp-server", cert) then
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1325 print(" Not valid for server-to-server connections to "..host..".")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1326 cert_ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1327 end
13326
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1328
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1329 local known_http_modules = set.new { "bosh"; "http_files"; "http_file_share"; "http_openmetrics"; "websocket" };
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1330 local http_loaded = modules:contains("http")
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1331 or not set.intersection(modules, known_http_modules):empty()
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1332 or contains_match(modules, "^http_")
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1333 or contains_match(modules, "_web$");
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1334
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1335 local http_host = api(host):get_option_string("http_host", host);
13327
f0fc6e7cc4de util.prosodyctl.check: Disable https cert check if http_external_url set
Kim Alvefur <zash@zash.se>
parents: 13326
diff changeset
1336 if api(host):get_option_string("http_external_url") then
f0fc6e7cc4de util.prosodyctl.check: Disable https cert check if http_external_url set
Kim Alvefur <zash@zash.se>
parents: 13326
diff changeset
1337 -- Assumed behind a reverse proxy
f0fc6e7cc4de util.prosodyctl.check: Disable https cert check if http_external_url set
Kim Alvefur <zash@zash.se>
parents: 13326
diff changeset
1338 http_loaded = false;
f0fc6e7cc4de util.prosodyctl.check: Disable https cert check if http_external_url set
Kim Alvefur <zash@zash.se>
parents: 13326
diff changeset
1339 end
13326
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1340 if http_loaded and not x509_verify_identity(http_host, nil, cert) then
13811
83478fc0806b prosodyctl check certs: Use correct hostname in warning message about HTTPS
Matthew Wild <mwild1@gmail.com>
parents: 13778
diff changeset
1341 print(" Not valid for HTTPS connections to "..http_host..".")
13326
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1342 cert_ok = false
76b6556c0f67 util.prosodyctl.check: Check cert for HTTPS if http module enabled
Kim Alvefur <zash@zash.se>
parents: 13325
diff changeset
1343 end
13302
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1344 if use_dane then
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1345 if cert.pubkey then
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1346 print(" DANE: TLSA 3 1 1 "..sha256(pem2der(cert:pubkey()), true))
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1347 elseif cert.pem then
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1348 print(" DANE: TLSA 3 0 1 "..sha256(pem2der(cert:pem()), true))
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1349 end
30b7cd40ee14 util.prosodyctl.check: Print DANE TLSA records for certificates
Kim Alvefur <zash@zash.se>
parents: 13301
diff changeset
1350 end
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1351 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1352 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1353 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1354 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1355 if cert_ok == false then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1356 print("")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1357 print("For more information about certificates please see https://prosody.im/doc/certificates");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1358 ok = false
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1359 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1360 print("")
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1361 end
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1362 -- intentionally not doing this by default
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1363 function checks.connectivity()
11782
d93107de52dd util.prosodyctl.check: Ignore unused "ok" variable [luacheck]
Kim Alvefur <zash@zash.se>
parents: 11780
diff changeset
1364 local _, prosody_is_running = is_prosody_running();
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1365 if api("*"):get_option_string("pidfile") and not prosody_is_running then
11780
98ae95235775 util.prosodyctl.check: Refuse to do ojn test unless prosody is running
Kim Alvefur <zash@zash.se>
parents: 11779
diff changeset
1366 print("Prosody does not appear to be running, which is required for this test.");
98ae95235775 util.prosodyctl.check: Refuse to do ojn test unless prosody is running
Kim Alvefur <zash@zash.se>
parents: 11779
diff changeset
1367 print("Start it and then try again.");
98ae95235775 util.prosodyctl.check: Refuse to do ojn test unless prosody is running
Kim Alvefur <zash@zash.se>
parents: 11779
diff changeset
1368 return 1;
98ae95235775 util.prosodyctl.check: Refuse to do ojn test unless prosody is running
Kim Alvefur <zash@zash.se>
parents: 11779
diff changeset
1369 end
98ae95235775 util.prosodyctl.check: Refuse to do ojn test unless prosody is running
Kim Alvefur <zash@zash.se>
parents: 11779
diff changeset
1370
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1371 local checker = "observe.jabber.network";
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1372 local probe_instance;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1373 local probe_modules = {
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1374 ["xmpp-client"] = "c2s_normal_auth";
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1375 ["xmpp-server"] = "s2s_normal";
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1376 ["xmpps-client"] = nil; -- TODO
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1377 ["xmpps-server"] = nil; -- TODO
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1378 };
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1379 local probe_settings = api("*"):get_option_string("connectivity_probe");
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1380 if type(probe_settings) == "string" then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1381 probe_instance = probe_settings;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1382 elseif type(probe_settings) == "table" and type(probe_settings.url) == "string" then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1383 probe_instance = probe_settings.url;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1384 if type(probe_settings.modules) == "table" then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1385 probe_modules = probe_settings.modules;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1386 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1387 elseif probe_settings ~= nil then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1388 print("The 'connectivity_probe' setting not understood.");
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1389 print("Expected an URL or a table with 'url' and 'modules' fields");
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1390 print("See https://prosody.im/doc/prosodyctl#check for more information."); -- FIXME
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1391 return 1;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1392 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1393
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1394 local check_api;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1395 if probe_instance then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1396 local parsed_url = socket_url.parse(probe_instance);
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1397 if not parsed_url then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1398 print(("'connectivity_probe' is not a valid URL: %q"):format(probe_instance));
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1399 print("Set it to the URL of an XMPP Blackbox Exporter instance and try again");
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1400 return 1;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1401 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1402 checker = parsed_url.host;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1403
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1404 function check_api(protocol, host)
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1405 local target = socket_url.build({scheme="xmpp",path=host});
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1406 local probe_module = probe_modules[protocol];
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1407 if not probe_module then
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1408 return nil, "Checking protocol '"..protocol.."' is currently unsupported";
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1409 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1410 return check_probe(probe_instance, probe_module, target);
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1411 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1412 else
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1413 check_api = check_ojn;
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1414 end
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1415
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1416 for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1417 local modules, component_module = modulemanager.get_modules_for_host(host);
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1418 if component_module then
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1419 modules:add(component_module)
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1420 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1421
11827
2359519260ec prosodyctl: Add alternate XMPP Blackbox Exporter connectivity check
Kim Alvefur <zash@zash.se>
parents: 11826
diff changeset
1422 print("Checking external connectivity for "..host.." via "..checker)
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1423 local function check_connectivity(protocol)
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1424 local success, err = check_api(protocol, host);
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1425 if not success and err ~= nil then
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1426 print((" %s: Failed to request check at API: %s"):format(protocol, err))
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1427 elseif success then
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1428 print((" %s: Works"):format(protocol))
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1429 else
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1430 print((" %s: Check service failed to establish (secure) connection"):format(protocol))
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1431 ok = false
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1432 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1433 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1434
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1435 if modules:contains("c2s") then
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1436 check_connectivity("xmpp-client")
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1437 if not api("*"):get_option_set("c2s_direct_tls_ports", {}):empty() then
11957
3a7ce7df7806 util.prosodyctl.check: Support direct TLS connectivity checks
Kim Alvefur <zash@zash.se>
parents: 11940
diff changeset
1438 check_connectivity("xmpps-client");
3a7ce7df7806 util.prosodyctl.check: Support direct TLS connectivity checks
Kim Alvefur <zash@zash.se>
parents: 11940
diff changeset
1439 end
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1440 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1441
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1442 if modules:contains("s2s") then
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1443 check_connectivity("xmpp-server")
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1444 if not api("*"):get_option_set("s2s_direct_tls_ports", {}):empty() then
11957
3a7ce7df7806 util.prosodyctl.check: Support direct TLS connectivity checks
Kim Alvefur <zash@zash.se>
parents: 11940
diff changeset
1445 check_connectivity("xmpps-server");
3a7ce7df7806 util.prosodyctl.check: Support direct TLS connectivity checks
Kim Alvefur <zash@zash.se>
parents: 11940
diff changeset
1446 end
11779
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1447 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1448
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1449 print()
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1450 end
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1451 print("Note: The connectivity check only checks the reachability of the domain.")
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1452 print("Note: It does not ensure that the check actually reaches this specific prosody instance.")
f4f0bdaeabd2 prosodyctl: Add external connectivity check based on observe.jabber.network
Jonas Schäfer <jonas@wielicki.name>
parents: 11778
diff changeset
1453 end
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1454
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1455 function checks.turn()
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1456 local turn_enabled_hosts = {};
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1457 local turn_services = {};
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1458
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1459 for host in enabled_hosts() do
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1460 local has_external_turn = modulemanager.get_modules_for_host(host):contains("turn_external");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1461 if has_external_turn then
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1462 local hostapi = api(host);
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1463 table.insert(turn_enabled_hosts, host);
13216
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1464 local turn_host = hostapi:get_option_string("turn_external_host", host);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1465 local turn_port = hostapi:get_option_number("turn_external_port", 3478);
fcc052ca1652 util.prosodyctl.check: Get some config options via minimal moduleapi #896
Kim Alvefur <zash@zash.se>
parents: 13121
diff changeset
1466 local turn_secret = hostapi:get_option_string("turn_external_secret");
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1467 if not turn_secret then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1468 print("Error: Your configuration is missing a turn_external_secret for "..host);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1469 print("Error: TURN will not be advertised for this host.");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1470 ok = false;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1471 else
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1472 local turn_id = ("%s:%d"):format(turn_host, turn_port);
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1473 if turn_services[turn_id] and turn_services[turn_id].secret ~= turn_secret then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1474 print("Error: Your configuration contains multiple differing secrets");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1475 print(" for the TURN service at "..turn_id.." - we will only test one.");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1476 elseif not turn_services[turn_id] then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1477 turn_services[turn_id] = {
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1478 host = turn_host;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1479 port = turn_port;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1480 secret = turn_secret;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1481 };
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1482 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1483 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1484 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1485 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1486
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1487 if what == "turn" then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1488 local count = it.count(pairs(turn_services));
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1489 if count == 0 then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1490 print("Error: Unable to find any TURN services configured. Enable mod_turn_external!");
12488
3183f358a88f util.prosodyctl.check: turn: Report lack of TURN services as a problem #1749
Kim Alvefur <zash@zash.se>
parents: 12466
diff changeset
1491 ok = false;
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1492 else
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1493 print("Identified "..tostring(count).." TURN services.");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1494 print("");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1495 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1496 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1497
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1498 for turn_id, turn_service in pairs(turn_services) do
12377
317132bca8c0 prosodyctl: check: include TURN checks by default
Matthew Wild <mwild1@gmail.com>
parents: 12376
diff changeset
1499 print("Testing TURN service "..turn_id.."...");
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1500
12372
1ba451c10f41 prosodyctl: check turn: Add support for testing data relay with an external STUN server via --ping
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
1501 local result = check_turn_service(turn_service, opts.ping);
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1502 if #result.warnings > 0 then
12381
d999c2b3e289 prosodyctl: check turn: fix formatting of multiple warnings
Matthew Wild <mwild1@gmail.com>
parents: 12380
diff changeset
1503 print(("%d warnings:\n"):format(#result.warnings));
d999c2b3e289 prosodyctl: check turn: fix formatting of multiple warnings
Matthew Wild <mwild1@gmail.com>
parents: 12380
diff changeset
1504 print(" "..table.concat(result.warnings, "\n "));
d999c2b3e289 prosodyctl: check turn: fix formatting of multiple warnings
Matthew Wild <mwild1@gmail.com>
parents: 12380
diff changeset
1505 print("");
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1506 end
12380
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1507
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1508 if opts.verbose then
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1509 if result.external_ip then
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1510 print(("External IP: %s"):format(result.external_ip.address));
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1511 end
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1512 if result.relayed_addresses then
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1513 for i, relayed_address in ipairs(result.relayed_addresses) do
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1514 print(("Relayed address %d: %s:%d"):format(i, relayed_address.address, relayed_address.port));
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1515 end
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1516 end
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1517 if result.external_ip_pong then
12390
71b5c9b8b07a prosodyctl: check turn: warn about external port mismatches behind NAT
Matthew Wild <mwild1@gmail.com>
parents: 12385
diff changeset
1518 print(("TURN external address: %s:%d"):format(result.external_ip_pong.address, result.external_ip_pong.port));
12380
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1519 end
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1520 end
3a702f37e87c prosodyctl: check turn: always show debug info even if test fails
Matthew Wild <mwild1@gmail.com>
parents: 12379
diff changeset
1521
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1522 if result.error then
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1523 print("Error: "..result.error.."\n");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1524 ok = false;
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1525 else
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1526 print("Success!\n");
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1527 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1528 end
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1529 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1530
13710
f7de36fed53c prosodyctl: check: Fix variable name (thanks luacheck)
Matthew Wild <mwild1@gmail.com>
parents: 13708
diff changeset
1531 function checks.features(check_host, quiet)
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1532 if not quiet then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1533 print("Feature report");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1534 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1535
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1536 local common_subdomains = {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1537 http_file_share = "share";
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1538 muc = "groups";
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1539 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1540
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1541 local recommended_component_modules = {
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1542 muc = { "muc_mam" };
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1543 };
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1544
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1545 local function print_feature_status(feature, host)
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1546 if quiet then return; end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1547 print("", feature.ok and "OK" or "(!)", feature.name);
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1548 if feature.desc then
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1549 print("", "", feature.desc);
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1550 print("");
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1551 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1552 if not feature.ok then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1553 if feature.lacking_modules then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1554 table.sort(feature.lacking_modules);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1555 print("", "", "Suggested modules: ");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1556 for _, module in ipairs(feature.lacking_modules) do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1557 print("", "", (" - %s: https://prosody.im/doc/modules/mod_%s"):format(module, module));
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1558 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1559 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1560 if feature.lacking_components then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1561 table.sort(feature.lacking_components);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1562 for _, component_module in ipairs(feature.lacking_components) do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1563 local subdomain = common_subdomains[component_module];
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1564 local recommended_mods = recommended_component_modules[component_module];
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1565 if subdomain then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1566 print("", "", "Suggested component:");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1567 print("");
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1568 print("", "", "", ("-- Documentation: https://prosody.im/doc/modules/mod_%s"):format(component_module));
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1569 print("", "", "", ("Component %q %q"):format(subdomain.."."..host, component_module));
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1570 if recommended_mods then
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1571 print("", "", "", " modules_enabled = {");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1572 table.sort(recommended_mods);
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1573 for _, mod in ipairs(recommended_mods) do
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1574 print("", "", "", (" %q;"):format(mod));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1575 end
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1576 print("", "", "", " }");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1577 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1578 else
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1579 print("", "", ("Suggested component: %s"):format(component_module));
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1580 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1581 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1582 print("");
13722
8bf5d07e3796 util.prosodyctl.check: Fix typo in informational message
Matthew Wild <mwild1@gmail.com>
parents: 13717
diff changeset
1583 print("", "", "If you have already configured any of these components, they may not be");
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1584 print("", "", "linked correctly to "..host..". For more info see https://prosody.im/doc/components");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1585 end
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1586 if feature.lacking_component_modules then
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1587 table.sort(feature.lacking_component_modules, function (a, b)
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1588 return a.host < b.host;
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1589 end);
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1590 for _, problem in ipairs(feature.lacking_component_modules) do
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1591 local hostapi = api(problem.host);
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1592 local current_modules_enabled = hostapi:get_option_array("modules_enabled", {});
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1593 print("", "", ("Component %q is missing the following modules: %s"):format(problem.host, table.concat(problem.missing_mods)));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1594 print("");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1595 print("","", "Add the missing modules to your modules_enabled under the Component, like this:");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1596 print("");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1597 print("");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1598 print("", "", "", ("-- Documentation: https://prosody.im/doc/modules/mod_%s"):format(problem.component_module));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1599 print("", "", "", ("Component %q %q"):format(problem.host, problem.component_module));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1600 print("", "", "", (" modules_enabled = {"));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1601 for _, mod in ipairs(current_modules_enabled) do
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1602 print("", "", "", (" %q;"):format(mod));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1603 end
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1604 for _, mod in ipairs(problem.missing_mods) do
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1605 print("", "", "", (" %q; -- Add this!"):format(mod));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1606 end
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1607 print("", "", "", (" }"));
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1608 end
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1609 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1610 end
13768
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1611 if feature.meta then
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1612 for k, v in it.sorted_pairs(feature.meta) do
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1613 print("", "", (" - %s: %s"):format(k, v));
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1614 end
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1615 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1616 print("");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1617 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1618
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1619 local all_ok = true;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1620
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1621 local config = configmanager.getconfig();
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1622
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1623 local f, s, v;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1624 if check_host then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1625 f, s, v = it.values({ check_host });
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1626 else
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1627 f, s, v = enabled_user_hosts();
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1628 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1629
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1630 for host in f, s, v do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1631 local modules_enabled = set.new(config["*"].modules_enabled);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1632 modules_enabled:include(set.new(config[host].modules_enabled));
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1633
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1634 -- { [component_module] = { hostname1, hostname2, ... } }
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1635 local host_components = setmetatable({}, { __index = function (t, k) return rawset(t, k, {})[k]; end });
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1636
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1637 do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1638 local hostapi = api(host);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1639
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1640 -- Find implicitly linked components
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1641 for other_host in enabled_components() do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1642 local parent_host = other_host:match("^[^.]+%.(.+)$");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1643 if parent_host == host then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1644 local component_module = configmanager.get(other_host, "component_module");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1645 if component_module then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1646 table.insert(host_components[component_module], other_host);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1647 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1648 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1649 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1650
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1651 -- And components linked explicitly
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1652 for _, disco_item in ipairs(hostapi:get_option_array("disco_items", {})) do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1653 local other_host = disco_item[1];
13778
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
1654 if type(other_host) == "string" then
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
1655 local component_module = configmanager.get(other_host, "component_module");
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
1656 if component_module then
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
1657 table.insert(host_components[component_module], other_host);
b6d0f1d79b60 prosodyctl check: Be more robust against invalid disco_items, and show warning
Matthew Wild <mwild1@gmail.com>
parents: 13768
diff changeset
1658 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1659 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1660 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1661 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1662
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1663 local current_feature;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1664
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1665 local function check_module(suggested, alternate, ...)
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1666 if set.intersection(modules_enabled, set.new({suggested, alternate, ...})):empty() then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1667 current_feature.lacking_modules = current_feature.lacking_modules or {};
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1668 table.insert(current_feature.lacking_modules, suggested);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1669 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1670 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1671
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1672 local function check_component(suggested, alternate, ...)
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1673 local found;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1674 for _, component_module in ipairs({ suggested, alternate, ... }) do
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1675 found = host_components[component_module][1];
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1676 if found then
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1677 local enabled_component_modules = api(found):get_option_inherited_set("modules_enabled");
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1678 local recommended_mods = recommended_component_modules[component_module];
13727
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1679 if recommended_mods then
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1680 local missing_mods = {};
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1681 for _, mod in ipairs(recommended_mods) do
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1682 if not enabled_component_modules:contains(mod) then
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1683 table.insert(missing_mods, mod);
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1684 end
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1685 end
13727
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1686 if #missing_mods > 0 then
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1687 if not current_feature.lacking_component_modules then
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1688 current_feature.lacking_component_modules = {};
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1689 end
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1690 table.insert(current_feature.lacking_component_modules, {
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1691 host = found;
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1692 component_module = component_module;
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1693 missing_mods = missing_mods;
704765bfe0a3 prosodyctl: check features: Fix traceback for components with no recommended modules (thanks Menel, riau)
Matthew Wild <mwild1@gmail.com>
parents: 13723
diff changeset
1694 });
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1695 end
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1696 end
13747
c25ab2f47876 prosodyctl: check features: stop searching after finding a matching component
Matthew Wild <mwild1@gmail.com>
parents: 13727
diff changeset
1697 break;
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1698 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1699 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1700 if not found then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1701 current_feature.lacking_components = current_feature.lacking_components or {};
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1702 table.insert(current_feature.lacking_components, suggested);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1703 end
13768
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1704 return found;
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1705 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1706
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1707 local features = {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1708 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1709 name = "Basic functionality";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1710 desc = "Support for secure connections, authentication and messaging";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1711 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1712 check_module("disco");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1713 check_module("roster");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1714 check_module("saslauth");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1715 check_module("tls");
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1716 end;
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1717 };
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1718 {
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1719 name = "Multi-device messaging and data synchronization";
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1720 desc = "Multiple clients connected to the same account stay in sync";
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1721 check = function ()
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1722 check_module("carbons");
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1723 check_module("mam");
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1724 check_module("bookmarks");
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1725 check_module("pep");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1726 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1727 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1728 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1729 name = "Mobile optimizations";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1730 desc = "Help mobile clients reduce battery and data usage";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1731 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1732 check_module("smacks");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1733 check_module("csi_simple", "csi_battery_saver");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1734 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1735 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1736 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1737 name = "Web connections";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1738 desc = "Allow connections from browser-based web clients";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1739 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1740 check_module("bosh");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1741 check_module("websocket");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1742 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1743 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1744 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1745 name = "User profiles";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1746 desc = "Enable users to publish profile information";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1747 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1748 check_module("vcard_legacy", "vcard");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1749 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1750 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1751 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1752 name = "Blocking";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1753 desc = "Block communication with chosen entities";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1754 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1755 check_module("blocklist");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1756 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1757 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1758 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1759 name = "Push notifications";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1760 desc = "Receive notifications on platforms that don't support persistent connections";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1761 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1762 check_module("cloud_notify");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1763 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1764 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1765 {
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1766 name = "Audio/video calls and P2P";
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1767 desc = "Assist clients in setting up connections between each other";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1768 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1769 check_module(
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1770 "turn_external",
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1771 "external_services",
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1772 "turncredentials",
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1773 "extdisco"
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1774 );
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1775 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1776 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1777 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1778 name = "File sharing";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1779 desc = "Sharing of files to groups and offline users";
13768
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1780 check = function (self)
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1781 local service = check_component("http_file_share", "http_upload", "http_upload_external");
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1782 if service then
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1783 local size_limit;
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1784 if api(service):get_option("component_module") == "http_file_share" then
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1785 size_limit = api(service):get_option_number("http_file_share_size_limit", 10*1024*1024);
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1786 end
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1787 if size_limit then
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1788 self.meta = {
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1789 ["Size limit"] = human_units.format(size_limit, "b", "b");
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1790 };
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1791 end
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1792 end
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1793 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1794 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1795 {
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1796 name = "Group chats";
13767
56fad06904b1 prosodyctl check features: Add descriptions to features
Matthew Wild <mwild1@gmail.com>
parents: 13747
diff changeset
1797 desc = "Create group chats and channels";
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1798 check = function ()
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1799 check_component("muc");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1800 end;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1801 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1802 };
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1803
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1804 if not quiet then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1805 print(host);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1806 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1807
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1808 for _, feature in ipairs(features) do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1809 current_feature = feature;
13768
4365f0f03c33 prosodyctl check features: Report size limit for HTTP upload
Matthew Wild <mwild1@gmail.com>
parents: 13767
diff changeset
1810 feature:check();
13717
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1811 feature.ok = (
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1812 not feature.lacking_modules and
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1813 not feature.lacking_components and
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1814 not feature.lacking_component_modules
4f173a44370b prosodyctl: check features: check for mod_muc_mam on MUC components
Matthew Wild <mwild1@gmail.com>
parents: 13710
diff changeset
1815 );
13707
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1816 -- For improved presentation, we group the (ok) and (not ok) features
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1817 if feature.ok then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1818 print_feature_status(feature, host);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1819 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1820 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1821
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1822 for _, feature in ipairs(features) do
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1823 if not feature.ok then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1824 all_ok = false;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1825 print_feature_status(feature, host);
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1826 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1827 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1828
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1829 if not quiet then
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1830 print("");
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1831 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1832 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1833
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1834 return all_ok;
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1835 end
6c59b9072871 prosodyctl: check features: Check for recommended feature availability
Matthew Wild <mwild1@gmail.com>
parents: 13706
diff changeset
1836
13301
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1837 if what == nil or what == "all" then
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1838 local ret;
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1839 ret = checks.disabled();
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1840 if ret ~= nil then return ret; end
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1841 ret = checks.config();
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1842 if ret ~= nil then return ret; end
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1843 ret = checks.dns();
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1844 if ret ~= nil then return ret; end
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1845 ret = checks.certs();
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1846 if ret ~= nil then return ret; end
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1847 ret = checks.turn();
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1848 if ret ~= nil then return ret; end
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1849 elseif checks[what] then
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1850 local ret = checks[what]();
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1851 if ret ~= nil then return ret; end
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1852 else
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1853 show_warning("Don't know how to check '%s'. Try one of 'config', 'dns', 'certs', 'disabled', 'turn' or 'connectivity'.", what);
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1854 show_warning("Note: The connectivity check will connect to a remote server.");
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1855 return 1;
84d83f4a190f util.prosodyctl.check: Wrap each check in a function
Kim Alvefur <zash@zash.se>
parents: 13256
diff changeset
1856 end
12357
cd11d7c4af8b util.prosodyctl: check turn: New command to verify STUN/TURN service is operational
Matthew Wild <mwild1@gmail.com>
parents: 12233
diff changeset
1857
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1858 if not ok then
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1859 print("Problems found, see above.");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1860 else
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1861 print("All checks passed, congratulations!");
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1862 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1863 return ok and 0 or 2;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1864 end
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1865
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1866 return {
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1867 check = check;
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1868 };