added nsh for remote login and stuff.

This commit is contained in:
Izaya 2017-09-01 09:07:07 +10:00
parent 55310a6c2c
commit 7e42870c71
4 changed files with 60 additions and 1 deletions

View File

@ -18,6 +18,8 @@ modules/net/net-ext.lua
modules/applications/luash.lua modules/applications/luash.lua
modules/applications/genkernel.lua modules/applications/genkernel.lua
fwrap skex exec/skex2.lua fwrap skex exec/skex2.lua
fwrap nshd exec/nshd.lua
fwrap nsh exec/nsh.lua
modules/util/tape.lua modules/util/tape.lua
modules/util/fs-automount.lua modules/util/fs-automount.lua
modules/setup.lua modules/setup.lua

24
exec/nsh.lua Normal file
View File

@ -0,0 +1,24 @@
tA = {...}
local h,p = tA[1], tonumber(tA[2])
local function nshcw(h,p)
while true do
local sI = os.getenv("sI")
local ev = {event.pull()}
if ev[1] == "net_msg" and ev[2] == h and ev[3] == p then
write(ev[4])
elseif ev[1] == "key" and ev[2] == sI then
net.send(h,p,string.char(ev[3],ev[4]))
end
end
end
net.send(h,p or 23,"initnsh2")
local bt = os.time()
local tp,src,port,msg
repeat
tp, src, port, msg = event.pull()
until (tp == "net_msg" and src == h and port == p) or os.time() > bt+16
if tp == "net_msg" then
nshcw(h,tonumber(msg))
else
print("timeout.")
end

33
exec/nshd.lua Normal file
View File

@ -0,0 +1,33 @@
local tA = {...}
local nport = tA[1] or "23"
function nshdw(h,p,s)
spawn("nshdw["..tostring(s).."]",function() print(pcall(function()
while true do
local sI = os.getenv("sI")
local ev = {event.pull()}
if ev[1] == "net_msg" and ev[2] == h and ev[3] == p then
event.push("key",sI,string.byte(ev[4]:sub(1,1)),string.byte(ev[4]:sub(2,2)))
elseif ev[1] == "display" and ev[2] == sI then
if ev[3]:len() < 1024 then
net.send(h,p,ev[3])
else
for i = 1, ev[3]:len(), 1024 do
net.send(h,p,ev[3]:sub(i,i+1023))
end
end
end
end
end)) end,{sI=s})
end
spawn("nshd["..tostring(nport).."]",function() print(pcall(function()
while true do
local _, src, port, msg = event.pull("net_msg")
if port == nport and msg == "initnsh2" then
local cport = math.random(65535-1024,65535)
local ns = "nsh-"..tostring(cport)
net.send(src,port,tostring(cport))
luash(ns)
nshdw(src,cport,ns)
end
end
end)) end)

View File

@ -41,5 +41,5 @@ spawn("lua shell",function()
print(table.unpack(r)) print(table.unpack(r))
end end
end end
end,si) end,{sI=si})
end end