Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- local editing = false
- local exit = false
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- for i,v in ipairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- if args[1] == nil then
- term.setTextColor(colors.white)
- print()
- print("Usage: remoteshell <id>")
- return
- end
- local com = tonumber(args[1])
- rednet.send(com, "print()")
- id,msg,d = rednet.receive(.3)
- if msg ~= nil and msg == "AUTHENTICATE" then
- print()
- print("AUTHENTICATION REQUIRED")
- term.write("Username: ")
- user = read()
- term.write("Password: ")
- pass = read("*")
- rednet.send(com, {"AUTHENTICATE",user,pass})
- id,msg,d = rednet.receive(.3)
- if msg == nil then
- return
- end
- end
- function listen()
- id,msg = rednet.receive()
- if msg == "AUTHENTICATE" then
- error("YOU HAVE BEEN LOGGED OUT")
- elseif msg == "breakpivot" then
- print()
- print("No pivot to break!")
- elseif id == com then
- if type(msg) == "table" then
- if msg[1] == "ls" then
- print()
- print(textutils.serialise(msg[2]))
- elseif msg[1] == "id" then
- print()
- print("HOST ID: "..msg[2])
- elseif msg[1] == "peak" then
- local file = fs.open(".t","w")
- for i,v in ipairs(msg[2]) do
- file.writeLine(v)
- end
- file.close()
- editing = true
- return
- elseif msg[1] == "getconnected" then
- print()
- print(textutils.serialise(msg[2]))
- end
- else
- loadstring(msg)()
- end
- end
- end
- function split(s)
- if s == "" then return {} end
- local t = {}
- for i in string.gmatch(s,"%S+") do
- table.insert(t,i)
- end
- return t
- end
- clear()
- term.setTextColor(colors.red)
- print("YOU ARE NOW IN A REMOTE CONNECTION WITH "..com)
- print("TYPE 'help' FOR HELP")
- function start()
- term.setTextColor(colors.red)
- term.write(" : ")
- term.setTextColor(colors.white)
- local input1 = read()
- local input = split(string.lower(input1))
- if input == {} then
- return
- elseif input[1] == "help" then
- print("remoteshell help")
- print("---------------------")
- term.setTextColor(colors.yellow)
- term.write("print <data>")
- term.setTextColor(colors.white)
- print(": prints out data from the host computer on the client")
- term.setTextColor(colors.yellow)
- term.write("id")
- term.setTextColor(colors.white)
- print(": prints the id of the connected host")
- term.setTextColor(colors.yellow)
- term.write("ls")
- term.setTextColor(colors.white)
- print(": lists files on host computer")
- term.setTextColor(colors.yellow)
- term.write("run <file>")
- term.setTextColor(colors.white)
- print(": runs specified file on host and prints the return val")
- term.setTextColor(colors.yellow)
- term.write("peak <file>")
- term.setTextColor(colors.white)
- print(": peaks at a file")
- term.setTextColor(colors.yellow)
- term.write("getconnected")
- term.setTextColor(colors.white)
- print(": prints computer ids connected to host")
- term.setTextColor(colors.yellow)
- term.write("pivot <id>")
- term.setTextColor(colors.white)
- print(": remotely connects to the specified id")
- term.setTextColor(colors.yellow)
- term.write("breakpivot")
- term.setTextColor(colors.white)
- print(": breaks pivot (:O)")
- term.setTextColor(colors.yellow)
- term.write("rs on/off")
- term.setTextColor(colors.white)
- print(": turns all rs sides on or off")
- term.setTextColor(colors.yellow)
- term.write("logout")
- term.setTextColor(colors.white)
- print(": logs out of remoteshell")
- elseif input[1] == "logout" then
- exit = true
- elseif input[1] == "peak" then
- if input[2] ~= nil then
- rednet.send(com,{"peak",input[2]})
- end
- elseif input[1] == "rs" then
- if input[2] == "on" then
- rednet.send(com,{"rs","on"})
- elseif input[2] == "off" then
- rednet.send(com,{"rs","off"})
- end
- elseif input[1] == "id" then
- rednet.send(com,{"id"})
- elseif input[1] == "getconnected" then
- rednet.send(com,{"getconnected"})
- elseif input[1] == "pivot" then
- if type(tonumber(input[2])) == "number" then
- rednet.send(com,{"pivot",tonumber(input[2])})
- end
- elseif input[1] == "run" then
- rednet.send(com, {"run",input[2]})
- elseif input[1] == "ls" then
- rednet.send(com,{"ls"})
- elseif input[1] == "print" then
- local s = ""
- for i,v in ipairs(input) do
- if i == 2 then
- s = v
- elseif i ~= 1 then
- s = s + " " + v
- end
- end
- local send = "rednet.send("..os.getComputerID()..",'print('..textutils.serialise("..s..")..')')"
- rednet.send(com, send)
- else
- rednet.send(com, input1)
- end
- end
- while true do
- parallel.waitForAny(start,listen)
- if editing then
- shell.run("edit",".t")
- clear()
- fs.delete(".t")
- editing = false
- end
- if exit then
- clear()
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement