Guest User

SU

a guest
Jan 1st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. open = fs.open
  2. --Checks for program in ./su
  3. function chkSU(progname)
  4. fs.open = open
  5.   if fs.exists("/.su") then
  6. SU = fs.open("/.su","r")
  7. Cont = SU.readAll()
  8. SU.close()
  9.     if fs.exists(progname) then
  10.       if string.find(Cont,progname) then
  11.         return true
  12.       else
  13.         return false
  14.       end
  15.     else
  16.       print("Program Not Found In System")
  17.     end
  18.   end
  19. end
  20. --Adds Program to .su
  21. local function addRoot(progname)
  22. SU = fs.open("/.su","a")
  23. SU.write(progname)
  24. SU.close()
  25. end
  26. --Adds Program to .tempSU
  27. function tempSU()
  28.  
  29. end
  30. --Prompts the user for input on whether
  31. --or not to run root functions
  32. function PromptUser(progname)
  33. term.setBackgroundColor(colors.white)
  34. term.setTextColor(colors.black)
  35. term.clear()
  36. term.setCursorPos(1,1)
  37. print(progname.."is trying to use root functions.")
  38. print("Allow "..progname.." root access?")
  39. local evnt, key, held = os.pullEvent("key")
  40.   if key == 21 then
  41.   --ALLOW ROOT ACCESS PERMANANTLY
  42.   addRoot(progname)
  43.   elseif key == 49 then
  44.   --DENY ROOT ACCESS UNTIL REQUESTED AGAIN
  45.   elseif key == 20 then
  46.   --GIVE ROOT ACCESS FOR THIS BOOT
  47.   else
  48.   print("exiting root manager")
  49.   sleep(1)
  50.   term.setBackgroundColor(colors.black)
  51.   term.setTextColor(colors.white)
  52.   term.clear()
  53.   term.setCursorPos(1,1)
  54.   end
  55.  sleep(0)
  56. end
  57. --Requests SU on program 'A'
  58. function SUReq(A)
  59.   if chkSU(A) == true then
  60.     return "Root Already Gained"
  61.   else
  62.     PromptUser(A)
  63.   end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment