Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Loading AES encryption functions. AES API ported to CC by SquidDev. Thanks heaps!
- local apipath
- if shell then apipath = fs.combine(shell.dir(),"aes") else apipath = "" end
- if (not aes) and (not fs.exists(apipath)) then
- print("AES API not found! Downloading...")
- local prog = http.get("http://pastebin.com/raw/9E5UHiqv")
- if not prog then error("FAIL!") end
- local file = fs.open(apipath,"w")
- file.write(prog.readAll())
- file.close()
- end
- if not aes then
- local res = os.loadAPI(apipath)
- if not res then error("Didn't load AES API!") end
- end
- --In case I use an API that uses a different syntax than (msg, key)
- local encrite = function(msg, key)
- return aes.encrypt(key, msg)
- end
- local decrite = function(msg, key)
- return aes.decrypt(key, msg)
- end
- local encode = function(txt) --converts string into a table of each character's byte code
- if type(txt) ~= "string" then return false, "requires string" end
- return {txt:byte(1,-1)}
- end
- local decode = function(tbl) --converts an encoded string into something useful.
- if type(tbl) ~= "table" then return false, "requires table" end
- return string.char(tableunpack(tbl))
- end
- local strcapsule = function(txt)
- return "\""..tostring(txt).."\""
- end
- local cwrite = function(txt,setY,doClearLine)
- local scr_x, scr_y = termgetSize()
- local x,y = termgetCursorPos()
- termsetCursorPos((scr_x/2)-(#txt/2),setY or y)
- if doClearLine then termclearLine() end
- write(txt)
- end
- local waitForModem = function()
- local mod
- while true do
- sleep(0.2)
- mod = peripheral.find("modem")
- if mod then
- return mod
- end
- end
- end
- if not peripheral.find("modem") then
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- termclear()
- cwrite("Encmail requires a modem.",3)
- cwrite("Add one, or press a key.",4)
- sleep(0.1)
- local outcome = parallelwaitForAny(function() os.pullEvent("key") end, waitForModem)
- modems = {peripheral.find("modem")}
- if #modems == 0 then
- termsetBackgroundColor(colors.black)
- termsetCursorPos(1,scr_y)
- termclearLine()
- sleep(0)
- return false
- end
- end
- local modemOpen = function(chan)
- for a = 1, #modems do
- modems[a].open(chan)
- end
- end
- local modemClose = function(chan)
- for a = 1, #modems do
- modems[a].close(chan)
- end
- end
- local modemTransmit = function(chan,repchan,msg)
- for a = 1, #modems do
- modems[a].transmit(chan,repchan,msg)
- end
- end
- local tsv = function(visible)
- if termcurrent then if termcurrent().setVisible then termcurrent().setVisible(visible) return true else return false end else return false end
- end
- local maindir = ".encmail"
- local userdir = fs.combine(maindir,"users")
- local configpath = fs.combine(maindir,"config")
- local readConfig = function()
- dofile(configpath)
- end
- local writeConfig = function() --writes current values to config, no arguments needed!
- local file = fs.open(configpath,"w")
- file.writeLine("--This config file will store any variables I want persistant.")
- file.writeLine("--Do not modify while running! It won't do a thing!")
- file.close()
- end
- local fenv = getfenv()
- readConfig()
- local newfenv = getfenv()
- local newvars = {}
- for k,v in pairs(newfenv) do
- if not fenv[k] then
- newvars[k] = v
- end
- end
- listUsers = function()
- return fs.list(userdir)
- end
- listMail = function(user)
- if not fs.isDir(fs.combine(userdir,user)) then
- return false, "No such user"
- end
- local output = {}
- local path = fs.list(fs.combine(userdir,user))
- end
Add Comment
Please, Sign In to add comment