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 -- Enforces user authentification
33 function luci.http.basic_auth(verify_callback, realm)
38 -- Returns the main dispatcher URL
39 function luci.http.dispatcher()
40 return luci.http.env.SCRIPT_NAME or ""
43 -- Returns the upload dispatcher URL
44 function luci.http.dispatcher_upload()
45 return luci.http.dispatcher() .. "-upload"
48 -- Returns a table of all COOKIE, GET and POST Parameters
49 function luci.http.formvalues()
53 -- Gets form value from key
54 function luci.http.formvalue(key, default)
55 local c = luci.http.formvalues()
57 for match in key:gmatch("[%w-_]+") do
67 -- Gets a table of values with a certain prefix
68 function luci.http.formvaluetable(prefix)
69 return luci.http.formvalue(prefix, {})
72 -- Sends a custom HTTP-Header
73 function luci.http.header(key, value)
74 print(key .. ": " .. value)
78 function luci.http.prepare_content(type)
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)
92 local fpath = luci.http.formvalue(name)
93 local fname = luci.http.formvalue(name .. "_name")
95 if fpath and fname and luci.fs.isfile(fpath) then
100 -- Sets HTTP-Status-Header
101 function luci.http.status(code, message)
102 print("Status: " .. tostring(code) .. " " .. message)