Advertisement
Guest User

99_sshd.lua

a guest
Jan 23rd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. local component = require('component')
  2. local m = component.modem
  3. local term = require('term')
  4. local buffer = require('buffer')
  5.  
  6. local io_write = io.write
  7. local io_read = io.read
  8.  
  9. local buffer_readline = buffer.readLine
  10.  
  11. local term_read = term.read
  12. local term_write = term.write
  13. local term_clear = term.clear
  14.  
  15. local print_original = print
  16.  
  17.  
  18. local sshport = 2222
  19. local send_to = '4669b39d-51a5-4d9a-8700-4b30d25fdcd1'
  20.  
  21. local function send_ssh(...)
  22.     m.send(send_to, sshport, ...)
  23. end
  24.  
  25. local function buffer_readline_override(buf, ...)
  26.     local out = buffer_readline(buf, ...)
  27.     if buf == io.stdin then
  28.         send_ssh(tostring(out))
  29.     end
  30.     return out
  31. end
  32.  
  33. local function io_read_override(buf, ...)
  34.     local out = io_read(buf, ...)
  35.     if buf == io.stdin then
  36.         send_ssh(tostring(out)..'\n')  
  37.     end
  38.     return out
  39. end
  40.  
  41. local function io_write_override(...)
  42.     local tgt = io_write(...)
  43.     send_ssh(...)
  44.     return tgt
  45. end
  46.  
  47. local function term_clear_override()
  48.     local out = term_clear()
  49.     send_ssh('<clear>')
  50.     return out
  51. end
  52.  
  53. io.write = function(...) return io_write_override(...) end
  54. io.read = function(buf, ...) return io_read_override(buf, ...) end
  55. buffer.readLine = function(buf, ...) return buffer_readline_override(buf, ...) end
  56.  
  57. term.read = function(...) local out = term_read(...); send_ssh(out); return out end
  58. term.write = function(...) local out = term_write(...); send_ssh(...); return out end
  59. term.clear = term_clear_override
  60.  
  61. print = function(...) print_original(...); send_ssh((... or '')..'\n') end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement