Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Set up everything
- local args = {...}
- local data = {}
- local files = 0
- local cursor = 0
- --Open file and read contens into array
- local file = fs.open(args[1],"r")
- local ln = ""
- while true do
- ln = file.readLine()
- if ln then
- data[#data+1] = ln
- else
- break
- end
- end
- file.close()
- file = nil
- ln = nil
- --Get amount of files stored
- for i=1,#data,1 do
- if data[i] == "NEWFILE" then
- files = files+1
- end
- end
- print("Files found: "..files)
- --Dump function
- local function dmp(s,c)
- local newfile = fs.open(s,"w")
- for i=1,#c,1 do
- newfile.writeLine(c[i])
- end
- newfile.close()
- print("Created file \""..s.."\"")
- return
- end
- --Goto file function
- local function nextfile()
- repeat
- cursor = cursor +1
- until data[cursor] == "NEWFILE"
- end
- --Read specific file
- for i=1,files,1 do
- nextfile() --Goto next file
- local cfile = {}
- cursor = cursor +1
- local name = data[cursor]
- cursor = cursor +1
- repeat
- cfile[#cfile+1] = data[cursor]
- cursor = cursor +1
- until data[cursor] == "EOF"
- dmp(name,cfile)
- end
- --[[
- NEWFILE
- startup
- shell.run("SecOS")
- EOF
- NEWFILE
- SecOS
- os.pullEvent = os.pullEventRaw
- local username, passwd = ""
- local run = true
- local status = ""
- local w,h = term.getSize()
- os.loadAPI("/secure")
- local function drawHeader()
- local w,h = term.getSize()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- term.clearLine()
- term.write("SecOS running")
- local s = textutils.formatTime(os.time())
- term.setCursorPos(w-string.len(s)+1,1)
- term.write(s)
- term.setCursorPos(1,3)
- end
- local function drawStatus()
- local x,y = term.getCursorPos()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(math.floor((w/2)-(string.len(status)/2)),h)
- term.clearLine()
- term.write(status)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(x,y)
- end
- local function updateStatus()
- drawStatus()
- if (not (status == "")) then
- sleep(1)
- status = ""
- drawStatus()
- end
- end
- local function login()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,3)
- term.clearLine()
- term.write("Username: ")
- username = read(nil,nil,nil)
- if (username == "exit") then
- run = false
- return
- end
- term.setCursorPos(1,4)
- term.clearLine()
- term.write("Password: ")
- passwd = read("*",nil,nil)
- if (secure.resolvePass(username,passwd)) then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- status = "Login successful!"
- run = false
- return
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,4)
- term.clearLine()
- status = "Login failed!"
- run = true
- return
- end
- end
- term.clear()
- drawStatus()
- while (run) do
- parallel.waitForAll(drawHeader,updateStatus,login)
- end
- updateStatus()
- term.setCursorPos(1,1)
- term.clear()
- os.unloadAPI("secure")
- usernamee = nil
- passwd = nil
- EOF
- NEWFILE
- secure
- function encode(sInput)
- local encoded = ""
- local value = 0
- for i=1,string.len(sInput),1 do
- value = value+string.byte(string.sub(sInput,i,i))
- end
- for i=1,string.len(sInput),1 do
- encoded = encoded..tostring(string.byte(string.sub(sInput,i,i))*value)
- end
- return encoded
- end
- function resolvePass(username2, passwd2)
- if (not (fs.exists("/users/"..username2..".usr"))) then
- return false
- end
- local file = fs.open("/users/"..username2..".usr","r")
- chars = tostring(file.readLine())
- file.close()
- if (chars == secure.encode(passwd2)) then
- return true
- else
- return false
- end
- end
- EOF
- NEWFILE
- mkusr
- os.loadAPI("secure")
- term.write("Root password: ")
- local pass = read("*",nil,nil)
- local file = fs.open("/users/root.usr","r")
- local code = file.readLine()
- file.close()
- if (code == secure.encode(pass)) then
- else
- print("Password incorrect!")
- return
- end
- term.write("New user: ")
- user = read(nil,nil,nil)
- term.write("New password: ")
- pass = read("*",nil,nil)
- if (fs.exists("/users/"..user..".usr")) then
- print("This user already exists!")
- return
- end
- local file = fs.open("/users/"..user..".usr","w")
- file.write(secure.encode(pass))
- file.close()
- print("User successfully created!")
- os.unloadAPI("secure")
- return
- EOF
- NEWFILE
- passwd
- local args = {...}
- local name, pass = ""
- os.loadAPI("secure")
- term.write("Username: ")
- name = read(nil,nil,nil)
- term.write("Password: ")
- pass = read("*",nil,nil)
- if (not fs.exists("/users/"..name..".usr")) then
- print("User not found!")
- return
- end
- local file = fs.open("/users/"..name..".usr","r")
- local code = file.readLine()
- file.close()
- if (code == secure.encode(pass)) then
- print("Password correct!")
- else
- print("Password incorrect!")
- return
- end
- term.write("New password: ")
- pass = read("*",nil,nil)
- local file = fs.open("/users/"..name..".usr","w")
- file.write(secure.encode(pass))
- file.close()
- print("Password successfully changed!")
- os.unloadAPI("secure")
- return
- 51528501725017252432
- EOF
- NEWFILE
- /users/root.usr
- 51528501725017252432
- EOF
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement