Advertisement
Guest User

bash

a guest
Jun 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. local cobalt = dofile( "cobalt" )
  2. cobalt.ui = dofile( "cobalt-ui/init.lua" )
  3. os.loadAPI("/var/var")
  4. os.loadAPI("/lib/login")
  5. settings.load("/etc/.users")
  6. local Panel = cobalt.ui.new({ w = "50%", marginleft="25%", h = "50%", margintop = "25%" })
  7. local Text = Panel:add("text", {text=var.hostname.." login", wrap="center"})
  8. Text.y=4
  9. local Username = Panel:add( "input", {
  10.     w = "80%",
  11.     marginleft="10%",
  12.     y = 6,
  13.     backPassiveColour = colours.lightGrey,
  14.     forePassiveColour = colours.grey,
  15.     backActiveColour = colours.lightGrey,
  16.     placeholder = "Username",
  17.     placeholderColour = colours.grey,
  18. })
  19. local Password = Panel:add( "input", {
  20.     w = "80%",
  21.     marginleft="10%",
  22.     y = 8,
  23.     backPassiveColour = colours.lightGrey,
  24.     forePassiveColour = colours.grey,
  25.     backActiveColour = colours.lightGrey,
  26.     placeholder = "Password",
  27.     placeholderColour = colours.grey,
  28.     mask = "*",
  29. })
  30. local Button = Panel:add("button", {wrap="center",y=10})
  31. Button.text = "Log In"
  32. Button.backColour = colors.blue
  33. Button.onclick = function()
  34.     local passwd = settings.get(Username.text)
  35.     if Password.text == passwd then
  36.         auth({true, Username.text})
  37.     end
  38. end
  39.  
  40. function cobalt.draw()
  41.   cobalt.ui.draw()
  42. end
  43.  
  44. function cobalt.update( dt )
  45.     cobalt.ui.update( dt )
  46. end
  47.  
  48. function cobalt.mousepressed( x, y, button )
  49.     cobalt.ui.mousepressed( x, y, button )
  50. end
  51.  
  52. function cobalt.mousereleased( x, y, button )
  53.     cobalt.ui.mousereleased( x, y, button )
  54. end
  55.  
  56. function cobalt.keypressed( keycode, key )
  57.     cobalt.ui.keypressed( keycode, key )
  58. end
  59.  
  60. function cobalt.keyreleased( keycode, key )
  61.     cobalt.ui.keyreleased( keycode, key )
  62. end
  63.  
  64. function cobalt.textinput( t )
  65.     cobalt.ui.textinput( t )
  66. end
  67.  
  68. function getCurrentDir(username)
  69.     local dir = shell.dir()
  70.     if dir == "home/" .. username then
  71.         return "~/"
  72.     else
  73.         return "/" .. dir
  74.     end
  75. end
  76.  
  77. function runShell(username)
  78.     while true do
  79.         term.write(username .. "@" .. var.hostname .. "[" .. getCurrentDir(username) .. "]: ")
  80.         local cmd = io.read()
  81.         local cursorX, cursorY = term.getCursorPos()
  82.         term.setCursorPos(1, cursorY)
  83.         if cmd == "exit" then
  84.             break
  85.         elseif cmd == "cd ~ " then
  86.             shell.run("cd", "/home/" .. username)
  87.         else
  88.             shell.run(cmd)
  89.         end
  90.     end
  91. end
  92. function auth(authCorrect)
  93. if authCorrect[1] == true then
  94.     term.clear()
  95.     term.setCursorPos(1,1)
  96.     print("Welcome to Zinc Linux, ".. authCorrect[2])
  97.     shell.run("cd", "/home/" .. authCorrect[2])
  98.     runShell(authCorrect[2])
  99. end
  100. end
  101. cobalt.initLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement