Firestorm002

PassLockBasic 1.0 [BUG FREE]

Nov 16th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.98 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --[[Variables]]--
  3. local w,h = term.getSize()
  4. local x = 0
  5. local y = 0
  6. local z = 0
  7. local f2 = 0
  8. local f = 0
  9. local g = 0
  10. local pa = 0
  11. --[[Functions]]--
  12. function clear()
  13.   term.clear()
  14. end
  15.  
  16. function write(str,x2,y2)
  17.   term.setCursorPos(x2,y2)
  18.   term.write(str)
  19. end
  20.  
  21. function cwrite(str,y2)
  22.   term.setCursorPos(w/2 - #str/2,y2)
  23.   term.write(str)
  24. end
  25.  
  26. function title(str)
  27.   cwrite(string.rep("-",w),1)
  28.   cwrite(str,2)
  29.   cwrite(string.rep("-",w),3)
  30. end
  31.  
  32. function firstBootTitle()
  33.   cwrite(string.rep("-",w),1)
  34.   cwrite("<Installer Setup>",2)
  35.   cwrite(string.rep("-",w),3)
  36. end
  37.  
  38. function optionsTitle()
  39.   cwrite(string.rep("-",w),1)
  40.   cwrite("<Options>",2)
  41.   cwrite(string.rep("-",w),3)
  42. end
  43.  
  44. function DoTOptions()
  45.   cwrite("What will you be locking today?",5)
  46.   cwrite("Press 'A' for 'Computer'.",7)
  47.   cwrite("Press 'B' for 'Door'.",8)
  48.   while x == 0 do
  49.     eva,p1a = os.pullEvent("char")
  50.     if p1a == "a" then
  51.       hel = fs.open("PassLockFiles/DoT","w")
  52.       hel.write("term")
  53.       hel.close()
  54.       x = x + 1
  55.     elseif p1a == "b" then
  56.       hel = fs.open("PassLockFiles/DoT","w")
  57.       hel.write("door")
  58.       hel.close()
  59.       x = x + 1
  60.     end
  61.   end
  62. end
  63.  
  64. function doorSideOption()
  65.   cwrite("What side is your door on?",5)
  66.   cwrite("Press 'A' for 'Left'.",7)
  67.   cwrite("Press 'B' for 'Right'.",8)
  68.   cwrite("Press 'C' for 'Top'.",9)
  69.   cwrite("Press 'D' for 'Bottom'.",10)
  70.   hbl = fs.open("PassLockFiles/doorSide","w")
  71.   while y == 0 do
  72.     ev,p1 = os.pullEvent("char")
  73.     if p1 == "a" then
  74.       hbl.write("left")
  75.       y = y + 1
  76.     elseif p1 == "b" then
  77.       hbl.write("right")
  78.       y = y + 1
  79.     elseif p1 == "c" then
  80.       hbl.write("top")
  81.       y = y + 1
  82.     elseif p1 == "d" then
  83.       hbl.write("bottom")
  84.       y = y + 1
  85.     end
  86.   end
  87.   hbl.close()
  88. end
  89.  
  90. function passwordOption()
  91.   while z == 0 do
  92.     clear()
  93.     title("<PASSWORD CENTER>")
  94.     term.setCursorPos(3,7)
  95.     term.write("NEW PASSWORD: ")
  96.     chpass = read("*")
  97.     term.setCursorPos(3,9)
  98.     term.write("RETYPE PASSWORD: ")
  99.     ch2pass = read("*")
  100.     if chpass == ch2pass then
  101.       clear()
  102.       title("<PASSWORD SET!>")
  103.       hb = fs.open("PassLockFiles/PWFile","w")
  104.       hb.write(ch2pass)
  105.       hb.close()
  106.       sleep(2)
  107.       clear()
  108.       z = z + 1
  109.     else
  110.       clear()
  111.       title("<PASSWORDS DON'T MATCH. TRY AGAIN.>")
  112.       sleep(2)
  113.       clear()
  114.     end
  115.   end
  116.   z = z - 1
  117. end
  118.  
  119. function optionMenu()
  120.   while f2 == 0 do
  121.     clear()
  122.     title("<OPTIONS>")
  123.     cwrite("Press 'A' to change password.",7)
  124.     cwrite("Press 'U' to uninstall PassLockBasic.",9)
  125.     cwrite("Press 'E' to exit.",11)
  126.     ev,p1 = os.pullEvent("char")
  127.     if p1 == "a" then
  128.       passwordOption()
  129.       clear()
  130.     elseif p1 == "u" then
  131.       clear()
  132.       logo(8)
  133.       cwrite("Uninstalling...",4)
  134.       fs.delete("PassLockFiles")
  135.       fs.delete("startup")
  136.       if fs.exists("logoff") then
  137.         fs.delete("logoff")
  138.       end
  139.       sleep(2)
  140.       clear()
  141.       cwrite("Uninstalled.",4)
  142.       logo(8)
  143.       sleep(1)
  144.       cwrite("Rebooting system to finalize uninstall...",4)
  145.       logo(8)
  146.       sleep(2)
  147.       clear()
  148.       os.reboot()
  149.     elseif p1 == "e" then
  150.       f2 = f2 + 1
  151.       clear()
  152.     end
  153.   end
  154.   f2 = f2 - 1
  155. end
  156.  
  157. function openDoor(side)
  158.   rs.setOutput(side,true)
  159.   sleep(2)
  160.   rs.setOutput(side,false)
  161. end
  162.  
  163. function logo(ht)
  164.   write("____________________________________________",4,ht)
  165.   write("  ________________________________________  ",4,ht + 1)
  166.   write("||        _______    ___        ___       ||",4,ht + 2)
  167.   write("||       /   o  /   /  /       / o \\      ||",4,ht + 3)
  168.   write("||      /  /---/   /  /       /  __/      ||",4,ht + 4)
  169.   write("||     /  /       /  /___    /  o  \\      ||",4,ht + 5)
  170.   write("||    /__/       /______/   /______/      ||",4,ht + 6)
  171.   write("||________________________________________||",4,ht + 7)
  172.   write("____________________________________________",4,ht + 8)
  173. end
  174. --[[Startup Checks]]--
  175. clear()
  176. logo(5)
  177. sleep(3)
  178.  
  179. if fs.exists("PassLockFiles") == false then
  180.   fs.makeDir("PassLockFiles")
  181. end
  182.  
  183. if fs.exists("PassLockFiles/PassLockBasic") == false then
  184.   fs.copy(shell.getRunningProgram(),"PassLockFiles/PassLockBasic")
  185.   su = fs.open("startup","w")
  186.   su.write("shell.run(\"PassLockFiles/PassLockBasic\")")
  187.   su.close()
  188. end
  189.  
  190. if fs.exists("PassLockFiles/DoT") == false then
  191.   h15 = fs.open("PassLockFiles/DoT","w")
  192.   h15.close()
  193. end
  194.  
  195. if fs.exists("PassLockFiles/firstBoot") == false then
  196.   h = fs.open("PassLockFiles/firstBoot","w")
  197.   h.write("1")
  198.   h.close()
  199. end
  200.  
  201. if fs.exists("PassLockFiles/doorSide") == false then
  202.   h13 = fs.open("PassLockFiles/doorSide","w")
  203.   h13.close()
  204. end
  205.  
  206. if fs.exists("PassLockFiles/PWFile") == false then
  207.   h14 = fs.open("PassLockFiles/PWFile","w")
  208.   h14.close()
  209. end
  210.  
  211. ha = fs.open("PassLockFiles/firstBoot","r")
  212. ha32 = ha.readAll()
  213. ha.close()
  214. if ha32 == "1" then
  215.   clear()
  216.   firstBootTitle()
  217.   DoTOptions()
  218.   clear()
  219.   ha3 = fs.open("PassLockFiles/DoT","r")
  220.   ha3a = ha3.readAll()
  221.   ha3.close()
  222.   if ha3a == "door" then
  223.     firstBootTitle()
  224.     doorSideOption()
  225.   end
  226.   passwordOption()
  227.   ha2 = fs.open("PassLockFiles/firstBoot","w")
  228.   ha2.write("0")
  229.   ha2.close()
  230. end
  231.  
  232. sos = fs.open("PassLockFiles/DoT","r")
  233. sosr = sos.readAll()
  234. sos.close()
  235.  
  236. if sosr == "term" then
  237.   sos3 = fs.open("logoff","w")
  238.   sos3.writeLine("shell.run(\"PassLockFiles/PassLockBasic\")")
  239.   sos3.close()
  240. end
  241.  
  242. clear()
  243. term.setCursorPos(1,1)
  244. --[[Locking Code]]--
  245. while f == 0 do
  246.   d3 = fs.open("PassLockFiles/DoT","r")
  247.   d3a = d3.readAll()
  248.   d3.close()
  249.   clear()
  250.   if d3a == "term" then
  251.     title("<LOCKED TERMINAL>")
  252.   elseif d3a == "door" then
  253.     title("<LOCKED DOOR>")
  254.   else
  255.     title("<DEBUG MENU>")
  256.   end
  257.   write(string.rep("-",w),1,7)
  258.   logo(9)
  259.   term.setCursorPos(3,5)
  260.   term.write("PASSWORD: ")
  261.   pass = read("*")
  262.   h3 = fs.open("PassLockFiles/PWFile","r")
  263.   h3a = h3.readAll()
  264.   if pass == h3a then
  265.     pa = 0
  266.     while g == 0 do
  267.       clear()
  268.       title("<PASS LOCK MENU>")
  269.       cwrite("Press 'U' to unlock.",5)
  270.       cwrite("Press 'O' to goto options.",6)
  271.       cwrite("Press 'E' to exit.",7)
  272.       logo(9)
  273.       ev,p1 = os.pullEvent("char")
  274.       if p1 == "u" then
  275.     g = g + 1
  276.     k2 = fs.open("PassLockFiles/DoT","r")
  277.     k2a = k2.readAll()
  278.     k2.close()
  279.     ds2 = fs.open("PassLockFiles/doorSide","r")
  280.         ds2a = ds2.readAll()
  281.     ds2.close()
  282.         if k2a == "term" then
  283.           f = f + 1
  284.           clear()
  285.           title("<TERMINAL UNLOCKED>")
  286.           cwrite("Type 'logoff' when you are done to",5)
  287.           cwrite("lock your computer.",6)
  288.           logo(9)
  289.           sleep(4)
  290.           clear()
  291.           term.setCursorPos(1,1)
  292.         elseif k2a == "door" then
  293.           clear()
  294.           title("<DOOR UNLOCKED>")
  295.           logo(9)
  296.           if ds2a == "left" then
  297.             rs.setOutput("left",true)
  298.             sleep(2)
  299.         rs.setOutput("left",false)
  300.           elseif ds2a == "right" then
  301.             rs.setOutput("right",true)
  302.         sleep(2)
  303.         rs.setOutput("right",false)
  304.           elseif ds2a == "top" then
  305.             rs.setOutput("top",true)
  306.         sleep(2)
  307.         rs.setOutput("top",false)
  308.           elseif ds2a == "bottom" then
  309.             rs.setOutput("bottom",true)
  310.             sleep(2)
  311.         rs.setOutput("bottom",false)
  312.           else
  313.             cwrite("DOORSIDE ERROR.",7)
  314.           end
  315.           clear()
  316.         end
  317.       clear()
  318.       elseif p1 == "o" then
  319.         optionMenu()
  320.       elseif p1 == "e" then
  321.         clear()
  322.         g = g + 1
  323.       end
  324.     end
  325.     g = 0
  326.   else
  327.     clear()
  328.     pa = pa + 1
  329.     if pa > 2 then
  330.       title("TOO MANY WRONG ATTEMPTS, SHUTTING DOWN...")
  331.       logo(9)
  332.       sleep(2)
  333.       os.shutdown()
  334.     else
  335.       title("WRONG PASSWORD. TRY AGAIN.")
  336.       logo(9)
  337.       sleep(2)
  338.     end
  339.   end
  340. end
  341. clear()
  342. title("<Booting Up CraftOS...>")
  343. sleep(1.5)
  344. cwrite("Welcome, User!",8)
  345. sleep(1)
  346. clear()
  347. term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment