#!/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 fs = require "nixio.fs"
+local luafm = require "luafm"
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)
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
+ path = luafm.make_new_path(destination..'/'..v.filename)
+ if path then
fs.copy(req.post[k][j].tempname, path)
end
end