Advertisement
znepb

Untitled

Jan 31st, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. local oldPullEvent = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. require("lib/aeslua")
  5. os.loadAPI("/.ld/bin/lib/sha256.lua")
  6. local keyFile = fs.open("/.ld/usr/key", "r")
  7. local key = keyFile.readAll()
  8. keyFile.close()
  9.  
  10. print("Please wait...")
  11.  
  12. local restrictedDirs = {"rom", ".ld", "startup"}
  13. local restrictedFiles = {"startup.lua", "startup", ".settings", "ldinstall.lua"}
  14. local encryptedFiles = {}
  15.  
  16. local versionFile = fs.open("/.ld/bin/version", "r")
  17. local version = versionFile.readAll()
  18. versionFile.close()
  19.  
  20. local function isRestricted(query)
  21. for i, v in pairs(restrictedDirs) do
  22. if v == query then
  23. return true
  24. end
  25. end
  26. for i, v in pairs(restrictedFiles) do
  27. if v == query then
  28. return true
  29. end
  30. end
  31. return false
  32. end
  33.  
  34. local function writeEncryptedFiles()
  35. local file = fs.open("/.ld/usr/encryptedFiles", "w")
  36. file.write(textutils.serialize(encryptedFiles))
  37. file.close()
  38. end
  39.  
  40. local function updateEncryptedFiles()
  41. local file = fs.open("/.ld/usr/encryptedFiles", "r")
  42. encryptedFiles = textutils.unserialize(file.readAll())
  43. file.close()
  44. end
  45.  
  46. local function isEncrypted(query)
  47. for i, v in pairs(encryptedFiles) do
  48. if v == query then
  49. return true
  50. end
  51. end
  52.  
  53. return false
  54. end
  55.  
  56. local function encryptAll(dir)
  57. for i, v in pairs(fs.list(dir)) do
  58. if fs.isDir(dir .. "/" .. v) and not isRestricted(v) then
  59. encryptAll(dir .. "/" .. v)
  60. elseif not isRestricted(v) and not isEncrypted(dir .. "/" .. v) then
  61. local file = fs.open(dir .. "/" .. v, "r")
  62. local data = file.readAll()
  63. file.close()
  64. local encryptedData = aeslua.encrypt(key, data)
  65. local file = fs.open(dir .. "/" .. v, "w")
  66. file.write(encryptedData)
  67. file.close()
  68. table.insert(encryptedFiles, dir .. "/" .. v)
  69. end
  70. end
  71. end
  72.  
  73. local function decryptAll(dir)
  74. for i, v in pairs(fs.list(dir)) do
  75. if fs.isDir(dir .. "/" .. v) and not isRestricted(v) then
  76. decryptAll(dir .. "/" .. v)
  77. elseif not isRestricted(v) and isEncrypted(dir .. "/" .. v) then
  78. print("decrypting: " .. dir .. "/" .. v)
  79. local file = fs.open(dir .. "/" .. v, "r")
  80. local data = file.readAll()
  81. file.close()
  82. local decryptedData = aeslua.decrypt(key, data)
  83. local file = fs.open(dir .. "/" .. v, "w")
  84. file.write(decryptedData)
  85. file.close()
  86. table.insert(encryptedFiles, dir .. "/" .. v)
  87. end
  88. end
  89. end
  90.  
  91. term.clear()
  92. term.setCursorPos(1, 1)
  93.  
  94. updateEncryptedFiles()
  95. encryptAll("/")
  96. writeEncryptedFiles()
  97.  
  98. term.clear()
  99. local success = false
  100.  
  101. if term.isColour() then
  102. term.setTextColour(colours.yellow)
  103. end
  104. print("Lockdown v" .. version)
  105. term.setTextColour(colours.white)
  106.  
  107. repeat
  108. term.write("Please enter your password: ")
  109. local password = read("*")
  110. local enteredKey = sha256.sha256(password)
  111. if enteredKey == key then
  112. print("Welcome.")
  113. success = true
  114. decryptAll("/")
  115. shell.setAlias("setkey", "/.ld/setkey.lua")
  116. os.pullEvent = oldPullEvent
  117. else
  118. print("Sorry, try again")
  119. end
  120. until success == true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement