Comparison

util/prosodyctl/check.lua @ 12217:39043233de04

util.prosodyctl.check: Add HTTP related DNS checks Since XEP-0363 is essentially mandatory now this will hopefully help diagnose some common issues.
author Kim Alvefur <zash@zash.se>
date Thu, 27 Jan 2022 12:36:50 +0100
parent 12159:aa299551f8c6
child 12218:0795e1ccf3d8
comparison
equal deleted inserted replaced
12216:0f5d04c3092f 12217:39043233de04
590 if target_hosts:contains("localhost") then 590 if target_hosts:contains("localhost") then
591 print(" Target 'localhost' cannot be accessed from other servers"); 591 print(" Target 'localhost' cannot be accessed from other servers");
592 target_hosts:remove("localhost"); 592 target_hosts:remove("localhost");
593 end 593 end
594 594
595 local function check_address(target)
596 local A, AAAA = dns.lookup(idna.to_ascii(target), "A"), dns.lookup(idna.to_ascii(target), "AAAA");
597 local prob = {};
598 if use_ipv4 and not A then table.insert(prob, "A"); end
599 if use_ipv6 and not AAAA then table.insert(prob, "AAAA"); end
600 return prob;
601 end
602
595 if modules:contains("proxy65") then 603 if modules:contains("proxy65") then
596 local proxy65_target = configmanager.get(host, "proxy65_address") or host; 604 local proxy65_target = configmanager.get(host, "proxy65_address") or host;
597 if type(proxy65_target) == "string" then 605 if type(proxy65_target) == "string" then
598 local A, AAAA = dns.lookup(idna.to_ascii(proxy65_target), "A"), dns.lookup(idna.to_ascii(proxy65_target), "AAAA"); 606 local prob = check_address(proxy65_target);
599 local prob = {};
600 if use_ipv4 and not A then
601 table.insert(prob, "A");
602 end
603 if use_ipv6 and not AAAA then
604 table.insert(prob, "AAAA");
605 end
606 if #prob > 0 then 607 if #prob > 0 then
607 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/") 608 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/")
608 .." record. Create one or set 'proxy65_address' to the correct host/IP."); 609 .." record. Create one or set 'proxy65_address' to the correct host/IP.");
609 end 610 end
610 else 611 else
611 print(" proxy65_address for "..host.." should be set to a string, unable to perform DNS check"); 612 print(" proxy65_address for "..host.." should be set to a string, unable to perform DNS check");
613 end
614 end
615
616 local known_http_modules = set.new { "bosh"; "http_files"; "http_file_share"; "http_openmetrics"; "websocket" };
617 local function contains_match(hayset, needle)
618 for member in hayset do if member:find(needle) then return true end end
619 end
620
621 if modules:contains("http") or not set.intersection(modules, known_http_modules):empty()
622 or contains_match(modules, "^http_") or contains_match(modules, "_web$") then
623
624 local http_host = configmanager.get(host, "http_host") or host;
625 local http_internal_host = http_host;
626 local http_url = configmanager.get(host, "http_external_url");
627 if http_url then
628 local url_parse = require "socket.url";
629 local external_url_parts = url_parse(http_url);
630 if external_url_parts then
631 http_host = external_url_parts.host;
632 else
633 print(" The 'http_external_url' setting is not a valid URL");
634 end
635 end
636
637 local prob = check_address(http_host);
638 if #prob > 1 then
639 print(" HTTP service " .. http_host .. " has no " .. table.concat(prob, "/") .. " record. Create one or change "
640 .. (http_url and "'http_external_url'" or "'http_host'").." to the correct host.");
641 end
642
643 if http_host ~= http_internal_host then
644 print(" Ensure the reverse proxy sets the HTTP Host header to '" .. http_internal_host .. "'");
612 end 645 end
613 end 646 end
614 647
615 if not use_ipv4 and not use_ipv6 then 648 if not use_ipv4 and not use_ipv6 then
616 print(" Both IPv6 and IPv4 are disabled, Prosody will not listen on any ports"); 649 print(" Both IPv6 and IPv4 are disabled, Prosody will not listen on any ports");