Advertisement
Shuudoushi

kodos

Nov 2nd, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. local keyboard = require("keyboard")
  2. local computer = require("computer")
  3. local fs = require("filesystem")
  4. local event = require("event")
  5. local shell = require("shell")
  6. local auth = require("auth")
  7. local term = require("term")
  8.  
  9. local running = true
  10.  
  11. while running do
  12.   if fs.exists("/installer.lua") then -- Auto deletes the installer at first boot.
  13.     fs.remove("/installer.lua")
  14.   end
  15.  
  16.   local username = ""
  17.   local password = ""
  18.  
  19.   login = auth.validate(username, password)
  20.  
  21.   if login then
  22.     auth.userLog(username, "login_pass")
  23.     if not fs.get("/tmp/").isReadOnly() then
  24.       hn = io.open("/tmp/.hostname.dat", "w") -- Writes the user inputted username to file for future use.
  25.        hn:write(username)
  26.         hn:close()
  27.       os.setenv("HOME", "/home/" .. username)
  28.       os.setenv("USER", username)
  29.       os.setenv("PATH", "/bin:/sbin:/usr/bin:/home/".. username .."/bin:.")
  30.     end
  31.  
  32.     local file = io.open("/etc/hostname")
  33.  
  34.     if file then
  35.       os.setenv("PS1", username .. "@" .. file:read("*l") .. "# ")
  36.       file:close()
  37.     else
  38.       os.setenv("PS1", username .. "@" .. username .. "# ")
  39.     end
  40.  
  41.     shell.setWorkingDirectory("/home/" .. username .. "/")
  42.     username, password = "" -- This is just a "bandaid fix" till I find a better way of doing it.
  43.     if fs.isAutorunEnabled() == false then
  44.       fs.setAutorunEnabled(true)
  45.     end
  46.     running = false
  47.     shell.execute("/.autorun.lua")
  48.   else
  49.     auth.userLog(username, "login_fail")
  50.     term.clear()
  51.     term.setCursor(1,1)
  52.     io.stderr:write("Login failed: Invalid information.")
  53.     os.sleep(2.5)
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement