Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args={...}
- local sandboxed = args[1]
- local privTable={}
- --Debug:
- --print(sandboxed)
- --Check if loaded...
- if fs.setReadOnly then error("Already loaded!!!",2) end
- privTable["aliases"]=shell.aliases()
- --Backup FS declaration...
- local oFs={}
- for k, v in pairs(fs) do
- oFs[k]=v
- end
- --Backup others declaration...
- local oldDfile=dofile
- local oldLfile=loadfile
- local err = error
- --Security declarations...
- local oldsenv=setfenv
- local rT={[1] = sandboxed}
- local function check(filename)
- for k,v in pairs(rT) do
- if v==filename then return true end
- end
- return false
- end
- local function isAllowed()
- --stub function, change it to fit your OS'es needs.
- return false
- end
- local function errorout()
- err("Insufficient permissions.",3)
- end
- --Start with the declaring...
- function fs.open(f,v)
- f=sandboxed..f or sandboxed
- if isAllowed() then return oFs.open(f,v) end
- if v ~= ("r" or "rb" or nil) then
- if check(f) then
- errorout()
- end
- end
- return oFs.open(f,v)
- end
- function fs.exists(f)
- f=sandboxed..f or sandboxed
- return oFs.exists(f)
- end
- function fs.isDir(f)
- f=sandboxed..f or sandboxed
- return oFs.isDir(f)
- end
- function fs.delete(f)
- f=sandboxed..f or sandboxed
- if isAllowed() then return oFs.delete(f) end
- if check(f) then
- errorout()
- end
- return oFs.delete(f)
- end
- function fs.copy(f,v)
- f=sandboxed..f or sandboxed
- v=sandboxed..v or sandboxed
- if isAllowed() then return oFs.copy(f,v) end
- if check(f) then
- errorout()
- end
- return oFs.copy(f,v)
- end
- function fs.move(f,v)
- f=sandboxed..f or sandboxed
- v=sandboxed..v or sandboxed
- if isAllowed() then return oFs.move(f,v) end
- if check(f) then
- errorout()
- end
- return oFs.move(f,v)
- end
- function fs.isReadOnly(f)
- f=sandboxed..f or sandboxed
- if check(f) then
- return true
- end
- return oFs.isReadOnly(f)
- end
- function fs.setReadOnly(file, bool)
- file=sandboxed..file or sandboxed
- if not isAllowed() then errorout() return nil end
- if not type(bool) == "boolean" then error("Boolean expected, got "..type(bool)..".") end
- if bool then
- if not check(file) then
- table.insert(rT, file)
- end
- return true
- else
- for k,v in pairs(rT) do
- if v == file then
- table.remove(rT, k)
- local derp = true
- end
- end
- if derp then return true end
- return false
- end
- end
- function fs.list(dir)
- if type(dir)=="string" then
- if string.sub(dir,#dir,#dir) == "/" then dir = string.sub(dir,1,#dir-1) end
- end
- dir=dir..sandboxed or sandboxed
- return oFs.list(dir)
- end
- function setfenv(...)
- return oldsenv(...)
- end
- function restore()
- if not isAllowed() then errorout() end
- fs={}
- for k,v in pairs(oFs) do
- fs[k]=v
- end
- dofile=oldDfile
- loadfile=oldLfile
- setfenv=oldsenv
- restore=nil
- for k,v in pairs(privTable.aliases) do
- shell.setAlias(k,v)
- end
- end
- --Clear aliases...
- for k,v in pairs(privTable.aliases) do
- shell.clearAlias(k,v)
- end
Advertisement
Add Comment
Please, Sign In to add comment