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