From dddb2a6b972f3491a7ca1ec82c56e704c6203642 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 27 Jan 2019 00:26:41 -0500 Subject: [PATCH] network update --wip --- sys/apis/injector.lua | 2 +- sys/apps/Network.lua | 75 +++++++++++++++++++++++++++++++++++---- sys/network/redserver.lua | 2 +- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/sys/apis/injector.lua b/sys/apis/injector.lua index 12792f6..7877a4c 100644 --- a/sys/apis/injector.lua +++ b/sys/apis/injector.lua @@ -106,7 +106,7 @@ return function(env) -- TODO: if there's no shell, we should not be checking relative paths below -- as they will resolve to root directory if env.shell and type(env.shell.getRunningProgram) == 'function' and sPath:sub(1, 1) ~= "/" then - sPath = fs.combine(fs.getDir(env.shell.getRunningProgram()), sPath) + sPath = fs.combine(fs.getDir(env.shell.getRunningProgram() or ''), sPath) end if fs.exists(sPath) and not fs.isDir(sPath) then return loadfile(sPath, env) diff --git a/sys/apps/Network.lua b/sys/apps/Network.lua index 70f77c2..2c26afe 100644 --- a/sys/apps/Network.lua +++ b/sys/apps/Network.lua @@ -1,5 +1,3 @@ -_G.requireInjector(_ENV) - local Config = require('config') local Event = require('event') local Socket = require('socket') @@ -44,17 +42,16 @@ local page = UI.Page { -- { text = 'Remove', event = 'untrust' }, } }, { text = 'Help', event = 'help', noCheck = true }, ---[[ { text = '\187', x = -3, dropdown = { - { text = 'Show all', event = 'show_all', noCheck = true }, - UI.MenuBar.spacer, - { text = 'Show trusted', event = 'show_trusted', noCheck = true }, + { text = 'Ports', event = 'ports', noCheck = true }, + -- { text = 'Show all', event = 'show_all', noCheck = true }, + -- UI.MenuBar.spacer, + -- { text = 'Show trusted', event = 'show_trusted', noCheck = true }, }, }, -]] }, }, grid = UI.ScrollingGrid { @@ -64,6 +61,22 @@ local page = UI.Page { sortColumn = 'label', autospace = true, }, + ports = UI.SlideOut { + titleBar = UI.TitleBar { + title = 'Ports', + event = 'ports_hide', + }, + grid = UI.ScrollingGrid { + y = 2, + columns = { + { heading = 'Port', key = 'port' }, + { heading = 'State', key = 'state' }, + { heading = 'Connection', key = 'connection' }, + }, + sortColumn = 'port', + autospace = true, + }, + }, notification = UI.Notification { }, accelerators = { t = 'telnet', @@ -93,6 +106,40 @@ local function sendCommand(host, command) end end +function page.ports.grid:update() + local function findConnection(port) + for _,socket in pairs(_G.transport.sockets) do + if socket.sport == port then + return socket + end + end + end + + local connections = { } + + for i = 0, 65535 do + if device.wireless_modem.isOpen(i) then + local conn = { + port = i + } + local socket = findConnection(i) + if socket then + conn.state = 'CONNECTED' + local host = socket.dhost + if network[host] then + host = network[host].label + end + conn.connection = host .. ':' .. socket.dport + else + conn.state = 'LISTEN' + end + table.insert(connections, conn) + end + end + self.values = connections + UI.Grid.update(self) +end + function page:eventHandler(event) local t = self.grid:getSelected() if t then @@ -167,6 +214,20 @@ This only needs to be done once. } }) + elseif event.type == 'ports' then + self.ports.grid:update() + self.ports:show() + + self.portsHandler = Event.onInterval(3, function() + self.ports.grid:update() + self.ports.grid:draw() + self:sync() + end) + + elseif event.type == 'ports_hide' then + Event.off(self.portsHandler) + self.ports:hide() + elseif event.type == 'show_all' then config.showTrusted = false self.grid:setValues(network) diff --git a/sys/network/redserver.lua b/sys/network/redserver.lua index 8da25a4..6c63d21 100644 --- a/sys/network/redserver.lua +++ b/sys/network/redserver.lua @@ -7,7 +7,7 @@ local os = _G.os local computerId = os.getComputerID() -modem.open(80) +--modem.open(80) -- https://github.com/golgote/neturl/blob/master/lib/net/url.lua local function parseQuery(str)