2 FFLuCI - SGI-Module for Haserl
5 Server Gateway Interface for Haserl
8 $Id: haserl.lua 2027 2008-05-07 21:16:35Z Cyrus $
11 Copyright 2008 Steven Barth <steven@midlink.org>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
26 module("ffluci.sgi.haserl", package.seeall)
33 -- Returns a table of all COOKIE, GET and POST Parameters
34 function ffluci.http.formvalues()
38 -- Gets form value from key
39 function ffluci.http.formvalue(key, default)
40 local c = ffluci.http.formvalues()
42 for match in key:gmatch("[%w-_]+") do
52 -- Gets a table of values with a certain prefix
53 function ffluci.http.formvaluetable(prefix)
54 return ffluci.http.formvalue(prefix, {})
57 -- Sends a custom HTTP-Header
58 function ffluci.http.header(key, value)
59 print(key .. ": " .. value)
63 function ffluci.http.prepare_content(type)
64 print("Content-Type: "..type.."\n")
67 -- Asks the browser to redirect to "url"
68 function ffluci.http.redirect(url)
69 ffluci.http.status(302, "Found")
70 ffluci.http.header("Location", url)
74 -- Returns the path of an uploaded file
75 -- WARNING! File uploads can be easily spoofed! Do additional sanity checks!
76 function ffluci.http.upload(name)
77 local fpath = ffluci.http.formvalue(name)
78 local fname = ffluci.http.formvalue(name .. "_name")
80 if fpath and fname and ffluci.fs.isfile(fpath) then
85 -- Sets HTTP-Status-Header
86 function ffluci.http.status(code, message)
87 print("Status: " .. tostring(code) .. " " .. message)