Advertisement
DOGGYWOOF

start check with fatal and warning

Jul 24th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 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. -- ASCII art for fatal error screen
  19. local fatalArt = {
  20. " |\\_/| ",
  21. " | X X ",
  22. " | <> _ ",
  23. " | _/\\------____ ((| |))",
  24. " | `--' | ",
  25. " _____|_ ___| |___. ",
  26. "/_/_____/____/_______| "
  27. }
  28.  
  29. -- ASCII art for warning screen
  30. local warningArt = {
  31. " |\\_/| ",
  32. " | ? ? ",
  33. " | <> _ ",
  34. " | _/\\------____ ((| |))",
  35. " | `--' | ",
  36. " _____|_ ___| |___. ",
  37. "/_/_____/____/_______| "
  38. }
  39.  
  40. -- Function to show an error message with ASCII art
  41. local function showError(message, isFatal)
  42. term.clear()
  43.  
  44. -- Determine ASCII art and color based on error type
  45. local artColor = isFatal and colors.red or colors.yellow
  46. local art = isFatal and fatalArt or warningArt
  47.  
  48. -- Display the ASCII art
  49. local startLine = math.floor((height - #art) / 2) - 2
  50. term.setTextColor(artColor)
  51. for i, line in ipairs(art) do
  52. centerText(startLine + i, line, artColor)
  53. end
  54.  
  55. -- Display error message below the ASCII art
  56. term.setTextColor(colors.white)
  57. centerText(startLine + #art + 2, "Error:", colors.white)
  58. centerText(startLine + #art + 3, message, colors.white)
  59.  
  60. -- Move "Please contact support." to the bottom in white
  61. centerText(height - 2, "Please contact support.", colors.white)
  62.  
  63. -- Keep the screen static with the error message
  64. while true do
  65. sleep(1)
  66. end
  67. end
  68.  
  69. -- Function to check for boot.lock file
  70. local function checkBootLock()
  71. if fs.exists("/boot.lock") then
  72. showError("System Disabled", false) -- Warning
  73. end
  74. end
  75.  
  76. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  77. local function isSecureBootConfigured()
  78. local settingsPath = "/.settings"
  79. if fs.exists(settingsPath) then
  80. local file = fs.open(settingsPath, "r")
  81. if file then
  82. local contents = file.readAll()
  83. file.close()
  84. -- Check if .settings contains shell.allow_disk_startup
  85. if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
  86. return false -- shell.allow_disk_startup not found
  87. end
  88. end
  89. else
  90. -- .settings file doesn't exist
  91. return false -- Secure boot configuration file is missing
  92. end
  93. return true -- Secure boot is properly configured
  94. end
  95.  
  96. -- Function to check for malicious paths in a file
  97. local function containsMaliciousPaths(filePath)
  98. if not fs.exists(filePath) then
  99. return false
  100. end
  101.  
  102. local file = fs.open(filePath, "r")
  103. if not file then
  104. return false
  105. end
  106.  
  107. local contents = file.readAll()
  108. file.close()
  109.  
  110. local maliciousPaths = {
  111. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  112. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  113. }
  114.  
  115. for _, path in ipairs(maliciousPaths) do
  116. if string.find(contents, path, 1, true) then
  117. return true
  118. end
  119. end
  120.  
  121. return false
  122. end
  123.  
  124. -- Function to check if /disk2/startup or /disk2/startup.lua includes malicious paths
  125. local function checkMaliciousBoot()
  126. if containsMaliciousPaths("/disk2/startup") then
  127. showError("Malicious Boot Device: /disk2/startup", false) -- Warning
  128. elseif containsMaliciousPaths("/disk2/startup.lua") then
  129. showError("Malicious Boot Device: /disk2/startup.lua", false) -- Warning
  130. end
  131. end
  132.  
  133. -- Function to check if /disk/users directory is empty
  134. local function checkEmptyUsers()
  135. local usersDir = "/disk/users"
  136. if fs.exists(usersDir) and fs.isDir(usersDir) then
  137. local files = fs.list(usersDir)
  138. if #files == 0 then
  139. showError("No user data found", false) -- Warning
  140. end
  141. else
  142. showError("No user data found", false) -- Warning
  143. end
  144. end
  145.  
  146. -- Function to check if /disk/boot/BIOS exists
  147. local function checkCriticalBootFiles()
  148. if not fs.exists("/disk/boot/BIOS") then
  149. showError("Critical boot files missing", true) -- Fatal
  150. end
  151. end
  152.  
  153. -- Function to check if any user has admin.txt
  154. local function checkAdmin()
  155. local usersDir = "/disk/users"
  156. if fs.exists(usersDir) and fs.isDir(usersDir) then
  157. local users = fs.list(usersDir)
  158. for _, user in ipairs(users) do
  159. local adminPath = fs.combine(usersDir, user, "admin.txt")
  160. if fs.exists(adminPath) then
  161. return true
  162. end
  163. end
  164. end
  165. return false
  166. end
  167.  
  168. -- Function to check if no-os file exists
  169. local function checkFirmware()
  170. if not fs.exists("/no-os") then
  171. showError("System Firmware corrupted", true) -- Fatal
  172. end
  173. end
  174.  
  175. -- Main function to initiate checks and continue boot process
  176. local function main()
  177. checkBootLock()
  178. if not isSecureBootConfigured() then
  179. showError("Secure boot config file corrupted", true) -- Fatal
  180. end
  181. checkMaliciousBoot()
  182. checkEmptyUsers()
  183. checkCriticalBootFiles()
  184. if not checkAdmin() then
  185. showError("No system administrators found", false) -- Warning
  186. end
  187. checkFirmware()
  188.  
  189. -- If no issues found, continue with normal boot process
  190. shell.run("/disk/boot/BIOS")
  191. print("No issues detected. Continuing boot process...")
  192. -- Your normal boot code here
  193. end
  194.  
  195. -- Start the main function
  196. main()
  197.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement