updated termsrv to basically work with the new rc system, added nc to netutil
This commit is contained in:
parent
ec5d938a64
commit
e5dd91e167
@ -46,4 +46,26 @@ function netutil.ping(addr,times,timeout, silent) -- Request acknowledgment from
|
|||||||
return success > 0, success, fail, avg
|
return success > 0, success, fail, avg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function netutil.nc(host,port)
|
||||||
|
port = port or 22
|
||||||
|
local socket = minitel.open(host,port)
|
||||||
|
if not socket then return false end
|
||||||
|
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
|
||||||
|
local b = io.read()
|
||||||
|
if b and b:len() > 0 then
|
||||||
|
socket:write(b.."\n")
|
||||||
|
end
|
||||||
|
until socket.state ~= "open"
|
||||||
|
end
|
||||||
|
|
||||||
return netutil
|
return netutil
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
print(pcall(function()
|
|
||||||
local minitel = require "minitel"
|
local minitel = require "minitel"
|
||||||
|
local shell = require "shell"
|
||||||
local port = 22
|
local port = 22
|
||||||
--local logfile = "/boot/termsrv.log"
|
|
||||||
|
|
||||||
local oout = io.output()
|
|
||||||
local pname = os.taskInfo(os.pid()).name
|
|
||||||
local function sread(self, len)
|
local function sread(self, len)
|
||||||
while true do
|
while true do
|
||||||
local d=self.sock:read(len)
|
local d=self.sock:read(len)
|
||||||
@ -31,6 +28,11 @@ local function sflush(self)
|
|||||||
self.wb = ""
|
self.wb = ""
|
||||||
self.flushing = false
|
self.flushing = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function start()
|
||||||
|
return os.spawn(function()
|
||||||
|
local oout = io.output()
|
||||||
|
local pname = os.taskInfo(os.pid()).name
|
||||||
while true do
|
while true do
|
||||||
local sock = minitel.listen(port)
|
local sock = minitel.listen(port)
|
||||||
print(string.format("Connection from %s:%d",sock.addr,sock.port))
|
print(string.format("Connection from %s:%d",sock.addr,sock.port))
|
||||||
@ -44,8 +46,8 @@ while true do
|
|||||||
fh.wb = ""
|
fh.wb = ""
|
||||||
io.input(fh)
|
io.input(fh)
|
||||||
io.output(fh)
|
io.output(fh)
|
||||||
fh:write(string.format("Connected to %s on port %d\n",os.getenv("HOSTNAME"),sock.port))
|
print(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
|
||||||
local pid = os.spawnfile("/boot/exec/shell.lua")
|
local pid = os.spawn(shell.interactive,string.format(pname.." shell [%s:%d]",sock.addr,sock.port))
|
||||||
repeat
|
repeat
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
if fh.wb:len() > 0 then
|
if fh.wb:len() > 0 then
|
||||||
@ -57,4 +59,5 @@ while true do
|
|||||||
oout:write(string.format("Session %s:%d ended",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,string.format(pname.." [%s:%d]",sock.addr,sock.port))
|
||||||
end
|
end
|
||||||
end))
|
end,"termsrv")
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user