beck3k

ComputerCraft - SSH-clone Client

May 29th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. local version = "Version 1.2"
  2. local description = "'SSH'-Client for connecting to a remote controlable PC/Turtle via Rednet"
  3. old_commands = {}
  4. running = true
  5. side = "left" --Side where the Modem is attached on
  6. w, h = term.getSize()
  7. Send_ID = 0
  8. send_to = 0
  9. nbr_com = 0
  10. commandSpec = ""
  11. --Functions
  12. local function printCentered(str, ypos)
  13. term.setCursorPos(w/2 - #str/2, ypos)
  14. term.write(str)
  15. end
  16. local function printRight(str, ypos)
  17. term.setCursorPos(w - #str, ypos)
  18. term.write(str)
  19. end
  20. local function printLeft(str, ypos)
  21. term.setCursorPos(1, ypos)
  22. term.write(str)
  23. end
  24. function drawHeader()
  25. printCentered("SSH-System for Rednet.", 1)
  26. printCentered(string.rep("-", w), 2)
  27. printLeft(version, h)
  28. printRight("by Dean4Devil", h)
  29. end
  30.  
  31. function ssh_send(msg)
  32. rednet.open(side)
  33. rednet.send(send_to, msg)
  34. id, answer, distance = rednet.receive(5)
  35. answer = tostring(answer)
  36. rednet.close(side)
  37. end
  38. --Funktions END
  39. --Main
  40. term.clear()
  41. while running == true do
  42. term.clear()
  43. drawHeader()
  44. term.setCursorPos(1, 4)
  45. write( "> " )
  46. commandRaw = read()
  47. commandMain = tostring(commandRaw)
  48. table.insert(old_commands, commandMain)
  49. commandMainLower = string.lower(commandMain)
  50. commandSpec = string.sub(commandMain, 1, 1)
  51. if commandSpec == "/" then --lokales Kommando -> nicht versenden!
  52. if commandMainLower == "/exit" then
  53. running = false
  54. elseif commandMainLower == "/connect" then
  55. print("Give ID:")
  56. write("> ")
  57. send_to = tonumber(read())
  58. elseif commandMainLower == "/disconnect" then
  59. term.clear()
  60. drawHeader()
  61. send_to = 0
  62. elseif commandMainLower == "/dito" then
  63. write("n")
  64. write(old_commands[#old_commands-1])
  65. ssh_send(old_commands[#old_commands-1])
  66. else
  67. print("Unknown Command!")
  68. end
  69. elseif commandSpec == "#" then --Server-PrΓ€prozessor -> versenden
  70.  
  71. else --normale Kommandos -> versenden
  72. ssh_send(commandMain)
  73. print(answer)
  74. sleep(1)
  75. end
  76.  
  77. end
  78. term.clear()
  79. term.setCursorPos(1,1)
  80. --Main END
Add Comment
Please, Sign In to add comment