Advertisement
DOGGYWOOF

Untitled

Sep 6th, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 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) - 1)
  41. centerText("2. Bootable devices", math.floor(h / 2))
  42. centerText("3. Device Info", math.floor(h / 2) + 1)
  43. centerText("4. Shutdown", math.floor(h / 2) + 2)
  44. end
  45.  
  46. -- Function to list bootable devices
  47. local function listBootableDevices()
  48. drawBorder()
  49. local _, h = term.getSize()
  50. centerText("Select Bootable Device", math.floor(h / 2) - 2)
  51.  
  52. local devices = {}
  53. for _, side in ipairs({"top", "bottom", "left", "right", "front", "back"}) do
  54. if disk.isPresent(side) then
  55. local mountPath = disk.getMountPath(side)
  56. if fs.exists(mountPath) then
  57. for _, file in ipairs(fs.list(mountPath)) do
  58. if file:match("^startup") then
  59. table.insert(devices, side)
  60. break
  61. end
  62. end
  63. end
  64. end
  65. end
  66.  
  67. for i, device in ipairs(devices) do
  68. centerText(i .. ". " .. device, math.floor(h / 2) - 1 + i)
  69. end
  70.  
  71. if #devices == 0 then
  72. centerText("No bootable devices found", math.floor(h / 2))
  73. os.sleep(2)
  74. showMenu()
  75. else
  76. term.setCursorPos(1, math.floor(h / 2) + #devices + 1)
  77. term.write("Select a device number: ")
  78. local choice = tonumber(read())
  79. if choice and devices[choice] then
  80. shell.run(disk.getMountPath(devices[choice]) .. "/startup.lua")
  81. else
  82. listBootableDevices()
  83. end
  84. end
  85. end
  86.  
  87. -- Function to show device information
  88. local function showDeviceInfo()
  89. term.setBackgroundColor(colors.black)
  90. term.clear()
  91. term.setCursorPos(1, 1)
  92.  
  93. -- Define colors
  94. local bgColor = colors.black
  95. local textColor = colors.white
  96. local headerColor = colors.blue
  97. local infoColor = colors.green
  98.  
  99. -- Function to print a header with a background color
  100. local function printHeader(text)
  101. term.setTextColor(headerColor)
  102. term.setBackgroundColor(bgColor)
  103. print(text)
  104. term.setTextColor(textColor)
  105. end
  106.  
  107. -- Function to print info with colors
  108. local function printInfo(label, value)
  109. term.setTextColor(infoColor)
  110. term.write(label .. ": ")
  111. term.setTextColor(textColor)
  112. print(value)
  113. end
  114.  
  115. -- Display ASCII art
  116. term.setTextColor(headerColor)
  117. print(" |\\_/|")
  118. print(" | @ @ DEVICE INFORMATION ")
  119. print(" | <> _ ")
  120. print(" | _/\\------____ ((| |))")
  121. print(" | `--' | ")
  122. print(" ____|_ ___| |___.' ")
  123. print("/_/_____/____/_______|")
  124.  
  125. -- Function to read config file using Lua's loadfile
  126. local function readConfig()
  127. local configFilePath = "/disk/bootloader/system.config"
  128. if fs.exists(configFilePath) then
  129. local config = loadfile(configFilePath)()
  130. if type(config) == "table" then
  131. return config
  132. else
  133. return {} -- Return an empty table if the format is incorrect
  134. end
  135. end
  136. return {} -- Return an empty table if the file does not exist
  137. end
  138.  
  139. -- Function to get the device info
  140. local function getDeviceInfo()
  141. local config = readConfig() -- Read config from Lua file
  142. local id = os.getComputerID() or "Unknown ID"
  143. local label = os.getComputerLabel() or "No Label"
  144. local osVersion = config.os_version or "Unknown OS Version"
  145. local bootloaderVersion = config.bootloader_version or "Unknown Bootloader Version"
  146. local securityPatch = config.security_patch or "Unknown Security Patch"
  147. local recoveryPartition = fs.exists("/recovery/") and "Recovery partition exists" or "No Recovery partition"
  148.  
  149. return {
  150. id = id,
  151. label = label,
  152. osVersion = osVersion,
  153. bootloaderVersion = bootloaderVersion,
  154. securityPatch = securityPatch,
  155. recoveryPartition = recoveryPartition
  156. }
  157. end
  158.  
  159. -- Get device info
  160. local info = getDeviceInfo()
  161.  
  162. -- Display device info with better UI
  163. printHeader("Computer Information:")
  164. printInfo("Computer ID", info.id)
  165. printInfo("Computer Label", info.label)
  166. printHeader("Software Information:")
  167. printInfo("Doggy OS Version", info.osVersion)
  168. printInfo("VA11-ILLA Bootloader Version", info.bootloaderVersion)
  169. printInfo("Security Patch Version", info.securityPatch)
  170. printHeader("System Information:")
  171. printInfo("Recovery Partition Status", info.recoveryPartition)
  172.  
  173. -- Prompt and wait for Enter key to reboot
  174. term.setTextColor(colors.yellow)
  175. term.setTextColor(textColor)
  176. local input = read()
  177. if input == "" then
  178. -- Reboot the computer
  179. os.reboot()
  180. end
  181. end
  182.  
  183. -- Function to handle menu selection
  184. local function handleSelection()
  185. while true do
  186. local event, key = os.pullEvent("key")
  187. if key == keys.one then
  188. shell.run("/disk/boot/Recovery.lua")
  189. elseif key == keys.two then
  190. listBootableDevices()
  191. elseif key == keys.three then
  192. showDeviceInfo()
  193. elseif key == keys.four then
  194. os.shutdown()
  195. end
  196. end
  197. end
  198.  
  199. -- Function to verify user credentials
  200. local function verifyCredentials(username, password)
  201. local userPath = "/disk/users/" .. username
  202. if fs.exists(userPath .. "/admin.txt") and fs.exists(userPath .. "/password.txt") then
  203. local file = fs.open(userPath .. "/password.txt", "r")
  204. local storedPassword = file.readAll()
  205. file.close()
  206. return storedPassword == password
  207. end
  208. return false
  209. end
  210.  
  211. -- Function to authenticate user
  212. local function authenticate()
  213. term.clear()
  214. drawBorder()
  215. local _, h = term.getSize()
  216. centerText("Doggy OS UEFI Authentication", 3)
  217.  
  218. local w, _ = term.getSize()
  219. local usernameX = math.floor(w / 2) - 10
  220.  
  221. term.setCursorPos(usernameX, 5)
  222. term.write("Username: ")
  223. term.setCursorPos(usernameX + 10, 5)
  224. local username = read()
  225.  
  226. term.setCursorPos(usernameX, 7)
  227. term.write("Password: ")
  228. term.setCursorPos(usernameX + 10, 7)
  229. local password = read("*") -- Masked input for password
  230.  
  231. if verifyCredentials(username, password) then
  232. showMenu()
  233. handleSelection()
  234. else
  235. centerText("Invalid credentials. Access denied.", 10)
  236. os.sleep(2)
  237. os.reboot()
  238. end
  239. end
  240.  
  241. -- Start authentication process
  242. authenticate()
  243.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement