3 local cgi = require "cgi"
4 local uci = require("uci")
5 local fs = require("nixio.fs")
6 local os = require("os")
7 local json = require("json")
11 local function is_in_dir(file, dir)
15 return file:sub(1, #dir) == dir
24 ret, msg = cgi.parse_request_body(req)
27 destfile=io.open(req.post["destination"][1]["tempname"],"r")
28 destination=destfile:read("*all")
30 local u_c = uci.cursor()
31 local basepath = u_c.get("filemanager","config","basedir")
33 for k, v in pairs(req.post) do
34 for j, v in pairs(req.post[k]) do
36 path = basepath..destination..'/'..v.filename
37 dir = fs.realpath(fs.dirname(path))
38 if dir and is_in_dir(dir,basepath) then
39 fs.copy(req.post[k][j].tempname, path)
47 print('{ "result": { "success": true, "error": null } }')