Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GUI setup
- local w, h = term.getSize()
- local screen = window.create(term.current(), 1, 1, w, h)
- -- Function to clear the screen and reset cursor
- local function clearScreen()
- screen.clear()
- screen.setCursorPos(1, 1)
- end
- -- Function to create borders for the UI
- local function createBorder()
- -- Top border
- screen.setCursorPos(1, 1)
- for i = 1, w do
- screen.write("-")
- end
- -- Bottom border
- screen.setCursorPos(1, h)
- for i = 1, w do
- screen.write("-")
- end
- end
- -- Function to draw a header section
- local function drawHeader(title)
- screen.setCursorPos(1, 1)
- createBorder()
- screen.setCursorPos(math.floor((w - #title) / 2), 2)
- screen.write(title)
- screen.setCursorPos(1, 3)
- for i = 1, w do
- screen.write("-")
- end
- end
- -- Function to check if file exists
- local function fileExists(path)
- local file = fs.open(path, "r")
- if file then
- file.close()
- return true
- else
- return false
- end
- end
- -- Function to get user input for authentication
- local function authenticateUser()
- clearScreen()
- drawHeader("Kiosk Setup - Authentication")
- screen.setCursorPos(1, 4)
- screen.write("Enter your username: ")
- local username = read()
- local passwordFile = "/disk/users/" .. username .. "/password.txt"
- if not fileExists(passwordFile) then
- screen.setCursorPos(1, 6)
- screen.write("User does not exist.")
- sleep(2)
- return false
- end
- local file = fs.open(passwordFile, "r")
- local storedPassword = file.readAll()
- file.close()
- screen.setCursorPos(1, 6)
- screen.write("Enter your password: ")
- local enteredPassword = read()
- if enteredPassword == storedPassword then
- local adminFile = "/disk/users/" .. username .. "/admin.txt"
- if fileExists(adminFile) then
- return true
- else
- screen.setCursorPos(1, 7)
- screen.write("Admin privileges required.")
- sleep(2)
- return false
- end
- else
- screen.setCursorPos(1, 7)
- screen.write("Invalid password.")
- sleep(2)
- return false
- end
- end
- -- Function to check Kiosk setup and app status
- local function checkKioskApp()
- clearScreen()
- drawHeader("Kiosk Setup Status")
- if not fileExists("/disk/embeded/sysapp.lua") then
- screen.setCursorPos(1, 4)
- screen.write("ERROR: Kiosk not set up or application missing.")
- sleep(2)
- return false
- else
- local file = fs.open("/disk/embeded/sysapp.lua", "r")
- local appContent = file.readAll()
- file.close()
- -- Check for a corrupted app (example: check if file is empty)
- if #appContent == 0 then
- screen.setCursorPos(1, 4)
- screen.write("ERROR: Application file is corrupted.")
- sleep(2)
- return false
- else
- screen.setCursorPos(1, 4)
- screen.write("Kiosk is set up and ready.")
- sleep(2)
- return true
- end
- end
- end
- -- Function to allow setting up a new Kiosk app
- local function setupKioskApp()
- clearScreen()
- drawHeader("Set Up New Kiosk App")
- if authenticateUser() then
- clearScreen()
- drawHeader("Kiosk Setup - New App")
- screen.setCursorPos(1, 4)
- screen.write("Is the new app a local file or a Pastebin program? (file/pastebin): ")
- local appType = read()
- if appType == "file" then
- clearScreen()
- drawHeader("Local File Upload")
- screen.setCursorPos(1, 4)
- screen.write("Enter the file path of the new app: ")
- local appPath = read()
- if not fileExists(appPath) then
- clearScreen()
- drawHeader("Error")
- screen.setCursorPos(1, 4)
- screen.write("File does not exist.")
- sleep(2)
- else
- local appFile = fs.open(appPath, "r")
- local appContent = appFile.readAll()
- appFile.close()
- local sysAppFile = fs.open("/disk/embeded/sysapp.lua", "w")
- sysAppFile.write(appContent)
- sysAppFile.close()
- clearScreen()
- drawHeader("Success")
- screen.setCursorPos(1, 4)
- screen.write("App copied successfully to /disk/embeded/sysapp.lua")
- sleep(2)
- end
- elseif appType == "pastebin" then
- clearScreen()
- drawHeader("Pastebin Program")
- screen.setCursorPos(1, 4)
- screen.write("Enter the Pastebin program ID: ")
- local pastebinID = read()
- local pastebinURL = "https://pastebin.com/raw/" .. pastebinID
- local pastebinContent = http.get(pastebinURL).readAll()
- local sysAppFile = fs.open("/disk/embeded/sysapp.lua", "w")
- sysAppFile.write(pastebinContent)
- sysAppFile.close()
- clearScreen()
- drawHeader("Success")
- screen.setCursorPos(1, 4)
- screen.write("App copied from Pastebin to /disk/embeded/sysapp.lua")
- sleep(2)
- else
- clearScreen()
- drawHeader("Error")
- screen.setCursorPos(1, 4)
- screen.write("Invalid choice.")
- sleep(2)
- end
- else
- clearScreen()
- drawHeader("Error")
- screen.setCursorPos(1, 4)
- screen.write("Authentication failed.")
- sleep(2)
- end
- end
- -- Main program
- if checkKioskApp() then
- shell.run("/disk/embeded/sysapp.lua")
- else
- setupKioskApp()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement