asteroidsteam

ssh

Dec 11th, 2016
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 KB | None | 0 0
  1. local args = {...}
  2. function starts(String,Start)
  3.    return string.sub(String,1,string.len(Start))==Start
  4. end
  5. connterm = false
  6. function usage()
  7. term.setTextColor(colors.red)
  8. print("-----------Secure Shell 2.7-----------")
  9. print("Usage:")
  10. print("ssh <id> [port]")
  11. print("ssh open [port]")
  12. --print("ssh broadcast <message> <id> [port] ")
  13. print("ssh setnick <nickname>")
  14. print("ssh testopen <id> [port]")
  15. print("ssh update")
  16. print("-----------Secure Shell 2.7-----------")
  17. term.setTextColor(colors.white)
  18. end
  19. if #args < 1 then
  20. usage()
  21. else if #args > 4 then
  22. usage()
  23. else
  24. if args[1] == "update" then
  25. shell.setAlias("pastebin", "/rom/programs/http/pastebin")
  26. shell.run("pastebin run qHUXSZHg")
  27. shell.setAlias("pastebin", "/os/un")
  28. else
  29. if args[1] == "testopen" then
  30. rednet.open("top")
  31. if #args > 2 then
  32. local server = rednet.lookup(args[2], args[3])
  33. if server then
  34. print("That server does exist!")
  35. else
  36. print("That server does Not exist!")
  37. end
  38. else
  39. local server = rednet.lookup(args[2], "25674")
  40. if server then
  41. print("That server does exist!")
  42. else
  43. print("That server does Not exist!")
  44. end
  45. end
  46.  
  47. else
  48. if args[1] == "setnick" then
  49. local file = fs.open("sshnickname", "w")
  50. file.writeLine(args[2])
  51. file.close()
  52. print("Nickname Set As: ", args[2])
  53. else
  54. if args[1] == "broadcast" then
  55. rednet.open("top")
  56. local nnfile = fs.exists("sshnickname")
  57. if #args > 3 then
  58. local server = rednet.lookup(args[3], args[4])
  59. if server then
  60. if nnfile then
  61. local filea = fs.open("sshnickname", "r")
  62. local bc = filea.readLine()..": "..args[2]
  63. filea.close()
  64. rednet.broadcast(bc, args[3])
  65. print("Broadcasted: ", bc, " to: \"", args[3],":",args[4], "\"")
  66. else
  67. rednet.broadcast(args[2], args[3])
  68. print("Broadcasted: ", args[2], " to: \"", args[3],":",args[4], "\"")
  69. end
  70. else
  71. print("Error: Secure shell server does not exist!")
  72. end
  73. else
  74. local server = rednet.lookup(args[3], "25674")
  75. if server then
  76. if nnfile then
  77. local filea = fs.open("sshnickname", "r")
  78. local bc = filea.readLine()..": "..args[2]
  79. filea.close()
  80. rednet.broadcast(bc, args[3])
  81. print("Broadcasted: ", bc, " to: \"", args[3],":",args[4], "\"")
  82. else
  83. rednet.broadcast(args[2], args[3])
  84. print("Broadcasted: ", args[2], " to: \"", args[3],":",args[4], "\"")
  85. end
  86. else
  87. print("Error: Secure shell server does not exist!")
  88. end
  89. end
  90.  
  91. else
  92. if args[1] == "open" then
  93. local id = os.getComputerID()
  94. if #args == 1 then
  95. print("Trying to open on id: ", id, " Port: 25674")
  96. rednet.open("top")
  97. local ids = tostring(id)
  98. rednet.host(ids, "25674")
  99. else
  100. print("Trying to open on id: ", id, " Port: ", args[2])
  101. rednet.open("top")
  102. local ids = tostring(id)
  103. rednet.host(ids, args[2])
  104. end
  105. else
  106. if #args == 1 then
  107. ip = tonumber(args[1])
  108. print("Trying: ", args[1])
  109. rednet.open("top")
  110. local server = rednet.lookup(args[1], "25674")
  111. if server then
  112. print("Entering secure shell server!")
  113. function recv()
  114. while true do
  115. local id, rec = rednet.receive("25674",3)
  116. if rednet.lookup(args[1],"25674") then
  117. printError("Connection Terminated: Satalite server is down.")
  118. connterm = true
  119. return
  120. else
  121. end
  122. if rec == nil then
  123.  
  124. else
  125. print("=> "..rec)
  126. write(">")
  127. end
  128. end
  129. end
  130. function send()
  131. write("> ")
  132. input = read()
  133. if starts(input,"/") then
  134. rednet.send(ip, input, "25674")
  135. else
  136. rednet.send(ip, input, "25674")
  137. end
  138. end
  139. while true do
  140. parallel.waitForAny(recv,send)
  141. if connterm == true then
  142. break
  143. end
  144. end
  145. print("Error: Secure shell server does not exist!")
  146. end
  147. else if #args == 2 then
  148. ip = tonumber(args[1])
  149. local portbb = tostring(args[2])
  150. print("Trying: ", args[1], " port:", args[2])
  151. rednet.open("top")
  152. local server = rednet.lookup(args[1], args[2])
  153. if server then
  154. print("Entering secure shell server!")
  155. function recv()
  156. while true do
  157. local id, rec = rednet.receive(args[2],3)
  158. if rednet.lookup(portbb,tostring(ip)) then
  159. printError("Connection Terminated: Satalite server is down.")
  160. connterm = true
  161. return
  162. else
  163. end
  164. if rec == nil then
  165.  
  166. else
  167. print("=> "..rec)
  168. write(">")
  169. end
  170. end
  171. end
  172. function send()
  173. write("> ")
  174. input = read()
  175. if starts(input,"/") then
  176. rednet.send(ip, input, args[2])
  177. else
  178. rednet.send(ip, input, args[2])
  179. end
  180. end
  181. while true do
  182. parallel.waitForAny(recv,send)
  183. if connterm == true then
  184. break
  185. end
  186. end
  187. else
  188. print("Error: Secure shell server does not exist!")
  189. end
  190. end
  191. end
  192. end
  193. end
  194. end
  195. end
  196. end
  197. end
  198. end
Advertisement
Add Comment
Please, Sign In to add comment