Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4KB

  1. print(pcall(function()
  2. local minitel = require "minitel"
  3. local port = 22
  4. --local logfile = "/boot/termsrv.log"
  5. if logfile then
  6. local log = io.open(logfile,"a")
  7. os.setenv("t",log.fd)
  8. end
  9. local function nextvty()
  10. local vtyn = -1
  11. repeat
  12. vtyn = vtyn + 1
  13. until not fs.exists("/iofs/vty"..tostring(vtyn))
  14. return "vty"..tostring(vtyn)
  15. end
  16. while true do
  17. local sock = minitel.listen(port)
  18. print(string.format("[%s] Connection from %s:%d",os.date("%Y-%m-%d %H:%M"),sock.addr,sock.port))
  19. os.spawn(function() _G.worked = {pcall(function()
  20. local vtyf = nextvty()
  21. local fdo = {}
  22. function fdo.read(d)
  23. return sock:read(d)
  24. end
  25. function fdo.write(d)
  26. return sock:write(d)
  27. end
  28. function fdo.close()
  29. sock:close()
  30. end
  31. iofs.register(vtyf,function() return fdo.read, fdo.write, fdo.close end)
  32. local f = io.open("/iofs/"..vtyf,"rw")
  33. print(vtyf, f.fd)
  34. local ot = os.getenv("t")
  35. os.setenv("t",f.fd)
  36. sock:write(string.format("Connected to %s on port %d\n",computer.address():sub(1,8),sock.port))
  37. local pid = spawnfile("/boot/exec/shell.lua",string.format("shell [%s:%d]",sock.addr,sock.port))
  38. repeat
  39. coroutine.yield()
  40. until sock.state ~= "open" or not tTasks[pid]
  41. f:close()
  42. sock:close()
  43. os.kill(pid)
  44. os.setenv("t",ot)
  45. print(string.format("Session %s:%d ended",sock.addr,sock.port))
  46. end)} end,string.format("remote login [%s:%d]",sock.addr,sock.port))
  47. end
  48. end))