randomdude999

SecuritySystem: Startup

Jul 24th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 KB | None | 0 0
  1. os.loadAPI('/.apis/sha')
  2. local passHashHandle = fs.open('/SecuritySystem/.passhash','r')
  3. local passHash = passHashHandle.readAll()
  4. passHashHandle.close()
  5. local w,h = term.getSize()
  6. local logo = paintutils.loadImage("/SecuritySystem/logo")
  7. local logoFile = fs.open("/SecuritySystem/logo",'r')
  8. local lines = {}
  9. for i in string.gmatch(logoFile.readAll(),"[^\n]+") do table.insert(lines, i) end
  10. local imgWidth = 0
  11. for i=1,#lines do if lines[i]:len()>imgWidth then imgWidth = lines[i]:len() end end
  12. local imgHeight = #lines
  13. logoFile.close()
  14. function getPass()
  15.   local inTerm = window.create(term.current(),w/2-6,h/2,13,1,true)
  16.   local oldTerm = term.redirect(inTerm)
  17.   term.setBackgroundColor(2^7)
  18.   term.write("            ")
  19.   term.setCursorPos(1,1)
  20.   local _,out = pcall(read,"*")
  21.   term.redirect(oldTerm)
  22.   term.clear()
  23.   term.setCursorPos(1,1)
  24.   return out
  25. end
  26.  
  27. term.clear()
  28. if h > (imgHeight+4) then
  29.   paintutils.drawImage(logo,math.ceil((w-imgWidth)/2),4)
  30.   term.setBackgroundColor(colors.black)
  31.   term.setCursorPos(math.ceil((w-string.len(os.version()))/2),1)
  32.   print(os.version())
  33.   term.setCursorPos(math.ceil((w-7)/2),2)
  34.   print("Loading")
  35. else
  36.   term.setCursorPos(math.ceil((w-string.len(os.version()))/2),h/2-1)
  37.   print(os.version())
  38.   term.setCursorPos(math.ceil((w-7)/2),h/2+1)
  39.   print("Loading")
  40. end
  41.  
  42. pcall(sleep,3)
  43. term.clear()
  44. while true do
  45.   term.setCursorPos(math.ceil((w-15)/2),h/2-2)
  46.   term.write("Enter Password:")
  47.   local input = getPass()
  48.   term.setBackgroundColor(colors.black)
  49.   if sha.sha256(input) == passHash then
  50.     term.setCursorPos(math.ceil((w-8)/2),h/2)
  51.     term.write("Correct!")
  52.     pcall(sleep,2)
  53.     break
  54.   else
  55.     term.setCursorPos(math.ceil((w-10)/2),h/2)
  56.     term.write("Incorrect!")
  57.     pcall(sleep,2)
  58.   end
  59. end
  60. os.unloadAPI("/.apis/sha")
  61. term.clear()
  62. term.setCursorPos(1,1)
  63. local version
  64. local webH = http.get("http://pastebin.com/raw.php?i=1PM7BAGH")
  65. if webH then version = webH.readAll() end
  66. webH.close()
  67. if version~="3" then
  68.   print("SecuritySystem appears to be outdated. Do you wish to update? [Y/N] ")
  69.   local _,key = os.pullEvent("key")
  70.   sleep(0)
  71.   if key==21 then
  72.     shell.run("pastebin run E5VeZu7G")
  73.   end
  74. end
  75. if fs.exists("/SecuritySystem/startup") then
  76.   shell.run("/SecuritySystem/startup")
  77. else
  78. if term.isColor() then term.setTextColor(colors.yellow) end
  79. print(os.version())
  80. end
Advertisement
Add Comment
Please, Sign In to add comment