2019-01-09 00:23:30 -05:00
|
|
|
local minitel = require "minitel"
|
2020-04-14 23:33:27 -04:00
|
|
|
local shell = require "shell"
|
2019-01-09 00:23:30 -05:00
|
|
|
local port = 22
|
|
|
|
|
2019-12-16 01:09:56 -05:00
|
|
|
local function sread(self, len)
|
|
|
|
while true do
|
|
|
|
local d=self.sock:read(len)
|
|
|
|
if d then
|
|
|
|
return d
|
|
|
|
end
|
|
|
|
coroutine.yield()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function swrite(self, data)
|
|
|
|
while self.flushing do
|
|
|
|
coroutine.yield()
|
|
|
|
end
|
|
|
|
if data and data:len() > 0 then
|
|
|
|
self.wb = self.wb .. (data or "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function sclose(self)
|
|
|
|
self.sock:close()
|
2019-01-09 00:23:30 -05:00
|
|
|
end
|
2019-12-16 01:09:56 -05:00
|
|
|
local function sflush(self)
|
|
|
|
self.flushing = true
|
|
|
|
self.sock:write(self.wb)
|
|
|
|
self.wb = ""
|
|
|
|
self.flushing = false
|
2019-07-14 06:52:56 -04:00
|
|
|
end
|
2020-04-14 23:33:27 -04:00
|
|
|
|
|
|
|
function start()
|
|
|
|
return os.spawn(function()
|
|
|
|
local oout = io.output()
|
|
|
|
local pname = os.taskInfo(os.pid()).name
|
|
|
|
while true do
|
|
|
|
local sock = minitel.listen(port)
|
|
|
|
print(string.format("Connection from %s:%d",sock.addr,sock.port))
|
|
|
|
os.spawn(function() _G.worked = {pcall(function()
|
|
|
|
local fh = {}
|
|
|
|
fh.sock = sock
|
|
|
|
fh.read = sread
|
|
|
|
fh.write = swrite
|
|
|
|
fh.close = sclose
|
|
|
|
fh.flush = sflush
|
|
|
|
fh.wb = ""
|
|
|
|
io.input(fh)
|
|
|
|
io.output(fh)
|
|
|
|
print(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
|
|
|
|
local pid = os.spawn(shell.interactive,string.format(pname.." shell [%s:%d]",sock.addr,sock.port))
|
|
|
|
repeat
|
|
|
|
coroutine.yield()
|
|
|
|
if fh.wb:len() > 0 then
|
|
|
|
fh:flush()
|
|
|
|
end
|
|
|
|
until sock.state ~= "open" or not os.taskInfo(pid)
|
|
|
|
sock:close()
|
|
|
|
os.kill(pid)
|
|
|
|
oout:write(string.format("Session %s:%d ended",sock.addr,sock.port))
|
|
|
|
end)} end,string.format(pname.." [%s:%d]",sock.addr,sock.port))
|
|
|
|
end
|
|
|
|
end,"termsrv")
|
2019-01-09 00:23:30 -05:00
|
|
|
end
|