Advertisement
Guest User

bash

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