3 nixio = require "nixio"
4 fs = require "nixio.fs"
6 util = require "luci.util"
7 ltn12 = require "ltn12"
9 local function is_in_dir(file, dir)
13 return file:sub(1, #dir) == dir
19 for dummy,param in pairs(util.split(nixio.getenv('QUERY_STRING'),'&')) do
20 val = util.split(param,'=')
21 args[val[1]] = util.urldecode(val[2],true)
24 local u_c = uci.cursor()
25 local basepath = u_c.get("filemanager","config","basedir")
27 path = fs.realpath(basepath..'/'..args["path"])
29 file = io.open(path,"rb")
34 if file and is_in_dir(path,basepath) then
35 print("Content-Type: application/octet-stream")
36 print('Content-Disposition: attachment; filename="'..fs.basename(args["path"])..'"')
39 ltn12.source.file(file),
40 ltn12.sink.file(io.stdout)
43 print("Status: 404 Not Found")
44 print("Content-Type: text/plain")
46 print("File not found")