Advertisement
DOGGYWOOF

DEV mode start check

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