2 LuCI - SGI-Module for Haserl
5 Server Gateway Interface for Haserl
8 $Id: webuci.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.webuci", package.seeall)
28 local status_set = false
30 -- Initialize the environment
31 function initenv(env, vars)
36 -- Returns the main dispatcher URL
37 function luci.http.dispatcher()
38 return luci.http.env.SCRIPT_NAME or ""
41 -- Returns the upload dispatcher URL
42 function luci.http.dispatcher_upload()
46 -- Returns a table of all COOKIE, GET and POST Parameters
47 function luci.http.formvalues()
51 -- Gets form value from key
52 function luci.http.formvalue(key, default)
53 return luci.http.formvalues()[key] or default
56 -- Gets a table of values with a certain prefix
57 function luci.http.formvaluetable(prefix)
59 prefix = prefix and prefix .. "." or "."
61 for k, v in pairs(luci.http.formvalues()) do
62 if k:find(prefix, 1, true) == 1 then
63 vals[k:sub(#prefix + 1)] = v
70 -- Sends a custom HTTP-Header
71 function luci.http.header(key, value)
72 print(key .. ": " .. value)
76 function luci.http.prepare_content(type)
77 if not status_set then
78 luci.http.status(200, "OK")
81 print("Content-Type: "..type.."\n")
84 -- Asks the browser to redirect to "url"
85 function luci.http.redirect(url)
86 luci.http.status(302, "Found")
87 luci.http.header("Location", url)
91 -- Returns the path of an uploaded file
92 -- WARNING! File uploads can be easily spoofed! Do additional sanity checks!
93 function luci.http.upload(name)
97 -- Sets HTTP-Status-Header
98 function luci.http.status(code, message)
99 print(luci.http.env.SERVER_PROTOCOL .. " " .. tostring(code) .. " " .. message)