Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to draw a border with a more refined style
- local function drawBorder()
- term.clear()
- local w, h = term.getSize()
- -- Draw top and bottom borders with a different style
- for y = 1, h do
- term.setCursorPos(1, y)
- if y == 1 or y == h then
- term.write("=")
- else
- term.write("|")
- end
- term.setCursorPos(w, y)
- if y == 1 or y == h then
- term.write("=")
- else
- term.write("|")
- end
- end
- -- Draw side borders
- for x = 1, w do
- if x == 1 or x == w then
- term.setCursorPos(x, 1)
- term.write("=")
- term.setCursorPos(x, h)
- term.write("=")
- end
- end
- end
- -- Function to center text on the screen
- local function centerText(text, y)
- local w, _ = term.getSize()
- local x = math.floor((w - #text) / 2) + 1
- term.setCursorPos(x, y)
- term.write(text)
- end
- -- Function to show bootable device options with the updated UI
- local function showBootOptions()
- drawBorder()
- local _, h = term.getSize()
- centerText("Bootable Device Options", math.floor(h / 2) - 2)
- -- Prepare a list of devices to check for startup files
- local devices = {}
- local mountPaths = {
- "/disk", "/disk2", "/disk3", "/disk4", "/disk5"
- }
- -- Iterate over mount paths and check for startup files
- for _, path in ipairs(mountPaths) do
- if fs.exists(path) then
- if fs.exists(path .. "/startup.lua") then
- table.insert(devices, path .. "/startup.lua")
- elseif fs.exists(path .. "/startup") then
- table.insert(devices, path .. "/startup")
- end
- end
- end
- -- Display the list of bootable devices
- if #devices == 0 then
- centerText("No bootable devices found", math.floor(h / 2))
- else
- for i, device in ipairs(devices) do
- centerText(i .. ". " .. device, math.floor(h / 2) + i)
- end
- -- Prompt for a choice from the user
- term.setCursorPos(1, math.floor(h / 2) + #devices + 1)
- term.write("Select a device number: ")
- local choice = tonumber(read())
- if choice and devices[choice] then
- shell.run(devices[choice])
- else
- showBootOptions() -- Retry if an invalid option is selected
- end
- end
- end
- -- Function to show the main UEFI menu with branding
- local function showMenu()
- drawBorder()
- local _, h = term.getSize()
- centerText("Doggy OS Embedded ROM Setup", 3)
- centerText("UEFI Options", math.floor(h / 2) - 2)
- centerText("1. Recovery", math.floor(h / 2))
- centerText("2. Bootable devices", math.floor(h / 2) + 1)
- centerText("3. Shutdown", math.floor(h / 2) + 2)
- centerText("4. Command Line", math.floor(h / 2) + 3) -- New option added
- end
- -- Function to handle menu selection
- local function handleSelection()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.one then
- shell.run("/disk/boot/Recovery.lua")
- elseif key == keys.two then
- showBootOptions() -- Updated boot option
- elseif key == keys.three then
- os.shutdown()
- elseif key == keys.four then
- shell.run("/disk/os/home.lua") -- Command Line option added
- end
- end
- end
- -- Function to verify user credentials
- local function verifyCredentials(username, password)
- local userPath = "/disk/users/" .. username
- if fs.exists(userPath .. "/admin.txt") and fs.exists(userPath .. "/password.txt") then
- local file = fs.open(userPath .. "/password.txt", "r")
- local storedPassword = file.readAll()
- file.close()
- return storedPassword == password
- end
- return false
- end
- -- Function to authenticate user with the updated UI
- local function authenticate()
- term.clear()
- drawBorder()
- local _, h = term.getSize()
- centerText("Doggy OS Embedded ROM Setup", 3)
- centerText("Please enter your credentials to proceed", 5)
- local w, _ = term.getSize()
- local formWidth = 40
- local formX = math.floor(w / 2) - math.floor(formWidth / 2)
- -- Username prompt and input field
- term.setCursorPos(formX, 7)
- term.write("Username: ")
- term.setCursorPos(formX + 10, 7)
- local username = read()
- -- Password prompt and input field
- term.setCursorPos(formX, 9)
- term.write("Password: ")
- term.setCursorPos(formX + 10, 9)
- local password = read("*") -- Masked input for password
- -- Verify credentials
- if verifyCredentials(username, password) then
- centerText("Authentication successful", 12)
- os.sleep(1)
- showMenu()
- handleSelection()
- else
- centerText("Invalid credentials. Access denied.", 12)
- os.sleep(2)
- os.reboot()
- end
- end
- -- Start authentication process
- authenticate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement