updated nc and termsrv
This commit is contained in:
parent
b408cfe27b
commit
1cb85bd5e8
17
exec/nc.lua
17
exec/nc.lua
@ -1,16 +1,23 @@
|
|||||||
local minitel = require "minitel"
|
local minitel = require "minitel"
|
||||||
local tA = {...}
|
local tA = {...}
|
||||||
|
|
||||||
host, port = tA[1], tA[2]
|
host, port = tA[1], tA[2] or 22
|
||||||
|
|
||||||
local socket = minitel.open(host,port)
|
local socket = minitel.open(host,port)
|
||||||
if not socket then return false end
|
if not socket then return false end
|
||||||
local b = ""
|
local b = ""
|
||||||
|
os.spawn(function()
|
||||||
|
repeat
|
||||||
|
local b = socket:read("*a")
|
||||||
|
if b and b:len() > 0 then
|
||||||
|
io.write(b)
|
||||||
|
end
|
||||||
|
coroutine.yield()
|
||||||
|
until socket.state ~= "open"
|
||||||
|
end)
|
||||||
repeat
|
repeat
|
||||||
io.write(socket:read("*a"))
|
local b = io.read()
|
||||||
coroutine.yield()
|
if b and b:len() > 0 then
|
||||||
b = io.read(nil,true) or ""
|
|
||||||
if b:len() > 0 then
|
|
||||||
socket:write(b.."\n")
|
socket:write(b.."\n")
|
||||||
end
|
end
|
||||||
until socket.state ~= "open"
|
until socket.state ~= "open"
|
||||||
|
@ -3,47 +3,58 @@ local minitel = require "minitel"
|
|||||||
local port = 22
|
local port = 22
|
||||||
--local logfile = "/boot/termsrv.log"
|
--local logfile = "/boot/termsrv.log"
|
||||||
|
|
||||||
if logfile then
|
local oout = io.output()
|
||||||
local log = io.open(logfile,"a")
|
local pname = os.taskInfo(os.pid()).name
|
||||||
os.setenv("t",log.fd)
|
local function sread(self, len)
|
||||||
|
while true do
|
||||||
|
local d=self.sock:read(len)
|
||||||
|
if d then
|
||||||
|
return d
|
||||||
|
end
|
||||||
|
coroutine.yield()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local function nextvty()
|
local function swrite(self, data)
|
||||||
local vtyn = -1
|
while self.flushing do
|
||||||
repeat
|
coroutine.yield()
|
||||||
vtyn = vtyn + 1
|
end
|
||||||
until not fs.exists("/iofs/vty"..tostring(vtyn))
|
if data and data:len() > 0 then
|
||||||
return "vty"..tostring(vtyn)
|
self.wb = self.wb .. (data or "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function sclose(self)
|
||||||
|
self.sock:close()
|
||||||
|
end
|
||||||
|
local function sflush(self)
|
||||||
|
self.flushing = true
|
||||||
|
self.sock:write(self.wb)
|
||||||
|
self.wb = ""
|
||||||
|
self.flushing = false
|
||||||
end
|
end
|
||||||
while true do
|
while true do
|
||||||
local sock = minitel.listen(port)
|
local sock = minitel.listen(port)
|
||||||
print(string.format("[%s] Connection from %s:%d",os.date("%Y-%m-%d %H:%M"),sock.addr,sock.port))
|
print(string.format("Connection from %s:%d",sock.addr,sock.port))
|
||||||
os.spawn(function() _G.worked = {pcall(function()
|
os.spawn(function() _G.worked = {pcall(function()
|
||||||
local vtyf = nextvty()
|
local fh = {}
|
||||||
local fdo = {}
|
fh.sock = sock
|
||||||
function fdo.read(d)
|
fh.read = sread
|
||||||
return sock:read(d)
|
fh.write = swrite
|
||||||
end
|
fh.close = sclose
|
||||||
function fdo.write(d)
|
fh.flush = sflush
|
||||||
return sock:write(d)
|
fh.wb = ""
|
||||||
end
|
io.input(fh)
|
||||||
function fdo.close()
|
io.output(fh)
|
||||||
sock:close()
|
fh:write(string.format("Connected to %s on port %d\n",os.getenv("HOSTNAME"),sock.port))
|
||||||
end
|
local pid = os.spawnfile("/boot/exec/shell.lua")
|
||||||
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)
|
|
||||||
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
|
repeat
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
until sock.state ~= "open" or not tTasks[pid]
|
if fh.wb:len() > 0 then
|
||||||
f:close()
|
fh:flush()
|
||||||
|
end
|
||||||
|
until sock.state ~= "open" or not os.taskInfo(pid)
|
||||||
sock:close()
|
sock:close()
|
||||||
os.kill(pid)
|
os.kill(pid)
|
||||||
os.setenv("t",ot)
|
oout:write(string.format("Session %s:%d ended",sock.addr,sock.port))
|
||||||
print(string.format("Session %s:%d ended",sock.addr,sock.port))
|
end)} end,string.format(pname.." [%s:%d]",sock.addr,sock.port))
|
||||||
end)} end,string.format("remote login [%s:%d]",sock.addr,sock.port))
|
|
||||||
end
|
end
|
||||||
end))
|
end))
|
||||||
|
Loading…
Reference in New Issue
Block a user