Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local connectedClients = {}
- local authentications = {
- {user = "admin", pass = "1234"}
- }
- local ruser = 1
- local pivotSender = nil
- local pivotID = nil
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function out(dat)
- print(dat)
- --rednet.send(ruser,"print(dat)")
- end
- function logout()
- rednet.send(ruser,"print('goodbye!') return")
- end
- function authenticate(user, pass)
- for i,v in ipairs(authentications) do
- if user == v.user and pass == v.pass then
- return true
- end
- end
- return false
- end
- function isConnected(num)
- for i,v in ipairs(connectedClients) do
- if v == num then
- return true
- end
- end
- for i,v in ipairs(peripheral.getNames()) do
- if peripheral.getType(v) == "computer" then
- if num == peripheral.wrap(v).getID() then
- return true
- end
- end
- end
- return false
- end
- for i,v in ipairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- function fakeShell()
- term.setTextColor(colors.yellow)
- term.write("> ")
- term.setTextColor(colors.white)
- input = read()
- shell.run(input)
- end
- function network()
- id,msg,d = rednet.receive()
- if pivotID ~= nil and id == pivotID then
- if type(msg) == "string" and msg == "breakpivot" then
- pivotID = nil
- pivotSender = nil
- else
- rednet.send(pivotSender,msg)
- end
- elseif isConnected(id) then
- if pivotID ~= nil then
- print(textutils.serialise(pivotID))
- rednet.send(pivotID, msg)
- elseif type(msg) == "string" and msg == "breakpivot" then
- rednet.send(id,"breakpivot")
- elseif type(msg) == "table" then
- if msg[1] == "run" then
- shell.run(msg[2])
- elseif msg[1] == "rs" then
- for i,v in ipairs(rs.getSides()) do
- if msg[2] == "on" then
- rs.setOutput(v,true)
- else
- rs.setOutput(v,false)
- end
- end
- elseif msg[1] == "id" then
- rednet.send(id,{"id",os.getComputerID()})
- elseif msg[1] == "peak" then
- if fs.exists(msg[2]) then
- local lines = {}
- local file = fs.open(msg[2],"r")
- while true do
- local line = file.readLine()
- if line == nil then
- break
- else
- table.insert(lines,line)
- end
- end
- rednet.send(id,{"peak",lines})
- else
- rednet.send(id,"print('File does not exist')")
- end
- elseif msg[1] == "getconnected" then
- local ids = {}
- for i,v in ipairs(peripheral.getNames()) do
- if peripheral.getType(v) == "computer" then
- table.insert(ids,peripheral.wrap(v).getID())
- end
- end
- rednet.send(id,{"getconnected",ids})
- elseif msg[1] == "ls" then
- local list = fs.list("/")
- rednet.send(id,{"ls",list})
- elseif msg[1] == "pivot" and type(msg[2]) == "number" then
- print("TRYING TO PIVOT INTO: "..msg[2])
- pivotID = msg[2]
- print(type(pivotID))
- rednet.send(pivotID,"print('hi')")
- id2,msg,d = rednet.receive(.3)
- if msg == nil then
- pivotSender = id
- rednet.send(id,"print() print('PIVOT SUCCESSFUL')")
- else
- pivotID = nil
- end
- end
- else
- ruser = id
- f = loadstring(msg)
- if not pcall(f) then
- rednet.send(ruser, "print('Error with last command')")
- end
- print()
- end
- elseif type(msg) == "table" then
- if msg[1] == "AUTHENTICATE" then
- if authenticate(msg[2],msg[3]) then
- table.insert(connectedClients,id)
- rednet.send(id,"AUTHENTICATED")
- end
- end
- clear()
- else
- rednet.send(id,"AUTHENTICATE")
- clear()
- end
- end
- if fs.exists(".start") then
- fakeShell = function()
- shell.run(".start")
- end
- end
- while true do
- parallel.waitForAny(fakeShell,network)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement