Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term = require("term")
- local gpu = require("tty").gpu()
- local thread = require("thread")
- local event = require("event")
- local component = require("component")
- local _, h = gpu.getResolution()
- local output = {}
- local ok
- local gerti
- local cfg
- local data
- local hash
- local encrypt
- local decrypt
- if not component.isAvailable("data") then
- io.stderr:write("Data card unavailable.")
- os.exit(1)
- else
- data = component.data
- if not data.sha256 then
- io.stderr:write("SHA-256 not available.")
- os.exit(1)
- end
- if not data.encrypt then
- io.stderr:write("AES-128 encryption not available.")
- os.exit(1)
- end
- hash = data.sha256
- encrypt = data.encrypt
- decrypt = data.decrypt
- end
- ok, gerti = pcall(require, "GERTiClient")
- if not ok then
- io.stderr:write("Could not load GERTi.")
- os.exit(1)
- end
- ok, cfg = pcall(require, "osu.config")
- if not ok then
- io.stderr:write("Could not load config.")
- os.exit(1)
- end
- if not cfg.remsec.enabled then
- io.stderr:write("RemSec is disabled on this computer.")
- os.exit(1)
- end
- if not gerti.getAddress() then
- io.stderr:write("No connection to MNC.")
- os.exit(1)
- end
- socket = gerti.openSocket(cfg.remsec.address)
- term.clear()
- local main = thread.create(function()
- event.pull("GERTData")
- txt = socket:read()
- print(txt[1])
- while true do
- term.setCursor(1, h)
- io.write("> ")
- cmd = io.read()
- socket:write(encrypt(hash(cfg.remsec.checksumtext), tostring(cfg.remsec.key), tostring(cfg.remsec.iv)))
- socket:write(encrypt(cmd, tostring(cfg.remsec.key), tostring(cfg.remsec.iv)))
- _, addr = event.pull("GERTData")
- if not addr == cfg.remsec.address then
- return
- else
- term.clear()
- txt = socket:read()
- output[#output+1] = txt[1]
- if #output == h-1 then
- for _, text in pairs(output) do
- print(text)
- end
- output = {}
- else
- for _, text in pairs(output) do
- print(text)
- end
- end
- end
- end
- end)
- local safeExit = thread.create(function()
- event.pull("interrupted")
- socket:close()
- end)
- local detectClosure = thread.create(function()
- event.pull("GERTConnectionClose")
- print("Server closed connection, exiting.")
- socket:close()
- end)
- thread.waitForAny({safeExit, detectClosure, main})
- os.exit()
Advertisement
Add Comment
Please, Sign In to add comment