Advertisement
Shuudoushi

new root

Dec 14th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local term = require("term")
  2. local shell = require("shell")
  3. local keyboard = require("keyboard")
  4. local computer = require("computer")
  5. local event = require("event")
  6. local io = require("io")
  7.  
  8. u = io.open("/username.dat", "r")
  9.  textu = u:read()
  10.   u:close()
  11.  
  12. us = io.open("/usernames.dat", "r")
  13.  textus = us:read()
  14.   us:close()
  15.  
  16. ps = io.open("/passwords.dat", "r")
  17.  textps = ps:read()
  18.   ps:close()
  19.  
  20. local dir = shell.getWorkingDirectory()
  21. local userHome = "/usr/home/" .. textu .. "/"
  22.  
  23. function root()
  24.  if dir ~= userHome and dir <= userHome then
  25.   local needSuper = "true"
  26.   print("This action requires root access.")
  27.  end
  28. end
  29.  
  30. function super()
  31.  if needSuper == true then
  32.   print("User: ")
  33.   username = term.read()
  34.   username = string.gsub(username, "\n", "")
  35.   print("Password: ")
  36.   password = term.read(nil, nil, nil, "")
  37.   password = string.gsub(password, "\n", "")
  38. end
  39.  if username == textus and password == textps then
  40.   local superUser = "true"
  41.   print("Logged in as Root.")
  42.   os.sleep(1)
  43.   os.setenv("PS1", "root" .. "@" .. textu .. "$ ")
  44.   shell.setWorkingDirectory("/")
  45.  else
  46.   print("Login failed.")
  47.  end
  48. end
  49.  
  50. while true do
  51.   root()
  52.  if root == needSuper then
  53.   super()
  54. end
  55.  if superUser == true then
  56.   break
  57.  end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement