mod_admin_telnet: Sort hosts
authorKim Alvefur <zash@zash.se>
Sat, 30 Nov 2019 21:56:21 +0100
changeset 10474 5267f12b038d
parent 10473 658b759a1f7a
child 10475 ae906d51e3d2
mod_admin_telnet: Sort hosts Groups by domain in DNS hierarchy order or something. Why not split on '.' you ask? Well becasue that's not what I typed here. Also "[^.]" is longer than "%P".
plugins/mod_admin_telnet.lua
--- a/plugins/mod_admin_telnet.lua	Sat Nov 30 19:34:40 2019 +0100
+++ b/plugins/mod_admin_telnet.lua	Sat Nov 30 21:56:21 2019 +0100
@@ -964,11 +964,15 @@
 	return hostmanager.deactivate(hostname, reason);
 end
 
+local function compare_hosts(a, b)
+	return a:gsub("%P", string.reverse):reverse() < b:gsub("%P", string.reverse):reverse();
+end
+
 function def_env.host:list()
 	local print = self.session.print;
 	local i = 0;
 	local type;
-	for host, host_session in iterators.sorted_pairs(prosody.hosts) do
+	for host, host_session in iterators.sorted_pairs(prosody.hosts, compare_hosts) do
 		i = i + 1;
 		type = host_session.type;
 		if type == "local" then