Advertisement
DOGGYWOOF

Untitled

Jan 20th, 2025 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. -- Clear the screen and set up colors
  2. term.clear()
  3. term.setBackgroundColor(colors.black)
  4. term.setTextColor(colors.white)
  5. term.clear()
  6.  
  7. -- Define the width and height of the screen
  8. local width, height = term.getSize()
  9.  
  10. -- Function to center text on the screen
  11. local function centerText(y, text, textColor)
  12. local x = math.floor((width - #text) / 2)
  13. term.setCursorPos(x, y)
  14. term.setTextColor(textColor)
  15. term.write(text)
  16. end
  17.  
  18. -- Function to display a box with title
  19. local function drawBox(y, height, title, message)
  20. local boxWidth = width - 4
  21. local x = 2
  22. -- Draw top border
  23. term.setTextColor(colors.cyan)
  24. term.setBackgroundColor(colors.gray)
  25. term.setCursorPos(x, y)
  26. term.write(string.rep("─", boxWidth))
  27. -- Title row
  28. term.setCursorPos(x + 2, y + 1)
  29. term.setTextColor(colors.white)
  30. term.setBackgroundColor(colors.cyan)
  31. term.write(title)
  32. -- Message rows
  33. term.setBackgroundColor(colors.black)
  34. for i = 1, height - 2 do
  35. term.setCursorPos(x + 2, y + i + 1)
  36. term.write(message[i] or "")
  37. end
  38. -- Draw bottom border
  39. term.setCursorPos(x, y + height)
  40. term.write(string.rep("─", boxWidth))
  41. end
  42.  
  43. -- ASCII art for fatal error screen
  44. local fatalArt = {
  45. " |\\_/| ",
  46. " | X X FATAL ERROR ",
  47. " | <> _ ",
  48. " | _/\\------____ ((| |))",
  49. " | `--' | ",
  50. " _____|_ ___| |___. ",
  51. "/_/_____/____/_______| "
  52. }
  53.  
  54. -- ASCII art for warning screen
  55. local warningArt = {
  56. " |\\_/| ",
  57. " | ? ? SECURITY ERROR ",
  58. " | <> _ ",
  59. " | _/\\------____ ((| |))",
  60. " | `--' | ",
  61. " _____|_ ___| |___. ",
  62. "/_/_____/____/_______| "
  63. }
  64.  
  65. -- Function to prompt for admin credentials with improved UI
  66. local function authenticateAdmin()
  67. term.clear()
  68. local authHeight = 8
  69. local message = {
  70. "Enter your username and password.",
  71. "You are required to authenticate as admin.",
  72. "",
  73. "(Please be aware of the case sensitivity of your credentials)."
  74. }
  75. drawBox(2, authHeight, "Admin Authentication Required", message)
  76.  
  77. -- Username input
  78. centerText(height // 2, "Enter Username:", colors.white)
  79. term.setCursorPos((width - 20) // 2, height // 2 + 1)
  80. local username = read()
  81.  
  82. -- Password input
  83. local passwordPath = "/disk/users/" .. username .. "/password.txt"
  84. local adminPath = "/disk/users/" .. username .. "/admin.txt"
  85.  
  86. if fs.exists(adminPath) and fs.exists(passwordPath) then
  87. -- Password field with hidden characters
  88. centerText(height // 2 + 2, "Enter Password:", colors.white)
  89. term.setCursorPos((width - 20) // 2, height // 2 + 3)
  90. local enteredPassword = read("*")
  91.  
  92. -- Check if the password is correct
  93. local file = fs.open(passwordPath, "r")
  94. local storedPassword = file.readAll()
  95. file.close()
  96.  
  97. if enteredPassword == storedPassword then
  98. -- Success message
  99. centerText(height // 2 + 4, "Authentication Successful!", colors.green)
  100. sleep(1)
  101. return true -- Authentication successful
  102. else
  103. -- Failure message
  104. centerText(height // 2 + 4, "Authentication Failed", colors.red)
  105. sleep(2)
  106. end
  107. else
  108. -- If the user doesn't exist or there's no password
  109. centerText(height // 2 + 4, "Authentication Failed: User Not Found", colors.red)
  110. sleep(2)
  111. end
  112. return false -- Authentication failed
  113. end
  114.  
  115. -- Function to show an error message with ASCII art
  116. local function showError(message, isFatal)
  117. term.clear()
  118.  
  119. -- Determine ASCII art and color based on error type
  120. local artColor = isFatal and colors.red or colors.yellow
  121. local art = isFatal and fatalArt or warningArt
  122.  
  123. -- Display the ASCII art
  124. local startLine = math.floor((height - #art) / 2) - 2
  125. term.setTextColor(artColor)
  126. for i, line in ipairs(art) do
  127. centerText(startLine + i, line, artColor)
  128. end
  129.  
  130. -- Display error message below the ASCII art
  131. term.setTextColor(colors.white)
  132. centerText(startLine + #art + 2, "Error:", colors.white)
  133. centerText(startLine + #art + 3, message, colors.white)
  134.  
  135. -- Move "Please contact support." to the bottom in white
  136. centerText(height - 2, "Press DEL for Admin Override", colors.white)
  137.  
  138. -- Wait for DEL key or keep the screen static
  139. while true do
  140. local event, key = os.pullEvent("key")
  141. if key == keys.delete then
  142. if authenticateAdmin() then
  143. return -- Exit the error screen if authentication succeeds
  144. end
  145. end
  146. sleep(0.1)
  147. end
  148. end
  149.  
  150. -- Function to check for boot.lock file
  151. local function checkBootLock()
  152. if fs.exists("/boot.lock") then
  153. showError("System Disabled", false) -- Warning
  154. end
  155. end
  156.  
  157. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  158. local function isSecureBootConfigured()
  159. local settingsPath = "/.settings"
  160. if fs.exists(settingsPath) then
  161. local file = fs.open(settingsPath, "r")
  162. if file then
  163. local contents = file.readAll()
  164. file.close()
  165. -- Check if .settings contains shell.allow_disk_startup
  166. if not string.find(contents, 'shell%.allow_disk_startup') then
  167. return false -- shell.allow_disk_startup not found
  168. end
  169. end
  170. else
  171. -- .settings file doesn't exist
  172. return false -- Secure boot configuration file is missing
  173. end
  174. return true -- Secure boot is properly configured
  175. end
  176.  
  177. -- Function to check for malicious paths in a file
  178. local function containsMaliciousPaths(filePath)
  179. if not fs.exists(filePath) then
  180. return false
  181. end
  182.  
  183. local file = fs.open(filePath, "r")
  184. if not file then
  185. return false
  186. end
  187.  
  188. local contents = file.readAll()
  189. file.close()
  190.  
  191. local maliciousPaths = {
  192. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  193. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  194. }
  195.  
  196. for _, path in ipairs(maliciousPaths) do
  197. if string.find(contents, path, 1, true) then
  198. return true
  199. end
  200. end
  201.  
  202. return false
  203. end
  204.  
  205. -- Function to check if /disk2/startup or /disk2/startup.lua includes malicious paths
  206. local function checkMaliciousBoot()
  207. if containsMaliciousPaths("/disk2/startup") then
  208. showError("Malicious Boot Device: /disk2/startup", false) -- Warning
  209. elseif containsMaliciousPaths("/disk2/startup.lua") then
  210. showError("Malicious Boot Device: /disk2/startup.lua", false) -- Warning
  211. end
  212. end
  213.  
  214. -- Function to check if /disk/users directory is empty
  215. local function checkEmptyUsers()
  216. local usersDir = "/disk/users"
  217. if fs.exists(usersDir) and fs.isDir(usersDir) then
  218. local files = fs.list(usersDir)
  219. if #files == 0 then
  220. showError("No user data found", false) -- Warning
  221. end
  222. else
  223. showError("No user data found", false) -- Warning
  224. end
  225. end
  226.  
  227. -- Function to check if /disk/boot/BIOS exists
  228. local function checkCriticalBootFiles()
  229. if not fs.exists("/disk/boot/boot-animation") then
  230. showError("/disk/boot/BIOS Cannot be loaded", true) -- Fatal
  231. end
  232. end
  233.  
  234. -- Function to check if any user has admin.txt
  235. local function checkAdmin()
  236. local usersDir = "/disk/users"
  237. if fs.exists(usersDir) and fs.isDir(usersDir) then
  238. local users = fs.list(usersDir)
  239. for _, user in ipairs(users) do
  240. local adminPath = fs.combine(usersDir, user, "admin.txt")
  241. if fs.exists(adminPath) then
  242. return true
  243. end
  244. end
  245. end
  246. return false
  247. end
  248.  
  249. -- Function to check if no-os file exists
  250. local function checkFirmware()
  251. if not fs.exists("/no-os") then
  252. showError("System Firmware Corrupted", true) -- Fatal
  253. end
  254. end
  255.  
  256. -- Main function to initiate checks and continue boot process
  257. local function main()
  258. checkBootLock()
  259. if not isSecureBootConfigured() then
  260. showError("Secure Boot Service Unavailable", true) -- Fatal
  261. end
  262. checkMaliciousBoot()
  263. checkEmptyUsers()
  264. checkCriticalBootFiles()
  265. if not checkAdmin() then
  266. showError("No system administrators found", false) -- Warning
  267. end
  268. checkFirmware()
  269.  
  270. -- If no issues found, continue with normal boot process
  271. shell.run("/disk/boot/BIOS")
  272. print("No issues detected. Continuing boot process...")
  273. shell.run("/disk/error/crash")
  274. -- Your normal boot code here
  275. end
  276.  
  277. -- Start the main function
  278. main()
  279.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement