Advertisement
DOGGYWOOF

Secure UEFI

Jul 1st, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. -- Function to draw a border
  2. local function drawBorder()
  3. term.clear()
  4. local w, h = term.getSize()
  5. for y = 1, h do
  6. term.setCursorPos(1, y)
  7. term.write("|")
  8. term.setCursorPos(w, y)
  9. term.write("|")
  10. end
  11. for x = 1, w do
  12. term.setCursorPos(x, 1)
  13. term.write("-")
  14. term.setCursorPos(x, h)
  15. term.write("-")
  16. end
  17. term.setCursorPos(1, 1)
  18. term.write("+")
  19. term.setCursorPos(w, 1)
  20. term.write("+")
  21. term.setCursorPos(1, h)
  22. term.write("+")
  23. term.setCursorPos(w, h)
  24. term.write("+")
  25. end
  26.  
  27. -- Function to center text on the screen
  28. local function centerText(text, y)
  29. local w, _ = term.getSize()
  30. local x = math.floor((w - #text) / 2) + 1
  31. term.setCursorPos(x, y)
  32. term.write(text)
  33. end
  34.  
  35. -- Function to show UEFI options menu
  36. local function showMenu()
  37. drawBorder()
  38. local _, h = term.getSize()
  39. centerText("Doggy OS UEFI Options", math.floor(h / 2) - 2)
  40. centerText("1. Recovery", math.floor(h / 2))
  41. centerText("2. Bootable devices", math.floor(h / 2) + 1)
  42. centerText("3. Shutdown", math.floor(h / 2) + 2)
  43. end
  44.  
  45. -- Function to list bootable devices
  46. local function listBootableDevices()
  47. drawBorder()
  48. local _, h = term.getSize()
  49. centerText("Select Bootable Device", math.floor(h / 2) - 2)
  50.  
  51. local devices = {}
  52. for _, side in ipairs({"top", "bottom", "left", "right", "front", "back"}) do
  53. if disk.isPresent(side) then
  54. local mountPath = disk.getMountPath(side)
  55. if fs.exists(mountPath) then
  56. for _, file in ipairs(fs.list(mountPath)) do
  57. if file:match("^startup") then
  58. table.insert(devices, side)
  59. break
  60. end
  61. end
  62. end
  63. end
  64. end
  65.  
  66. for i, device in ipairs(devices) do
  67. centerText(i .. ". " .. device, math.floor(h / 2) - 1 + i)
  68. end
  69.  
  70. if #devices == 0 then
  71. centerText("No bootable devices found", math.floor(h / 2))
  72. os.sleep(2)
  73. showMenu()
  74. else
  75. term.setCursorPos(1, math.floor(h / 2) + #devices + 1)
  76. term.write("Select a device number: ")
  77. local choice = tonumber(read())
  78. if choice and devices[choice] then
  79. shell.run(disk.getMountPath(devices[choice]) .. "/startup.lua")
  80. else
  81. listBootableDevices()
  82. end
  83. end
  84. end
  85.  
  86. -- Function to handle menu selection
  87. local function handleSelection()
  88. while true do
  89. local event, key = os.pullEvent("key")
  90. if key == keys.one then
  91. shell.run("/disk/boot/Recovery.lua")
  92. elseif key == keys.two then
  93. listBootableDevices()
  94. elseif key == keys.three then
  95. os.shutdown()
  96. end
  97. end
  98. end
  99.  
  100. -- Function to verify user credentials
  101. local function verifyCredentials(username, password)
  102. local userPath = "/disk/users/" .. username
  103. if fs.exists(userPath .. "/admin.txt") and fs.exists(userPath .. "/password.txt") then
  104. local file = fs.open(userPath .. "/password.txt", "r")
  105. local storedPassword = file.readAll()
  106. file.close()
  107. return storedPassword == password
  108. end
  109. return false
  110. end
  111.  
  112. -- Function to authenticate user
  113. local function authenticate()
  114. term.clear()
  115. drawBorder()
  116. local _, h = term.getSize()
  117. centerText("Doggy OS UEFI Authentication", 3)
  118.  
  119. local w, _ = term.getSize()
  120. local usernameX = math.floor(w / 2) - 10
  121.  
  122. term.setCursorPos(usernameX, 5)
  123. term.write("Username: ")
  124. term.setCursorPos(usernameX + 10, 5)
  125. local username = read()
  126.  
  127. term.setCursorPos(usernameX, 7)
  128. term.write("Password: ")
  129. term.setCursorPos(usernameX + 10, 7)
  130. local password = read("*") -- Masked input for password
  131.  
  132. if verifyCredentials(username, password) then
  133. showMenu()
  134. handleSelection()
  135. else
  136. centerText("Invalid credentials. Access denied.", 10)
  137. os.sleep(2)
  138. os.reboot()
  139. end
  140. end
  141.  
  142. -- Start authentication process
  143. authenticate()
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement