Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to draw a border
- local function drawBorder()
- term.clear()
- local w, h = term.getSize()
- for y = 1, h do
- term.setCursorPos(1, y)
- term.write("|")
- term.setCursorPos(w, y)
- term.write("|")
- end
- for x = 1, w do
- term.setCursorPos(x, 1)
- term.write("-")
- term.setCursorPos(x, h)
- term.write("-")
- end
- term.setCursorPos(1, 1)
- term.write("+")
- term.setCursorPos(w, 1)
- term.write("+")
- term.setCursorPos(1, h)
- term.write("+")
- term.setCursorPos(w, h)
- term.write("+")
- end
- -- Function to center text on the screen
- local function centerText(text, y)
- local w, _ = term.getSize()
- if #text > w then
- local firstLine = text:sub(1, w)
- local secondLine = text:sub(w + 1, #text)
- local x1 = math.floor((w - #firstLine) / 2) + 1
- local x2 = math.floor((w - #secondLine) / 2) + 1
- term.setCursorPos(x1, y)
- term.write(firstLine)
- term.setCursorPos(x2, y + 1)
- term.write(secondLine)
- else
- local x = math.floor((w - #text) / 2) + 1
- term.setCursorPos(x, y)
- term.write(text)
- end
- end
- -- Function to show an error message
- local function showError(message, title)
- drawBorder()
- local _, h = term.getSize()
- centerText(title, math.floor(h / 2) - 3)
- centerText("Error:", math.floor(h / 2) - 1)
- centerText(message, math.floor(h / 2) + 1)
- while true do
- os.pullEvent("key")
- end
- end
- -- Function to show a non-malicious error message
- local function showNonMaliciousError(message)
- showError(message, "Doggy OS Non-Malicious Error")
- end
- -- Check for boot.lock file
- if fs.exists("/boot.lock") then
- showError("System Disabled", "Doggy OS Security Error")
- end
- -- Function to check if .settings file exists and contains shell.allow_disk_startup
- local function isSecureBootConfigured()
- local settingsPath = "/.settings"
- if fs.exists(settingsPath) then
- local file = fs.open(settingsPath, "r")
- if file then
- local contents = file.readAll()
- file.close()
- -- Check if .settings contains shell.allow_disk_startup
- if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
- return false -- shell.allow_disk_startup not found
- end
- end
- else
- -- .settings file doesn't exist
- return false -- Secure boot configuration file is missing
- end
- return true -- Secure boot is properly configured
- end
- if not isSecureBootConfigured() then
- showError("Secure boot config file corrupted", "Doggy OS Security Error")
- end
- -- Function to check for malicious paths in a file
- local function containsMaliciousPaths(filePath)
- if not fs.exists(filePath) then
- return false
- end
- local file = fs.open(filePath, "r")
- if not file then
- return false
- end
- local contents = file.readAll()
- file.close()
- local maliciousPaths = {
- "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
- "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
- }
- for _, path in ipairs(maliciousPaths) do
- if string.find(contents, path, 1, true) then
- return true
- end
- end
- return false
- end
- -- Check if /disk2/startup or /disk2/startup.lua includes malicious paths
- if containsMaliciousPaths("/disk2/startup") then
- showError("Malicious Boot Device: /disk2/startup", "Doggy OS Security Error")
- elseif containsMaliciousPaths("/disk2/startup.lua") then
- showError("Malicious Boot Device: /disk2/startup.lua", "Doggy OS Security Error")
- end
- -- Check if /disk/users directory is empty
- local function isDiskUsersEmpty()
- local usersDir = "/disk/users"
- if fs.exists(usersDir) and fs.isDir(usersDir) then
- local files = fs.list(usersDir)
- return #files == 0
- end
- return true
- end
- if isDiskUsersEmpty() then
- showNonMaliciousError("No user data found")
- end
- -- Continue with the normal boot process if no issues were found
- print("No issues detected. Continuing boot process...")
- -- Your normal boot code here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement