Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- VirtualFSLayer Utilities Set (HTTP ver.)
- local mountFile = [[
- -- VirtualFSLayer Utilities Set - mount
- local args = {...}
- if #args == 0 then
- print("mount -- Mount a filesystem")
- print("Usage: mount [mount point] [file] [encryption key]")
- print("The file and encryption key parameters are optional.")
- print("Mounting a filesystem with no file creates a RAM drive.")
- print("Mounting a filesystem with no key creates an unencrypted file.")
- print("To mount a network filesystem, mount this: \"c:[id]\". ")
- print("For example, \"mount nfs c:9\" mounts computer 9 to \"nfs/\".")
- print("The encryption key will be interpreted as a password.")
- print("The file will be created if it doesn't exist.")
- print("Only one filesystem can be mounted at a time!")
- return
- end
- if not VirtualFSLayer then
- if not os.loadAPI("VirtualFSLayer") then
- error("Could not load VirtualFSLayer!")
- end
- end
- VirtualFSLayer.mount(args[1], args[2], args[3])
- ]]
- local unmountFile = [[
- -- VirtualFSLayer Utilities Set - unmount
- if not VirtualFSLayer then
- error("VirtualFSLayer has not loaded.")
- end
- print("Unmounting filesystem, this may take a bit..")
- VirtualFSLayer.unmount()
- ]]
- local setTypeFile = [[
- -- VirtualFSLayer Utilities Set - setFSMode
- local args = {...}
- if #args == 0 then
- print("setFSMode -- Set filesystem settings")
- print("Usage: setFSMode [mode] [file] [key]")
- print("Available modes are: ")
- print("0 - RAM drive")
- print("1 - Unencrypted file (requires file parameter)")
- print("2 - Encrypted file (requires file and key parameters)")
- print("2 - Network Filesystem")
- print("When switching to NetFS, the file is interpreted as a server ID")
- print("and the key is interpereted as a password.")
- return
- end
- if not VirtualFSLayer then
- if not os.loadAPI("VirtualFSLayer") then
- error("Could not load VirtualFSLayer!")
- end
- end
- if VirtualFSLayer.getMode() == -1 then
- error("No filesystem is loaded!")
- end
- if args[1] == "0" then
- VirtualFSLayer.makeMemdisk()
- elseif args[1] == "1" then
- if args[2] then
- VirtualFSLayer.makeUnencrypted()
- VirtualFSLayer.setLoadedFile(args[2])
- else
- error("You need to specify a file!")
- end
- elseif args[1] == "2" then
- if args[2] and args[3] then
- VirtualFSLayer.makeEncrypted(args[3])
- VirtualFSLayer.setLoadedFile(args[2])
- else
- error("You need to specify a file and key!")
- end
- elseif args[1] == "3" then
- args[2] = tonumber(args[2])
- if args[2] then
- VirtualFSLayer.makeNFS(args[2], args[3])
- end
- else
- error("Unrecognized mode.")
- end
- ]]
- local getMountedFile = [[
- if not VirtualFSLayer then
- error("VirtualFSLayer has not loaded.")
- end
- if VirtualFSLayer.getMode() == -1 then
- error("No filesystem is loaded!")
- end
- print(VirtualFSLayer.getLoadedFile().." is mounted to "..VirtualFSLayer.getMountPath())
- ]]
- local syncFile = [[
- local args = {...}
- if not VirtualFSLayer then
- error("VirtualFSLayer has not loaded.")
- end
- if VirtualFSLayer.getMode() == -1 then
- error("No filesystem is loaded!")
- end
- if VirtualFSLayer.getMode() == 0 then
- error("The active filesystem is a RAM drive!")
- end
- print("Synchronizing the filesystem, this may take a bit...")
- VirtualFSLayer.flush(unpack(args))
- ]]
- local function installStr(file, str)
- local f = fs.open(file, "w")
- f.write(str)
- f.close()
- print("Installed: "..file)
- end
- if not fs.exists("VirtualFSLayer") then
- if http then
- local h = http.get("http://pastebin.com/raw.php?i=knR5v4QU")
- if h then
- local data = h.readAll()
- h.close()
- installStr("VirtualFSLayer", data)
- else
- print("Cannot download the VirtualFSLayer.")
- print("We don't really know what went wrong.")
- print("Try again later, maybe?")
- end
- else
- print("Cannot download the VirtualFSLayer.")
- print("Please pester your server admin to enable the HTTP API,")
- print("or, alternatively, turn it on yourself.")
- end
- end
- if not fs.exists("base64") then
- if http then
- local h = http.get("http://pastebin.com/raw.php?i=pp3kpb19")
- if h then
- local data = h.readAll()
- h.close()
- installStr("base64", data)
- else
- print("Cannot download the base64 library.")
- print("Unfortunately, we don't know what went wrong.")
- print("You should try again later.")
- print("VirtualFSLayer needs this library to run.")
- end
- end
- end
- installStr("mount", mountFile)
- installStr("unmount", unmountFile)
- installStr("setFSMode", setTypeFile)
- installStr("getMountedFile", getMountedFile)
- installStr("sync", syncFile)
- if http then
- print("Optionally: Do you want to install the AES and SHA2 libraries?")
- print("These are required for encrypted filesystem access.")
- write("[y/n]> ")
- local dec = string.lower(string.sub(read(), 1, 1))
- if dec == "y" then
- local h = http.get("http://pastebin.com/raw.php?i=9c1h7812")
- if h then
- local data = h.readAll()
- h.close()
- installStr("SHA2", data)
- else
- print("Couldn't download the SHA2 library.")
- print("We don't know what went wrong.")
- print("Don't worry though, just try again later.")
- print("You don't need this library to use encrypted filesystems.")
- end
- local h = http.get("http://pastebin.com/raw.php?i=rCYDnCxn")
- if h then
- local data = h.readAll()
- h.close()
- installStr("AES", data)
- else
- print("Could not download the AES library.")
- print("We have no idea what went wrong.")
- print("You'll probably want to try again later.")
- print("You need this library to use encrypted filesystems.")
- end
- else
- if dec == "n" then
- print("Okay. Skipping...")
- else
- print("I'll take that as a no then. Skipping...")
- end
- end
- print("Also optional: Do you want to install the SHA1 library?")
- print("This is required to mount NetFS servers.")
- write("[y/n]> ")
- local dec = string.lower(string.sub(read(), 1, 1))
- if dec == "y" then
- local h = http.get("http://pastebin.com/raw.php?i=QvtjCy9h")
- if h then
- local data = h.readAll()
- h.close()
- installStr("SHA1", data)
- else
- print("Couldn't download the SHA1 library.")
- print("We can't determine what went wrong.")
- print("Please try again later.")
- print("Like I said above, you need this to mount NetFS servers.")
- end
- else
- if dec == "n" then
- print("Okay then. Skipping...")
- else
- print("I'm assuming that's a no. Skipping.")
- end
- end
- end
- print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement