Advertisement
DOGGYWOOF

BIOS W DEVELOPER SWITCH

Aug 7th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 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) - 3)
  40. centerText("1. Recovery", math.floor(h / 2) - 2)
  41. centerText("2. Bootable devices", math.floor(h / 2) - 1)
  42. centerText("3. Shutdown", math.floor(h / 2))
  43. centerText("4. Enable Developer Mode", math.floor(h / 2) + 1)
  44. end
  45.  
  46. -- Function to enable developer mode
  47. local function enableDeveloperMode()
  48. local file = fs.open("dev.cfg", "w")
  49. file.write("developer_mode=true")
  50. file.close()
  51. centerText("Developer mode enabled. Rebooting...", math.floor(term.getSize() / 2))
  52. os.sleep(2)
  53. os.reboot()
  54. end
  55.  
  56. -- Function to list bootable devices
  57. local function listBootableDevices()
  58. drawBorder()
  59. local _, h = term.getSize()
  60. centerText("Select Bootable Device", math.floor(h / 2) - 2)
  61.  
  62. local devices = {}
  63. for _, side in ipairs({"top", "bottom", "left", "right", "front", "back"}) do
  64. if disk.isPresent(side) then
  65. local mountPath = disk.getMountPath(side)
  66. if fs.exists(mountPath) then
  67. for _, file in ipairs(fs.list(mountPath)) do
  68. if file:match("^startup") then
  69. table.insert(devices, side)
  70. break
  71. end
  72. end
  73. end
  74. end
  75. end
  76.  
  77. for i, device in ipairs(devices) do
  78. centerText(i .. ". " .. device, math.floor(h / 2) - 1 + i)
  79. end
  80.  
  81. if #devices == 0 then
  82. centerText("No bootable devices found", math.floor(h / 2))
  83. os.sleep(2)
  84. showMenu()
  85. else
  86. term.setCursorPos(1, math.floor(h / 2) + #devices + 1)
  87. term.write("Select a device number: ")
  88. local choice = tonumber(read())
  89. if choice and devices[choice] then
  90. shell.run(disk.getMountPath(devices[choice]) .. "/startup.lua")
  91. else
  92. listBootableDevices()
  93. end
  94. end
  95. end
  96.  
  97. -- Function to handle menu selection
  98. local function handleSelection()
  99. while true do
  100. local event, key = os.pullEvent("key")
  101. if key == keys.one then
  102. shell.run("/disk/boot/Recovery.lua")
  103. elseif key == keys.two then
  104. listBootableDevices()
  105. elseif key == keys.three then
  106. os.shutdown()
  107. elseif key == keys.four then
  108. enableDeveloperMode()
  109. end
  110. end
  111. end
  112.  
  113. -- Function to verify user credentials
  114. local function verifyCredentials(username, password)
  115. local userPath = "/disk/users/" .. username
  116. if fs.exists(userPath .. "/admin.txt") and fs.exists(userPath .. "/password.txt") then
  117. local file = fs.open(userPath .. "/password.txt", "r")
  118. local storedPassword = file.readAll()
  119. file.close()
  120. return storedPassword == password
  121. end
  122. return false
  123. end
  124.  
  125. -- Function to authenticate user
  126. local function authenticate()
  127. term.clear()
  128. drawBorder()
  129. local _, h = term.getSize()
  130. centerText("Doggy OS UEFI Authentication", 3)
  131.  
  132. local w, _ = term.getSize()
  133. local usernameX = math.floor(w / 2) - 10
  134.  
  135. term.setCursorPos(usernameX, 5)
  136. term.write("Username: ")
  137. term.setCursorPos(usernameX + 10, 5)
  138. local username = read()
  139.  
  140. term.setCursorPos(usernameX, 7)
  141. term.write("Password: ")
  142. term.setCursorPos(usernameX + 10, 7)
  143. local password = read("*") -- Masked input for password
  144.  
  145. if verifyCredentials(username, password) then
  146. showMenu()
  147. handleSelection()
  148. else
  149. centerText("Invalid credentials. Access denied.", 10)
  150. os.sleep(2)
  151. os.reboot()
  152. end
  153. end
  154.  
  155. -- Start authentication process
  156. authenticate()
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement