Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.setReadOnly ~= nil then error("Already loaded!") end
- local shellProgram = shell.getRunningProgram
- local oldOpen = fs.open
- local oldCopy = fs.copy
- local oldDelete = fs.delete
- local oldMove = fs.move
- local oldReadOnly = fs.isReadOnly
- local oldList = fs.list
- local rT = {}
- --local iR = {}
- local hidden = {}
- local allowedPrograms={}
- local function isAllowed()
- if #allowedPrograms==0 then return true end
- for k,v in pairs(allowedPrograms) do
- if v==shellProgram() then return true end
- end
- return false
- end
- local function hidecheck(filename)
- for k,v in pairs(hidden) do
- if v==filename then return true end
- end
- return false
- end
- --[
- local function readcheck(filename)
- for k,v in pairs(iR) do
- if v==filename then return true end
- end
- return false
- end
- --]
- local function check(filename)
- for k,v in pairs(rT) do
- if v==filename then return true end
- end
- --for k,v in pairs(iR) do
- --if v==filename then return true end
- --end
- return false
- end
- local function errorout()
- error("File is readonly", 0)
- end
- function fs.open(f,v)
- --if readcheck(v) then errorout() end
- if isAllowed() then return oldOpen(f,v) end
- if v ~= ("r" or "rb" or nil) then
- if check(f) then
- errorout()
- end
- end
- return oldOpen(f,v)
- end
- function fs.delete(f)
- if isAllowed() then return oldDelete(f) end
- if check(f) then
- errorout()
- end
- return oldDelete(f)
- end
- function fs.copy(f,v)
- if isAllowed() then return oldCopy(f,v) end
- if check(f) then
- errorout()
- end
- return oldCopy(f,v)
- end
- function fs.move(f,v)
- if isAllowed() then return oldMove(f,v) end
- if check(f) then
- errorout()
- end
- return oldMove(f,v)
- end
- function fs.isReadOnly(f)
- if check(f) then
- return true
- end
- return oldReadOnly(f)
- end
- function fs.setReadOnly(file, bool)
- if not isAllowed() then error("Not permitted.",2) 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)
- derp = true
- end
- end
- if derp then return true end
- return false
- end
- end
- --[
- function fs.setReadable(file, bool)
- if not type(bool) == "boolean" then error("Boolean expected, got "..type(bool)..".") end
- if not bool then
- table.insert(iR, file)
- return true
- else
- for k,v in pairs(iR) do
- if v == file then
- table.remove(iR, k)
- return true
- end
- end
- return false
- end
- end
- --]
- function fs.hide(file)
- if not isAllowed() then error("Not permitted.",2) return nil end
- if not hidecheck(file) then
- table.insert(hidden,file)
- end
- return true
- end
- function fs.show(file)
- if not isAllowed() then error("Not permitted.",2) return nil end
- for k,v in pairs(hidden) do
- if v==file then
- table.remove(hidden,k)
- derp = true
- end
- end
- derp = derp or false
- return derp
- end
- function fs.list(dir)
- local dir=dir or ""
- if isAllowed() then return oldList(dir) end
- if hidecheck(dir) then return {} end
- local d = oldList(dir)
- for k,v in pairs(d) do
- if hidecheck(v) then
- table.remove(d,k)
- end
- end
- return d
- end
- --Make all programs in config.permissions allowed
- while true do
- if not fs.exists("config.permissions") then break end
- local fh=fs.open("config.permissions", "r")
- while true do
- local line=fh.readLine()
- if line==nil then break end
- table.insert(allowedPrograms, line)
- end
- fh.close()
- break
- end
- --Hide and make read-only allowed programs
- for k,v in pairs(allowedPrograms) do
- if not check(v) then
- table.insert(rT,v)
- end
- if not hidecheck(v) then
- table.insert(hidden,v)
- end
- end
- table.insert(rT,"config.permissions")
- table.insert(hidden,"config.permissions")
- table.insert(rT,shellProgram())
- table.insert(hidden,shellProgram())
Advertisement
Add Comment
Please, Sign In to add comment