Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 4674:f44726a910a0
mod_admin_telnet: Add initial port:list() and port:close() commands
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 24 Apr 2012 15:40:00 +0100 |
parent | 4647:57a4f863e48f |
child | 4684:dc70c4ffb66d |
comparison
equal
deleted
inserted
replaced
4673:2fb5882fdef1 | 4674:f44726a910a0 |
---|---|
757 print(host); | 757 print(host); |
758 end | 758 end |
759 return true, i.." hosts"; | 759 return true, i.." hosts"; |
760 end | 760 end |
761 | 761 |
762 def_env.port = {}; | |
763 | |
764 function def_env.port:list() | |
765 local print = self.session.print; | |
766 local services = portmanager.get_active_services().data; | |
767 local ordered_services, n_ports = {}, 0; | |
768 for service, interfaces in pairs(services) do | |
769 table.insert(ordered_services, service); | |
770 end | |
771 table.sort(ordered_services); | |
772 for _, service in ipairs(ordered_services) do | |
773 local ports_list = {}; | |
774 for interface, ports in pairs(services[service]) do | |
775 for port in pairs(ports) do | |
776 table.insert(ports_list, "["..interface.."]:"..port); | |
777 end | |
778 end | |
779 n_ports = n_ports + #ports_list; | |
780 print(service..": "..table.concat(ports_list, ", ")); | |
781 end | |
782 return true, #ordered_services.." services listening on "..n_ports.." ports"; | |
783 end | |
784 | |
785 function def_env.port:close(close_port, close_interface) | |
786 close_port = assert(tonumber(close_port), "Invalid port number"); | |
787 local n_closed = 0; | |
788 local services = portmanager.get_active_services().data; | |
789 for service, interfaces in pairs(services) do | |
790 for interface, ports in pairs(interfaces) do | |
791 if not close_interface or close_interface == interface then | |
792 if ports[close_port] then | |
793 self.session.print("Closing ["..interface.."]:"..close_port.."..."); | |
794 local ok, err = portmanager.close(interface, close_port) | |
795 if not ok then | |
796 self.session.print("Failed to close "..interface.." "..port..": "..err); | |
797 else | |
798 n_closed = n_closed + 1; | |
799 end | |
800 end | |
801 end | |
802 end | |
803 end | |
804 return true, "Closed "..n_closed.." ports"; | |
805 end | |
806 | |
762 ------------- | 807 ------------- |
763 | 808 |
764 function printbanner(session) | 809 function printbanner(session) |
765 local option = config.get("*", "core", "console_banner"); | 810 local option = config.get("*", "core", "console_banner"); |
766 if option == nil or option == "full" or option == "graphic" then | 811 if option == nil or option == "full" or option == "graphic" then |
787 pcall(option, session); | 832 pcall(option, session); |
788 end | 833 end |
789 end | 834 end |
790 end | 835 end |
791 | 836 |
792 require "core.portmanager".register_service("console", { | 837 module:add_item("net-provider", { |
838 name = "console"; | |
793 listener = console_listener; | 839 listener = console_listener; |
794 default_port = 5582; | 840 default_port = 5582; |
795 private = true; | 841 private = true; |
796 }); | 842 }); |