* applications/sgi-haserl: Added ffluci.http.upload for file uploads
[project/luci.git] / applications / sgi-haserl / src / sgi / haserl.lua
index 027697e2e4e48ec20afea99b7ba5f2661b06da62..0e388391dbe976095c5aa2ff2ca5658d77532ac6 100644 (file)
@@ -24,6 +24,7 @@ limitations under the License.
 
 ]]--
 module("ffluci.sgi.haserl", package.seeall)
 
 ]]--
 module("ffluci.sgi.haserl", package.seeall)
+require("ffluci.fs")
 
 -- Environment Table
 ffluci.http.env = ENV
 
 -- Environment Table
 ffluci.http.env = ENV
@@ -70,6 +71,17 @@ function ffluci.http.redirect(url)
        print()
 end
 
        print()
 end
 
+-- Returns the path of an uploaded file
+-- WARNING! File uploads can be easily spoofed! Do additional sanity checks!
+function ffluci.http.upload(name)
+       local fpath = ffluci.http.formvalue(name)
+       local fname = ffluci.http.formvalue(name .. "_name")
+       
+       if fpath and fname and ffluci.fs.isfile(fpath) then
+               return fpath
+       end
+end
+
 -- Sets HTTP-Status-Header
 function ffluci.http.status(code, message)
        print("Status: " .. tostring(code) .. " " .. message)
 -- Sets HTTP-Status-Header
 function ffluci.http.status(code, message)
        print("Status: " .. tostring(code) .. " " .. message)