Advertisement
Tatantyler

VirtualFSLayer Utilities Set

Jul 25th, 2013
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.29 KB | None | 0 0
  1. -- VirtualFSLayer Utilities Set (HTTP ver.)
  2.  
  3. local mountFile = [[
  4. -- VirtualFSLayer Utilities Set - mount
  5. local args = {...}
  6. if #args == 0 then
  7.     print("mount -- Mount a filesystem")
  8.     print("Usage: mount [mount point] [file] [encryption key]")
  9.     print("The file and encryption key parameters are optional.")
  10.     print("Mounting a filesystem with no file creates a RAM drive.")
  11.     print("Mounting a filesystem with no key creates an unencrypted file.")
  12.     print("To mount a network filesystem, mount this: \"c:[id]\". ")
  13.     print("For example, \"mount nfs c:9\" mounts computer 9 to \"nfs/\".")
  14.     print("The encryption key will be interpreted as a password.")
  15.     print("The file will be created if it doesn't exist.")
  16.     print("Only one filesystem can be mounted at a time!")
  17.     return
  18. end
  19.  
  20. if not VirtualFSLayer then
  21.     if not os.loadAPI("VirtualFSLayer") then
  22.         error("Could not load VirtualFSLayer!")
  23.     end
  24. end
  25.  
  26. VirtualFSLayer.mount(args[1], args[2], args[3])
  27. ]]
  28.  
  29. local unmountFile = [[
  30. -- VirtualFSLayer Utilities Set - unmount
  31.  
  32. if not VirtualFSLayer then
  33.     error("VirtualFSLayer has not loaded.")
  34. end
  35.  
  36. print("Unmounting filesystem, this may take a bit..")
  37. VirtualFSLayer.unmount()
  38. ]]
  39.  
  40. local setTypeFile = [[
  41. -- VirtualFSLayer Utilities Set - setFSMode
  42. local args = {...}
  43. if #args == 0 then
  44.     print("setFSMode -- Set filesystem settings")
  45.     print("Usage: setFSMode [mode] [file] [key]")
  46.     print("Available modes are: ")
  47.     print("0 - RAM drive")
  48.     print("1 - Unencrypted file (requires file parameter)")
  49.     print("2 - Encrypted file (requires file and key parameters)")
  50.     print("2 - Network Filesystem")
  51.     print("When switching to NetFS, the file is interpreted as a server ID")
  52.     print("and the key is interpereted as a password.")
  53.     return
  54. end
  55.  
  56. if not VirtualFSLayer then
  57.     if not os.loadAPI("VirtualFSLayer") then
  58.         error("Could not load VirtualFSLayer!")
  59.     end
  60. end
  61.  
  62. if VirtualFSLayer.getMode() == -1 then
  63.     error("No filesystem is loaded!")
  64. end
  65.  
  66. if args[1] == "0" then
  67.     VirtualFSLayer.makeMemdisk()
  68. elseif args[1] == "1" then
  69.     if args[2] then
  70.         VirtualFSLayer.makeUnencrypted()
  71.         VirtualFSLayer.setLoadedFile(args[2])
  72.     else
  73.         error("You need to specify a file!")
  74.     end
  75. elseif args[1] == "2" then
  76.     if args[2] and args[3] then
  77.         VirtualFSLayer.makeEncrypted(args[3])
  78.         VirtualFSLayer.setLoadedFile(args[2])
  79.     else
  80.         error("You need to specify a file and key!")
  81.     end
  82. elseif args[1] == "3" then
  83.     args[2] = tonumber(args[2])
  84.     if args[2] then
  85.         VirtualFSLayer.makeNFS(args[2], args[3])
  86.     end
  87. else
  88.     error("Unrecognized mode.")
  89. end
  90. ]]
  91.  
  92. local getMountedFile = [[
  93. if not VirtualFSLayer then
  94.     error("VirtualFSLayer has not loaded.")
  95. end
  96.  
  97. if VirtualFSLayer.getMode() == -1 then
  98.     error("No filesystem is loaded!")
  99. end
  100.  
  101. print(VirtualFSLayer.getLoadedFile().." is mounted to "..VirtualFSLayer.getMountPath())
  102. ]]
  103.  
  104. local syncFile = [[
  105. local args = {...}
  106. if not VirtualFSLayer then
  107.     error("VirtualFSLayer has not loaded.")
  108. end
  109.  
  110. if VirtualFSLayer.getMode() == -1 then
  111.     error("No filesystem is loaded!")
  112. end
  113.  
  114. if VirtualFSLayer.getMode() == 0 then
  115.     error("The active filesystem is a RAM drive!")
  116. end
  117.  
  118. print("Synchronizing the filesystem, this may take a bit...")
  119. VirtualFSLayer.flush(unpack(args))
  120. ]]
  121.  
  122. local function installStr(file, str)
  123.     local f = fs.open(file, "w")
  124.     f.write(str)
  125.     f.close()
  126.     print("Installed: "..file)
  127. end
  128.  
  129. if not fs.exists("VirtualFSLayer") then
  130.     if http then
  131.         local h = http.get("http://pastebin.com/raw.php?i=knR5v4QU")
  132.         if h then
  133.             local data = h.readAll()
  134.             h.close()
  135.             installStr("VirtualFSLayer", data)
  136.         else
  137.             print("Cannot download the VirtualFSLayer.")
  138.             print("We don't really know what went wrong.")
  139.             print("Try again later, maybe?")
  140.         end
  141.     else
  142.         print("Cannot download the VirtualFSLayer.")
  143.         print("Please pester your server admin to enable the HTTP API,")
  144.         print("or, alternatively, turn it on yourself.")
  145.     end
  146. end
  147. if not fs.exists("base64") then
  148.     if http then
  149.         local h = http.get("http://pastebin.com/raw.php?i=pp3kpb19")
  150.         if h then
  151.             local data = h.readAll()
  152.             h.close()
  153.             installStr("base64", data)
  154.         else
  155.             print("Cannot download the base64 library.")
  156.             print("Unfortunately, we don't know what went wrong.")
  157.             print("You should try again later.")
  158.             print("VirtualFSLayer needs this library to run.")
  159.         end
  160.     end
  161. end
  162. installStr("mount", mountFile)
  163. installStr("unmount", unmountFile)
  164. installStr("setFSMode", setTypeFile)
  165. installStr("getMountedFile", getMountedFile)
  166. installStr("sync", syncFile)
  167. if http then
  168.     print("Optionally: Do you want to install the AES and SHA2 libraries?")
  169.     print("These are required for encrypted filesystem access.")
  170.     write("[y/n]> ")
  171.     local dec = string.lower(string.sub(read(), 1, 1))
  172.     if dec == "y" then
  173.         local h = http.get("http://pastebin.com/raw.php?i=9c1h7812")
  174.         if h then
  175.             local data = h.readAll()
  176.             h.close()
  177.             installStr("SHA2", data)
  178.         else
  179.             print("Couldn't download the SHA2 library.")
  180.             print("We don't know what went wrong.")
  181.             print("Don't worry though, just try again later.")
  182.             print("You don't need this library to use encrypted filesystems.")
  183.         end
  184.        
  185.         local h = http.get("http://pastebin.com/raw.php?i=rCYDnCxn")
  186.         if h then
  187.             local data = h.readAll()
  188.             h.close()
  189.             installStr("AES", data)
  190.         else
  191.             print("Could not download the AES library.")
  192.             print("We have no idea what went wrong.")
  193.             print("You'll probably want to try again later.")
  194.             print("You need this library to use encrypted filesystems.")
  195.         end
  196.     else
  197.         if dec == "n" then
  198.             print("Okay. Skipping...")
  199.         else
  200.             print("I'll take that as a no then. Skipping...")
  201.         end
  202.     end
  203.     print("Also optional: Do you want to install the SHA1 library?")
  204.     print("This is required to mount NetFS servers.")
  205.     write("[y/n]> ")
  206.     local dec = string.lower(string.sub(read(), 1, 1))
  207.     if dec == "y" then
  208.         local h = http.get("http://pastebin.com/raw.php?i=QvtjCy9h")
  209.         if h then
  210.             local data = h.readAll()
  211.             h.close()
  212.             installStr("SHA1", data)
  213.         else
  214.             print("Couldn't download the SHA1 library.")
  215.             print("We can't determine what went wrong.")
  216.             print("Please try again later.")
  217.             print("Like I said above, you need this to mount NetFS servers.")
  218.         end
  219.     else
  220.         if dec == "n" then
  221.             print("Okay then. Skipping...")
  222.         else
  223.             print("I'm assuming that's a no. Skipping.")
  224.         end
  225.     end
  226. end
  227. print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement