Comparison

plugins/mod_admin_telnet.lua @ 9330:36badabc85ce

mod_admin_telnet: Make use of util.iterators.sorted_pairs()
author Matthew Wild <mwild1@gmail.com>
date Fri, 21 Sep 2018 14:36:29 +0100
parent 9009:4c745d42c974
child 9332:048389a9bbd4
comparison
equal deleted inserted replaced
9329:19bc3ec13f07 9330:36badabc85ce
873 873
874 function def_env.host:list() 874 function def_env.host:list()
875 local print = self.session.print; 875 local print = self.session.print;
876 local i = 0; 876 local i = 0;
877 local type; 877 local type;
878 for host in values(array.collect(keys(prosody.hosts)):sort()) do 878 for host, host_session in it.sorted_pairs(prosody.hosts) do
879 i = i + 1; 879 i = i + 1;
880 type = hosts[host].type; 880 type = host_session.type;
881 if type == "local" then 881 if type == "local" then
882 print(host); 882 print(host);
883 else 883 else
884 type = module:context(host):get_option_string("component_module", type); 884 type = module:context(host):get_option_string("component_module", type);
885 if type ~= "component" then 885 if type ~= "component" then
894 def_env.port = {}; 894 def_env.port = {};
895 895
896 function def_env.port:list() 896 function def_env.port:list()
897 local print = self.session.print; 897 local print = self.session.print;
898 local services = portmanager.get_active_services().data; 898 local services = portmanager.get_active_services().data;
899 local ordered_services, n_ports = {}, 0; 899 local n_services, n_ports = 0, 0;
900 for service, interfaces in pairs(services) do 900 for service, interfaces in it.sorted_pairs(services) do
901 table.insert(ordered_services, service); 901 n_services = n_services + 1;
902 end
903 table.sort(ordered_services);
904 for _, service in ipairs(ordered_services) do
905 local ports_list = {}; 902 local ports_list = {};
906 for interface, ports in pairs(services[service]) do 903 for interface, ports in pairs(interfaces) do
907 for port in pairs(ports) do 904 for port in pairs(ports) do
908 table.insert(ports_list, "["..interface.."]:"..port); 905 table.insert(ports_list, "["..interface.."]:"..port);
909 end 906 end
910 end 907 end
911 n_ports = n_ports + #ports_list; 908 n_ports = n_ports + #ports_list;
912 print(service..": "..table.concat(ports_list, ", ")); 909 print(service..": "..table.concat(ports_list, ", "));
913 end 910 end
914 return true, #ordered_services.." services listening on "..n_ports.." ports"; 911 return true, n_services.." services listening on "..n_ports.." ports";
915 end 912 end
916 913
917 function def_env.port:close(close_port, close_interface) 914 function def_env.port:close(close_port, close_interface)
918 close_port = assert(tonumber(close_port), "Invalid port number"); 915 close_port = assert(tonumber(close_port), "Invalid port number");
919 local n_closed = 0; 916 local n_closed = 0;