#!/usr/bin/lua local cgi = require "cgi" local uci = require("uci") local fs = require("nixio.fs") local os = require("os") local json = require("json") local req = {} local function is_in_dir(file, dir) if file == dir then return true else return file:sub(1, #dir) == dir end end print("\r") cgi.new(req) if req.boundary then ret, msg = cgi.parse_request_body(req) end destfile=io.open(req.post["destination"][1]["tempname"],"r") destination=destfile:read("*all") local u_c = uci.cursor() local basepath = u_c.get("filemanager","config","basedir") for k, v in pairs(req.post) do for j, v in pairs(req.post[k]) do if v["filename"] then path = basepath..destination..'/'..v.filename dir = fs.realpath(fs.dirname(path)) if dir and is_in_dir(dir,basepath) then fs.copy(req.post[k][j].tempname, path) end end end end cgi.cleanup(req) print('{ "result": { "success": true, "error": null } }')