Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- --[[Variables]]--
- local w,h = term.getSize()
- local x = 0
- local y = 0
- local z = 0
- local f2 = 0
- local f = 0
- local g = 0
- local pa = 0
- --[[Functions]]--
- function clear()
- term.clear()
- end
- function write(str,x2,y2)
- term.setCursorPos(x2,y2)
- term.write(str)
- end
- function cwrite(str,y2)
- term.setCursorPos(w/2 - #str/2,y2)
- term.write(str)
- end
- function title(str)
- cwrite(string.rep("-",w),1)
- cwrite(str,2)
- cwrite(string.rep("-",w),3)
- end
- function firstBootTitle()
- cwrite(string.rep("-",w),1)
- cwrite("<Installer Setup>",2)
- cwrite(string.rep("-",w),3)
- end
- function optionsTitle()
- cwrite(string.rep("-",w),1)
- cwrite("<Options>",2)
- cwrite(string.rep("-",w),3)
- end
- function DoTOptions()
- cwrite("What will you be locking today?",5)
- cwrite("Press 'A' for 'Computer'.",7)
- cwrite("Press 'B' for 'Door'.",8)
- while x == 0 do
- eva,p1a = os.pullEvent("char")
- if p1a == "a" then
- hel = fs.open("PassLockFiles/DoT","w")
- hel.write("term")
- hel.close()
- x = x + 1
- elseif p1a == "b" then
- hel = fs.open("PassLockFiles/DoT","w")
- hel.write("door")
- hel.close()
- x = x + 1
- end
- end
- end
- function doorSideOption()
- cwrite("What side is your door on?",5)
- cwrite("Press 'A' for 'Left'.",7)
- cwrite("Press 'B' for 'Right'.",8)
- cwrite("Press 'C' for 'Top'.",9)
- cwrite("Press 'D' for 'Bottom'.",10)
- hbl = fs.open("PassLockFiles/doorSide","w")
- while y == 0 do
- ev,p1 = os.pullEvent("char")
- if p1 == "a" then
- hbl.write("left")
- y = y + 1
- elseif p1 == "b" then
- hbl.write("right")
- y = y + 1
- elseif p1 == "c" then
- hbl.write("top")
- y = y + 1
- elseif p1 == "d" then
- hbl.write("bottom")
- y = y + 1
- end
- end
- hbl.close()
- end
- function passwordOption()
- while z == 0 do
- clear()
- title("<PASSWORD CENTER>")
- term.setCursorPos(3,7)
- term.write("NEW PASSWORD: ")
- chpass = read("*")
- term.setCursorPos(3,9)
- term.write("RETYPE PASSWORD: ")
- ch2pass = read("*")
- if chpass == ch2pass then
- clear()
- title("<PASSWORD SET!>")
- hb = fs.open("PassLockFiles/PWFile","w")
- hb.write(ch2pass)
- hb.close()
- sleep(2)
- clear()
- z = z + 1
- else
- clear()
- title("<PASSWORDS DON'T MATCH. TRY AGAIN.>")
- sleep(2)
- clear()
- end
- end
- z = z - 1
- end
- function optionMenu()
- while f2 == 0 do
- clear()
- title("<OPTIONS>")
- cwrite("Press 'A' to change password.",7)
- cwrite("Press 'U' to uninstall PassLockBasic.",9)
- cwrite("Press 'E' to exit.",11)
- ev,p1 = os.pullEvent("char")
- if p1 == "a" then
- passwordOption()
- clear()
- elseif p1 == "u" then
- clear()
- logo(8)
- cwrite("Uninstalling...",4)
- fs.delete("PassLockFiles")
- fs.delete("startup")
- if fs.exists("logoff") then
- fs.delete("logoff")
- end
- sleep(2)
- clear()
- cwrite("Uninstalled.",4)
- logo(8)
- sleep(1)
- cwrite("Rebooting system to finalize uninstall...",4)
- logo(8)
- sleep(2)
- clear()
- os.reboot()
- elseif p1 == "e" then
- f2 = f2 + 1
- clear()
- end
- end
- f2 = f2 - 1
- end
- function openDoor(side)
- rs.setOutput(side,true)
- sleep(2)
- rs.setOutput(side,false)
- end
- function logo(ht)
- write("____________________________________________",4,ht)
- write(" ________________________________________ ",4,ht + 1)
- write("|| _______ ___ ___ ||",4,ht + 2)
- write("|| / o / / / / o \\ ||",4,ht + 3)
- write("|| / /---/ / / / __/ ||",4,ht + 4)
- write("|| / / / /___ / o \\ ||",4,ht + 5)
- write("|| /__/ /______/ /______/ ||",4,ht + 6)
- write("||________________________________________||",4,ht + 7)
- write("____________________________________________",4,ht + 8)
- end
- --[[Startup Checks]]--
- clear()
- logo(5)
- sleep(3)
- if fs.exists("PassLockFiles") == false then
- fs.makeDir("PassLockFiles")
- end
- if fs.exists("PassLockFiles/PassLockBasic") == false then
- fs.copy(shell.getRunningProgram(),"PassLockFiles/PassLockBasic")
- su = fs.open("startup","w")
- su.write("shell.run(\"PassLockFiles/PassLockBasic\")")
- su.close()
- end
- if fs.exists("PassLockFiles/DoT") == false then
- h15 = fs.open("PassLockFiles/DoT","w")
- h15.close()
- end
- if fs.exists("PassLockFiles/firstBoot") == false then
- h = fs.open("PassLockFiles/firstBoot","w")
- h.write("1")
- h.close()
- end
- if fs.exists("PassLockFiles/doorSide") == false then
- h13 = fs.open("PassLockFiles/doorSide","w")
- h13.close()
- end
- if fs.exists("PassLockFiles/PWFile") == false then
- h14 = fs.open("PassLockFiles/PWFile","w")
- h14.close()
- end
- ha = fs.open("PassLockFiles/firstBoot","r")
- ha32 = ha.readAll()
- ha.close()
- if ha32 == "1" then
- clear()
- firstBootTitle()
- DoTOptions()
- clear()
- ha3 = fs.open("PassLockFiles/DoT","r")
- ha3a = ha3.readAll()
- ha3.close()
- if ha3a == "door" then
- firstBootTitle()
- doorSideOption()
- end
- passwordOption()
- ha2 = fs.open("PassLockFiles/firstBoot","w")
- ha2.write("0")
- ha2.close()
- end
- sos = fs.open("PassLockFiles/DoT","r")
- sosr = sos.readAll()
- sos.close()
- if sosr == "term" then
- sos3 = fs.open("logoff","w")
- sos3.writeLine("shell.run(\"PassLockFiles/PassLockBasic\")")
- sos3.close()
- end
- clear()
- term.setCursorPos(1,1)
- --[[Locking Code]]--
- while f == 0 do
- d3 = fs.open("PassLockFiles/DoT","r")
- d3a = d3.readAll()
- d3.close()
- clear()
- if d3a == "term" then
- title("<LOCKED TERMINAL>")
- elseif d3a == "door" then
- title("<LOCKED DOOR>")
- else
- title("<DEBUG MENU>")
- end
- write(string.rep("-",w),1,7)
- logo(9)
- term.setCursorPos(3,5)
- term.write("PASSWORD: ")
- pass = read("*")
- h3 = fs.open("PassLockFiles/PWFile","r")
- h3a = h3.readAll()
- if pass == h3a then
- pa = 0
- while g == 0 do
- clear()
- title("<PASS LOCK MENU>")
- cwrite("Press 'U' to unlock.",5)
- cwrite("Press 'O' to goto options.",6)
- cwrite("Press 'E' to exit.",7)
- logo(9)
- ev,p1 = os.pullEvent("char")
- if p1 == "u" then
- g = g + 1
- k2 = fs.open("PassLockFiles/DoT","r")
- k2a = k2.readAll()
- k2.close()
- ds2 = fs.open("PassLockFiles/doorSide","r")
- ds2a = ds2.readAll()
- ds2.close()
- if k2a == "term" then
- f = f + 1
- clear()
- title("<TERMINAL UNLOCKED>")
- cwrite("Type 'logoff' when you are done to",5)
- cwrite("lock your computer.",6)
- logo(9)
- sleep(4)
- clear()
- term.setCursorPos(1,1)
- elseif k2a == "door" then
- clear()
- title("<DOOR UNLOCKED>")
- logo(9)
- if ds2a == "left" then
- rs.setOutput("left",true)
- sleep(2)
- rs.setOutput("left",false)
- elseif ds2a == "right" then
- rs.setOutput("right",true)
- sleep(2)
- rs.setOutput("right",false)
- elseif ds2a == "top" then
- rs.setOutput("top",true)
- sleep(2)
- rs.setOutput("top",false)
- elseif ds2a == "bottom" then
- rs.setOutput("bottom",true)
- sleep(2)
- rs.setOutput("bottom",false)
- else
- cwrite("DOORSIDE ERROR.",7)
- end
- clear()
- end
- clear()
- elseif p1 == "o" then
- optionMenu()
- elseif p1 == "e" then
- clear()
- g = g + 1
- end
- end
- g = 0
- else
- clear()
- pa = pa + 1
- if pa > 2 then
- title("TOO MANY WRONG ATTEMPTS, SHUTTING DOWN...")
- logo(9)
- sleep(2)
- os.shutdown()
- else
- title("WRONG PASSWORD. TRY AGAIN.")
- logo(9)
- sleep(2)
- end
- end
- end
- clear()
- title("<Booting Up CraftOS...>")
- sleep(1.5)
- cwrite("Welcome, User!",8)
- sleep(1)
- clear()
- term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment