Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Remote Terminal
- by BigShinyToys
- OPEN SOURCE CODE (no rights reserved)
- ]]--
- tArgs = {...}
- if #tArgs == 0 then
- elseif tArgs[1] == "reboot" then
- os.reboot()
- elseif tArgs[1] == "shutdown" then
- os.shutdown()
- elseif tArgs[1] == "restore" then
- function os.pullEventRaw( _sFilter )
- return coroutine.yield( _sFilter )
- end
- term.restore()
- print("Closed Sestion")
- return
- elseif tArgs[1] == "logoff" then
- function os.pullEventRaw( _sFilter )
- return coroutine.yield( _sFilter )
- end
- term.restore()
- print("Closed Sestion")
- end
- UserID = -1
- -- user names tha have access
- local Authenticate = {
- ted = "hello",
- harry = "hello2"
- }
- local function openRednet()
- local listOfSides = rs.getSides()
- for i = 1,6 do
- if peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem" then
- rednet.open(listOfSides[i])
- return listOfSides[i]
- end
- end
- end
- modemOn = openRednet()
- if not modemOn then
- print("No WIFI ModemnPress any key to return to exit")
- os.pullEvent("key")
- return
- end
- function os.pullEventRaw(...)
- local e1,e2,e3,e4,e5 = coroutine.yield(...)
- if e1 == "rednet_message" and e2 == UserID then
- local a = string.sub(e3,1,3)
- if a == "key" then
- return "key",tonumber(string.sub(e3,4,string.len(e3)))
- elseif a == "cha" then
- return "char",string.sub(e3,4,4)
- end
- end
- return e1,e2,e3,e4,e5
- end
- remote = {}
- function remote.write(s)
- rednet.send(UserID,"WRT"..s)
- end
- function remote.clear()
- rednet.send(UserID,"CLR")
- end
- function remote.clearLine()
- rednet.send(UserID,"CLL")
- end
- function remote.setCursorBlink(s)
- rednet.send(UserID,"SCB"..tostring(s))
- end
- function remote.setCursorPos(x,y)
- rednet.send(UserID,"SCP"..textutils.serialize({x,y}))
- end
- function remote.getSize()
- rednet.send(UserID,"GSZ")
- while true do
- local w1,w2,w3 = os.pullEvent("rednet_message")
- if string.sub(w3,1,3) == "SIZ" then
- local a = textutils.unserialize(string.sub(w3,4,string.len(w3)))
- return a[1],a[2]
- end
- end
- end
- function remote.getCursorPos()
- rednet.send(UserID,"GCP")
- while true do
- local w1,w2,w3 = os.pullEvent("rednet_message")
- if string.sub(w3,1,3) == "POS" then
- local a = textutils.unserialize(string.sub(w3,4,string.len(w3)))
- return a[1],a[2]
- end
- end
- end
- function remote.scroll(nLines)
- rednet.send(UserID,"SCR"..tostring(nLines))
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Remote Terminal Started")
- while true do
- local q1,q2,q3,q4,q5 = os.pullEvent()
- print(tostring(q1).." "..tostring(q2))
- if q1 == "rednet_message" then
- local test = string.sub(q3,1,12)
- if test == "RMTLOGINREQ:" then
- local uDAT = textutils.unserialize(string.sub(q3,13,string.len(q3)))
- if Authenticate[uDAT[1]] == uDAT[2] then
- term.clear()
- term.setCursorPos(1,1)
- print("User "..tostring(uDAT[1]).." Online")
- rednet.send(q2,"Request Accepted")
- sleep(1)
- UserID = q2
- term.redirect(remote)
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- end
- end
- end
- print("Open Connection")
Add Comment
Please, Sign In to add comment