mirror of
https://github.com/kepler155c/opus
synced 2025-01-01 03:10:28 +00:00
network update --wip
This commit is contained in:
parent
b320c92551
commit
dddb2a6b97
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user