Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open = fs.open
- --Checks for program in ./su
- rBCKP = os.reboot
- function os.reboot()
- os.reboot = rBCKP
- fs.delete("/.tempsu")
- File = fs.open("/.tempsu","a")
- File.close()
- os.reboot()
- end
- function chkSU(progname)
- fs.open = open
- if fs.exists("/.su") then
- SU = fs.open("/.su","r")
- TSU = fs.open("/.tempsu","r")
- TSUA = TSU.readAll()
- Cont = SU.readAll()
- TSU.close()
- SU.close()
- if fs.exists(progname) then
- A = ("/??"..progname.."/??")
- if string.find(Cont,A) or string.find(TSUA,A) then
- return true
- else
- return false
- end
- else
- print("Program Not Found In System")
- end
- end
- end
- --Adds Program to .su
- local function addRoot(progname)
- SU = fs.open("/.su","a")
- SU.writeLine("/??"..progname.."/??")
- SU.close()
- end
- --Adds Program to .tempSU
- local function tempSU(progname)
- local TempFile = fs.open("/.tempsu","a")
- TempFile.writeLine("/??"..progname.."/??")
- TempFile.close()
- end
- --Prompts the user for input on whether
- --or not to run root functions
- function PromptUser(progname)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- print(progname.."is trying to use root functions.")
- print("Allow "..progname.." root access?")
- print("Enter Y (yes) N (no) or T (temproot)")
- local ans = read()
- if ans == "Y" then
- --ALLOW ROOT ACCESS PERMANANTLY
- addRoot(progname)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- return true
- elseif ans == "N" then
- --DENY ROOT ACCESS UNTIL REQUESTED AGAIN
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- return false
- elseif ans == "T" then
- --GIVE ROOT ACCESS FOR THIS BOOT
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- tempSU(progname)
- return true
- else
- print("exiting root manager")
- sleep(1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- end
- sleep(0)
- end
- --Requests SU on program 'A'
- function SUReq(A)
- if chkSU(A) == true then
- return true
- else
- return PromptUser(A)
- end
- end
Add Comment
Please, Sign In to add comment