2019-01-09 00:23:30 -05:00
|
|
|
print(pcall(function()
|
|
|
|
local minitel = require "minitel"
|
|
|
|
local port = 22
|
2019-07-14 06:52:56 -04:00
|
|
|
--local logfile = "/boot/termsrv.log"
|
2019-01-09 00:23:30 -05:00
|
|
|
|
|
|
|
if logfile then
|
|
|
|
local log = io.open(logfile,"a")
|
|
|
|
os.setenv("t",log.fd)
|
|
|
|
end
|
2019-07-14 06:52:56 -04:00
|
|
|
local function nextvty()
|
|
|
|
local vtyn = -1
|
|
|
|
repeat
|
|
|
|
vtyn = vtyn + 1
|
|
|
|
until not fs.exists("/iofs/vty"..tostring(vtyn))
|
|
|
|
return "vty"..tostring(vtyn)
|
|
|
|
end
|
2019-01-09 00:23:30 -05:00
|
|
|
while true do
|
|
|
|
local sock = minitel.listen(port)
|
|
|
|
print(string.format("[%s] Connection from %s:%d",os.date("%Y-%m-%d %H:%M"),sock.addr,sock.port))
|
|
|
|
os.spawn(function() _G.worked = {pcall(function()
|
2019-07-14 06:52:56 -04:00
|
|
|
local vtyf = nextvty()
|
|
|
|
local fdo = {}
|
2019-01-09 00:23:30 -05:00
|
|
|
function fdo.read(d)
|
|
|
|
return sock:read(d)
|
|
|
|
end
|
|
|
|
function fdo.write(d)
|
|
|
|
return sock:write(d)
|
|
|
|
end
|
|
|
|
function fdo.close()
|
|
|
|
sock:close()
|
|
|
|
end
|
2019-07-14 06:52:56 -04:00
|
|
|
iofs.register(vtyf,function() return fdo.read, fdo.write, fdo.close end)
|
|
|
|
local f = io.open("/iofs/"..vtyf,"rw")
|
|
|
|
print(vtyf, f.fd)
|
|
|
|
local ot = os.getenv("t")
|
|
|
|
os.setenv("t",f.fd)
|
2019-01-09 00:23:30 -05:00
|
|
|
sock:write(string.format("Connected to %s on port %d\n",computer.address():sub(1,8),sock.port))
|
|
|
|
local pid = spawnfile("/boot/exec/shell.lua",string.format("shell [%s:%d]",sock.addr,sock.port))
|
|
|
|
repeat
|
|
|
|
coroutine.yield()
|
|
|
|
until sock.state ~= "open" or not tTasks[pid]
|
2019-07-14 06:52:56 -04:00
|
|
|
f:close()
|
2019-01-09 00:23:30 -05:00
|
|
|
sock:close()
|
|
|
|
os.kill(pid)
|
2019-07-14 06:52:56 -04:00
|
|
|
os.setenv("t",ot)
|
|
|
|
print(string.format("Session %s:%d ended",sock.addr,sock.port))
|
2019-01-09 00:23:30 -05:00
|
|
|
end)} end,string.format("remote login [%s:%d]",sock.addr,sock.port))
|
|
|
|
end
|
|
|
|
end))
|