1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-21 18:57:41 +00:00

rttp initial version -- insecure

This commit is contained in:
kepler155c@gmail.com
2018-03-30 13:12:46 -04:00
parent a17677730f
commit 3dd351cc86
8 changed files with 272 additions and 4 deletions

57
sys/apis/fs/redfs.lua Normal file
View File

@@ -0,0 +1,57 @@
--[[
Mount a readonly file system from another computer across rednet. The
target computer must be running OpusOS or redserver.
Syntax:
rn://<id>/directory/subdir
Examples:
rn://12/usr/etc
rn://8/usr
]]--
local rttp = require('rttp')
local fs = _G.fs
local redfs = { }
local function getListing(uri)
local success, response = rttp.get(uri .. '?recursive=true')
if not success then
error(response)
end
if response.statusCode ~= 200 then
error('Received response ' .. response.statusCode)
end
local list = { }
for _,v in pairs(response.data) do
if not v.isDir then
list[v.path] = {
url = uri .. '/' .. v.path,
size = v.size,
}
end
end
return list
end
function redfs.mount(dir, uri)
if not uri then
error('redfs syntax: uri')
end
local list = getListing(uri)
for path, entry in pairs(list) do
if not fs.exists(fs.combine(dir, path)) then
local node = fs.mount(fs.combine(dir, path), 'urlfs', entry.url)
node.size = entry.size
end
end
end
return redfs

View File

@@ -1,3 +1,4 @@
local rttp = require('rttp')
local Util = require('util')
local fs = _G.fs
@@ -50,7 +51,12 @@ function urlfs.open(node, fn, fl)
local c = node.cache
if not c then
c = Util.httpGet(node.url)
if node.url:match('^([%w][%w%+%-%.]*)%:') == 'rn' then
local s, response = rttp.get(node.url)
c = s and response.statusCode == 200 and response.data
else
c = Util.httpGet(node.url)
end
if c then
node.cache = c
node.size = #c