2 LuCI - 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("luci.sgi.haserl", package.seeall)
32 -- Returns the main dispatcher URL
33 function luci.http.dispatcher()
34 return luci.http.env.SCRIPT_NAME or ""
37 -- Returns the upload dispatcher URL
38 function luci.http.dispatcher_upload()
39 return luci.http.dispatcher() .. "-upload"
42 -- Returns a table of all COOKIE, GET and POST Parameters
43 function luci.http.formvalues()
47 -- Gets form value from key
48 function luci.http.formvalue(key, default)
49 local c = luci.http.formvalues()
51 for match in key:gmatch("[%w-_]+") do
61 -- Gets a table of values with a certain prefix
62 function luci.http.formvaluetable(prefix)
63 return luci.http.formvalue(prefix, {})
66 -- Sends a custom HTTP-Header
67 function luci.http.header(key, value)
68 print(key .. ": " .. value)
72 function luci.http.prepare_content(type)
73 print("Content-Type: "..type.."\n")
76 -- Asks the browser to redirect to "url"
77 function luci.http.redirect(url)
78 luci.http.status(302, "Found")
79 luci.http.header("Location", url)
83 -- Returns the path of an uploaded file
84 -- WARNING! File uploads can be easily spoofed! Do additional sanity checks!
85 function luci.http.upload(name)
86 local fpath = luci.http.formvalue(name)
87 local fname = luci.http.formvalue(name .. "_name")
89 if fpath and fname and luci.fs.isfile(fpath) then
94 -- Sets HTTP-Status-Header
95 function luci.http.status(code, message)
96 print("Status: " .. tostring(code) .. " " .. message)