nixio = require "nixio"
fs = require "nixio.fs"
-uci = require("uci")
util = require "luci.util"
ltn12 = require "ltn12"
-
-local function is_in_dir(file, dir)
- if file == dir then
- return true
- else
- return file:sub(1, #dir) == dir
- end
-end
+luafm = require "luafm"
args = {}
args[val[1]] = util.urldecode(val[2],true)
end
-local u_c = uci.cursor()
-local basepath = u_c.get("filemanager","config","basedir")
-
-path = fs.realpath(basepath..'/'..args["path"])
+path = luafm.make_path(args["path"])
if path then
file = io.open(path,"rb")
else
file = nil
end
-if file and is_in_dir(path,basepath) then
+if file then
print("Content-Type: application/octet-stream")
print('Content-Disposition: attachment; filename="'..fs.basename(args["path"])..'"')
print("\r")