Advertisement
DOGGYWOOF

Untitled

Jul 1st, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 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. if #text > w then
  31. local firstLine = text:sub(1, w)
  32. local secondLine = text:sub(w + 1, #text)
  33. local x1 = math.floor((w - #firstLine) / 2) + 1
  34. local x2 = math.floor((w - #secondLine) / 2) + 1
  35. term.setCursorPos(x1, y)
  36. term.write(firstLine)
  37. term.setCursorPos(x2, y + 1)
  38. term.write(secondLine)
  39. else
  40. local x = math.floor((w - #text) / 2) + 1
  41. term.setCursorPos(x, y)
  42. term.write(text)
  43. end
  44. end
  45.  
  46. -- Function to show an error message
  47. local function showError(message, title)
  48. drawBorder()
  49. local _, h = term.getSize()
  50. centerText(title, math.floor(h / 2) - 3)
  51. centerText("Error:", math.floor(h / 2) - 1)
  52. centerText(message, math.floor(h / 2) + 1)
  53. while true do
  54. os.pullEvent("key")
  55. end
  56. end
  57.  
  58. -- Function to show a non-malicious error message
  59. local function showNonMaliciousError(message)
  60. showError(message, "Doggy OS Non-Malicious Error")
  61. end
  62.  
  63. -- Check for boot.lock file
  64. if fs.exists("/boot.lock") then
  65. showError("System Disabled", "Doggy OS Security Error")
  66. end
  67.  
  68. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  69. local function isSecureBootConfigured()
  70. local settingsPath = "/.settings"
  71. if fs.exists(settingsPath) then
  72. local file = fs.open(settingsPath, "r")
  73. if file then
  74. local contents = file.readAll()
  75. file.close()
  76. -- Check if .settings contains shell.allow_disk_startup
  77. if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
  78. return false -- shell.allow_disk_startup not found
  79. end
  80. end
  81. else
  82. -- .settings file doesn't exist
  83. return false -- Secure boot configuration file is missing
  84. end
  85. return true -- Secure boot is properly configured
  86. end
  87.  
  88. if not isSecureBootConfigured() then
  89. showError("Secure boot config file corrupted", "Doggy OS Security Error")
  90. end
  91.  
  92. -- Function to check for malicious paths in a file
  93. local function containsMaliciousPaths(filePath)
  94. if not fs.exists(filePath) then
  95. return false
  96. end
  97.  
  98. local file = fs.open(filePath, "r")
  99. if not file then
  100. return false
  101. end
  102.  
  103. local contents = file.readAll()
  104. file.close()
  105.  
  106. local maliciousPaths = {
  107. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  108. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  109. }
  110.  
  111. for _, path in ipairs(maliciousPaths) do
  112. if string.find(contents, path, 1, true) then
  113. return true
  114. end
  115. end
  116.  
  117. return false
  118. end
  119.  
  120. -- Check if /disk2/startup or /disk2/startup.lua includes malicious paths
  121. if containsMaliciousPaths("/disk2/startup") then
  122. showError("Malicious Boot Device: /disk2/startup", "Doggy OS Security Error")
  123. elseif containsMaliciousPaths("/disk2/startup.lua") then
  124. showError("Malicious Boot Device: /disk2/startup.lua", "Doggy OS Security Error")
  125. end
  126.  
  127. -- Check if /disk/users directory is empty
  128. local function isDiskUsersEmpty()
  129. local usersDir = "/disk/users"
  130. if fs.exists(usersDir) and fs.isDir(usersDir) then
  131. local files = fs.list(usersDir)
  132. return #files == 0
  133. end
  134. return true
  135. end
  136.  
  137. if isDiskUsersEmpty() then
  138. showNonMaliciousError("No user data found")
  139. end
  140.  
  141. -- Continue with the normal boot process if no issues were found
  142. print("No issues detected. Continuing boot process...")
  143. -- Your normal boot code here
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement