Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- function starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- connterm = false
- function usage()
- term.setTextColor(colors.red)
- print("-----------Secure Shell 2.7-----------")
- print("Usage:")
- print("ssh <id> [port]")
- print("ssh open [port]")
- --print("ssh broadcast <message> <id> [port] ")
- print("ssh setnick <nickname>")
- print("ssh testopen <id> [port]")
- print("ssh update")
- print("-----------Secure Shell 2.7-----------")
- term.setTextColor(colors.white)
- end
- if #args < 1 then
- usage()
- else if #args > 4 then
- usage()
- else
- if args[1] == "update" then
- shell.setAlias("pastebin", "/rom/programs/http/pastebin")
- shell.run("pastebin run qHUXSZHg")
- shell.setAlias("pastebin", "/os/un")
- else
- if args[1] == "testopen" then
- rednet.open("top")
- if #args > 2 then
- local server = rednet.lookup(args[2], args[3])
- if server then
- print("That server does exist!")
- else
- print("That server does Not exist!")
- end
- else
- local server = rednet.lookup(args[2], "25674")
- if server then
- print("That server does exist!")
- else
- print("That server does Not exist!")
- end
- end
- else
- if args[1] == "setnick" then
- local file = fs.open("sshnickname", "w")
- file.writeLine(args[2])
- file.close()
- print("Nickname Set As: ", args[2])
- else
- if args[1] == "broadcast" then
- rednet.open("top")
- local nnfile = fs.exists("sshnickname")
- if #args > 3 then
- local server = rednet.lookup(args[3], args[4])
- if server then
- if nnfile then
- local filea = fs.open("sshnickname", "r")
- local bc = filea.readLine()..": "..args[2]
- filea.close()
- rednet.broadcast(bc, args[3])
- print("Broadcasted: ", bc, " to: \"", args[3],":",args[4], "\"")
- else
- rednet.broadcast(args[2], args[3])
- print("Broadcasted: ", args[2], " to: \"", args[3],":",args[4], "\"")
- end
- else
- print("Error: Secure shell server does not exist!")
- end
- else
- local server = rednet.lookup(args[3], "25674")
- if server then
- if nnfile then
- local filea = fs.open("sshnickname", "r")
- local bc = filea.readLine()..": "..args[2]
- filea.close()
- rednet.broadcast(bc, args[3])
- print("Broadcasted: ", bc, " to: \"", args[3],":",args[4], "\"")
- else
- rednet.broadcast(args[2], args[3])
- print("Broadcasted: ", args[2], " to: \"", args[3],":",args[4], "\"")
- end
- else
- print("Error: Secure shell server does not exist!")
- end
- end
- else
- if args[1] == "open" then
- local id = os.getComputerID()
- if #args == 1 then
- print("Trying to open on id: ", id, " Port: 25674")
- rednet.open("top")
- local ids = tostring(id)
- rednet.host(ids, "25674")
- else
- print("Trying to open on id: ", id, " Port: ", args[2])
- rednet.open("top")
- local ids = tostring(id)
- rednet.host(ids, args[2])
- end
- else
- if #args == 1 then
- ip = tonumber(args[1])
- print("Trying: ", args[1])
- rednet.open("top")
- local server = rednet.lookup(args[1], "25674")
- if server then
- print("Entering secure shell server!")
- function recv()
- while true do
- local id, rec = rednet.receive("25674",3)
- if rednet.lookup(args[1],"25674") then
- printError("Connection Terminated: Satalite server is down.")
- connterm = true
- return
- else
- end
- if rec == nil then
- else
- print("=> "..rec)
- write(">")
- end
- end
- end
- function send()
- write("> ")
- input = read()
- if starts(input,"/") then
- rednet.send(ip, input, "25674")
- else
- rednet.send(ip, input, "25674")
- end
- end
- while true do
- parallel.waitForAny(recv,send)
- if connterm == true then
- break
- end
- end
- print("Error: Secure shell server does not exist!")
- end
- else if #args == 2 then
- ip = tonumber(args[1])
- local portbb = tostring(args[2])
- print("Trying: ", args[1], " port:", args[2])
- rednet.open("top")
- local server = rednet.lookup(args[1], args[2])
- if server then
- print("Entering secure shell server!")
- function recv()
- while true do
- local id, rec = rednet.receive(args[2],3)
- if rednet.lookup(portbb,tostring(ip)) then
- printError("Connection Terminated: Satalite server is down.")
- connterm = true
- return
- else
- end
- if rec == nil then
- else
- print("=> "..rec)
- write(">")
- end
- end
- end
- function send()
- write("> ")
- input = read()
- if starts(input,"/") then
- rednet.send(ip, input, args[2])
- else
- rednet.send(ip, input, args[2])
- end
- end
- while true do
- parallel.waitForAny(recv,send)
- if connterm == true then
- break
- end
- end
- else
- print("Error: Secure shell server does not exist!")
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment