Advertisement
dannysmc95

uLock

Mar 20th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. -- Simple Door Lock
  2. -- Created by DannySMc
  3. -- Version 1.2
  4. -- Platform: Lua Virtual Machine
  5.  
  6. -- Security Method
  7. oldEvent = os.pullEvent
  8. os.pullEvent = os.pullEventRaw
  9.  
  10. -- Check for API
  11. if fs.exists("uapi") == false then
  12.   print("Missing uAPI!")
  13.   print("Attempting to download..")
  14.   getGit = http.get("https://raw.github.com/dannysmc95/uprograms/master/uapi")
  15.   getGit = getGit.readAll()
  16.   file = fs.open("uapi", "w")
  17.   file.write(getGit)
  18.   file.close()
  19.   print("Done!")
  20.   sleep(0.5)
  21. end
  22. os.loadAPI("uapi")
  23.  
  24. -- Installer for Configuration File
  25. if fs.exists(".uLockConf") == false then
  26.   uapi.cs()
  27.   print("Running Installer...")
  28.   sleep(0.5)
  29.   term.setCursorPos(1,3)
  30.   term.write("Redstone output side: ")
  31.   strSide = read()
  32.   term.setCursorPos(1,5)
  33.   term.write("Redstone pulse time: ")
  34.   strPulse = tonumber(read())
  35.   term.setCursorPos(1,7)
  36.   term.write("Terminal Label: ")
  37.   strName = read()
  38.   term.setCursorPos(1,9)
  39.   term.write("Password for unlock: ")
  40.   strPassword = read("*")
  41.   term.setCursorPos(1,11)
  42.   print("What is the name this program is saved as?")
  43.   term.setCursorPos(1,12)
  44.   term.write("Program Name: ")
  45.   strProgName = read()
  46.  
  47.   strPassword = uapi.checksum(strPassword, 1000)
  48.  
  49.   -- Create Configuration File
  50.   uapi.saveConfig({['progName']=strProgName, ['terminalName']=strName, ['redSide']=strSide, ['redPulse']=strPulse, ['lockPassword']=strPassword}, ".uLockConf")
  51.  
  52.   -- Startup File
  53.   term.setCursorPos(1,14)
  54.   print("Do you wish to create a startup file?")
  55.   term.setCursorPos(1,15)
  56.   repeat
  57.   term.write("YES/NO: ")
  58.   startupAnswer = read()
  59.   until ((startupAnswer == "YES") or (startupAnswer == "NO"))
  60.  
  61.   if startupAnswer == "YES" then
  62.     startFile = fs.open("startup", "w")
  63.     startFile.writeLine('os.loadAPI("uapi")')
  64.     startFile.writeLine('config = uapi.loadConfig(".uLockConf")')
  65.     startFile.writeLine("shell.run(config.progName)")
  66.     startFile.close()
  67.     print("Install Complete!")
  68.     sleep(0.5)
  69.   else
  70.     print("Install Complete!")
  71.     sleep(0.5)
  72.   end
  73.  
  74.   print("Rebooting the terminal...")
  75.   sleep(1)
  76.   os.reboot()
  77. end
  78.  
  79. -- Load Configuration File
  80. config = uapi.loadConfig(".uLockConf")
  81.  
  82. -- Password Lock Program
  83. uapi.cs()
  84. uapi.drawBox(1, 51, 1, 5, " ", "white", "cyan")
  85. uapi.drawBox(2, 51, 2, 3, " ", "white", "cyan")
  86. uapi.drawBox(3, 51, 3, 1, " ", "white", "cyan")
  87. uapi.printC(config.terminalName, 3, false, "white", "cyan")
  88. uapi.drawBox(1, 51, 19, 1, " ", "white", "cyan")
  89. uapi.printC("Password Lock (Ver 1.2) -> Created By DannySMc", 19, false, "white", "cyan")
  90. uapi.resetCol()
  91. term.setCursorPos(1,10)
  92. term.write(">     Password: ")
  93. password = read("*")
  94. password = uapi.checksum(password, 1000)
  95. if password == config.lockPassword then
  96.   term.setCursorPos(1,11)
  97.   print(">     Password Correct!")
  98.   rs.setOutput(config.redSide, true)
  99.   sleep(config.redPulse)
  100.   rs.setOutput(config.redSide, false)
  101.   sleep(0.5)
  102.   os.reboot()
  103. else
  104.   term.setCursorPos(1,11)
  105.   print(">     Password Incorrect!")
  106.   sleep(1.5)
  107.   os.reboot()
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement