comparison util/prosodyctl/check.lua @ 14050:64cd905cb1de

util.prosodyctl.check: Do not suggest renaming domain to public suffix Adds optional dependency on https://github.com/daurnimator/lua-psl
author Kim Alvefur <zash@zash.se>
date Thu, 22 Jan 2026 17:54:30 +0100
parents f5d415d54064
children 0ea2848d7771
comparison
equal deleted inserted replaced
14049:04c3687b5641 14050:64cd905cb1de
10 local jid_split = require "prosody.util.jid".prepped_split; 10 local jid_split = require "prosody.util.jid".prepped_split;
11 local modulemanager = require "prosody.core.modulemanager"; 11 local modulemanager = require "prosody.core.modulemanager";
12 local async = require "prosody.util.async"; 12 local async = require "prosody.util.async";
13 local httputil = require "prosody.util.http"; 13 local httputil = require "prosody.util.http";
14 local human_units = require "prosody.util.human.units"; 14 local human_units = require "prosody.util.human.units";
15 local have_psl, publicsuffix = pcall(require, "psl");
15 16
16 local function api(host) 17 local function api(host)
17 return setmetatable({ name = "prosodyctl.check"; host = host; log = prosody.log }, { __index = moduleapi }) 18 return setmetatable({ name = "prosodyctl.check"; host = host; log = prosody.log }, { __index = moduleapi })
18 end 19 end
19 20
586 print(" see https://prosody.im/doc/configure#overview for more information.") 587 print(" see https://prosody.im/doc/configure#overview for more information.")
587 print(""); 588 print("");
588 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", ")); 589 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", "));
589 end 590 end
590 end 591 end
592 local psl = have_psl and publicsuffix.latest(api("*"):get_option_string("public_suffix_file", nil));
591 for host, options in enabled_hosts() do 593 for host, options in enabled_hosts() do
592 -- This is meant to prod people away from xmpp.example.com towards example.com, 594 -- This is meant to prod people away from xmpp.example.com towards example.com,
593 -- but will not do the right thing with second level hierarchies like .co.uk 595 -- but will not do the right thing with second level hierarchies like .co.uk
594 -- This could be improved by using the Public Suffix List or a similar method. 596 -- unless lua-psl is installed
595 local host_options = set.new(it.to_array(it.keys(options))); 597 local host_options = set.new(it.to_array(it.keys(options)));
596 local subdomain = host:match("^[^.]+"); 598 local subdomain = host:match("^[^.]+");
597 local suggestion = host:gsub("^[^.]+%.", ""); 599 local suggestion = host:gsub("^[^.]+%.", "");
598 if not(host_options:contains("component_module")) and (subdomain == "jabber" or subdomain == "xmpp" 600 if not(host_options:contains("component_module")) and (subdomain == "jabber" or subdomain == "xmpp"
599 or subdomain == "chat" or subdomain == "im") and (suggestion:match("%."))then 601 or subdomain == "chat" or subdomain == "im") and (suggestion:match("%.") or psl and not psl:is_public_suffix(suggestion)) then
600 print(""); 602 print("");
601 print(" Suggestion: If "..host.. " is a new host with no real users yet, consider renaming it now to"); 603 print(" Suggestion: If "..host.. " is a new host with no real users yet, consider renaming it now to");
602 print(" "..suggestion..". You can use SRV records to redirect XMPP clients and servers to "..host.."."); 604 print(" "..suggestion..". You can use SRV records to redirect XMPP clients and servers to "..host..".");
603 print(" For more information see: https://prosody.im/doc/dns"); 605 print(" For more information see: https://prosody.im/doc/dns");
604 end 606 end