Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cobalt = dofile( "cobalt" )
- cobalt.ui = dofile( "cobalt-ui/init.lua" )
- os.loadAPI("/var/var")
- os.loadAPI("/lib/login")
- os.loadAPI("/lib/hash")
- settings.load("/etc/.users")
- local Panel = cobalt.ui.new({ w = "50%", marginleft="25%", h = "50%", margintop = "25%" })
- local Text = Panel:add("text", {text=var.hostname.." login", wrap="center"})
- Text.y=4
- local Username = Panel:add( "input", {
- w = "80%",
- marginleft="10%",
- y = 6,
- backPassiveColour = colours.lightGrey,
- forePassiveColour = colours.grey,
- backActiveColour = colours.lightGrey,
- placeholder = "Username",
- placeholderColour = colours.grey,
- })
- local Password = Panel:add( "input", {
- w = "80%",
- marginleft="10%",
- y = 8,
- backPassiveColour = colours.lightGrey,
- forePassiveColour = colours.grey,
- backActiveColour = colours.lightGrey,
- placeholder = "Password",
- placeholderColour = colours.grey,
- mask = "*",
- })
- local Button = Panel:add("button", {wrap="center",y=10})
- Button.text = "Log In"
- Button.backColour = colors.blue
- Button.onclick = function()
- settings.load("/etc/.users")
- local passwd = settings.get(Username.text)
- local pwd = hash.digest(Password.text)
- if textutils.serialize(pwd) == textutils.serialize(passwd) then
- auth({true, Username.text})
- else
- Text.text = "Password incorrect!"
- end
- end
- function cobalt.draw()
- cobalt.ui.draw()
- end
- function cobalt.update( dt )
- cobalt.ui.update( dt )
- end
- function cobalt.mousepressed( x, y, button )
- cobalt.ui.mousepressed( x, y, button )
- end
- function cobalt.mousereleased( x, y, button )
- cobalt.ui.mousereleased( x, y, button )
- end
- function cobalt.keypressed( keycode, key )
- cobalt.ui.keypressed( keycode, key )
- end
- function cobalt.keyreleased( keycode, key )
- cobalt.ui.keyreleased( keycode, key )
- end
- function cobalt.textinput( t )
- cobalt.ui.textinput( t )
- end
- function getCurrentDir(username)
- local dir = shell.dir()
- if dir == "home/" .. username then
- return "~/"
- else
- return "/" .. dir
- end
- end
- function runShell(username)
- while true do
- term.write(username .. "@" .. var.hostname .. "[" .. getCurrentDir(username) .. "]: ")
- local cmd = io.read()
- local cursorX, cursorY = term.getCursorPos()
- term.setCursorPos(1, cursorY)
- if cmd == "exit" then
- break
- elseif cmd == "cd ~ " then
- shell.run("cd", "/home/" .. username)
- else
- shell.run(cmd)
- end
- end
- end
- function auth(authCorrect)
- if authCorrect[1] == true then
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to Zinc Linux, ".. authCorrect[2])
- shell.run("cd", "/home/" .. authCorrect[2])
- runShell(authCorrect[2])
- end
- end
- cobalt.initLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement