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)
29 luci.http.env = webuci.env
32 local status_set = false
34 -- Returns the main dispatcher URL
35 function luci.http.dispatcher()
36 return luci.http.env.SCRIPT_NAME or ""
39 -- Returns the upload dispatcher URL
40 function luci.http.dispatcher_upload()
44 -- Returns a table of all COOKIE, GET and POST Parameters
45 function luci.http.formvalues()
49 -- Gets form value from key
50 function luci.http.formvalue(key, default)
51 return luci.http.formvalues()[key] or default
54 -- Gets a table of values with a certain prefix
55 function luci.http.formvaluetable(prefix)
57 prefix = prefix and prefix .. "." or "."
59 for k, v in pairs(luci.http.formvalues()) do
60 if k:find(prefix, 1, true) == 1 then
61 vals[k:sub(#prefix + 1)] = v
68 -- Sends a custom HTTP-Header
69 function luci.http.header(key, value)
70 print(key .. ": " .. value)
74 function luci.http.prepare_content(type)
75 if not status_set then
76 luci.http.status(200, "OK")
79 print("Content-Type: "..type.."\n")
82 -- Asks the browser to redirect to "url"
83 function luci.http.redirect(url)
84 luci.http.status(302, "Found")
85 luci.http.header("Location", url)
89 -- Returns the path of an uploaded file
90 -- WARNING! File uploads can be easily spoofed! Do additional sanity checks!
91 function luci.http.upload(name)
95 -- Sets HTTP-Status-Header
96 function luci.http.status(code, message)
97 print(webuci.env.SERVER_PROTOCOL .. " " .. tostring(code) .. " " .. message)