luci/libs/sgi-webuci/luasrc/sgi/webuci.lua
Steven Barth 4365fbe2a3 Squashed commit of the following:
commit d45d1757d24d8214f730af1a3401dd2bef4a434f
Author: Steven <steven@cyrus.homeunix.org>
Date:   Wed May 28 17:23:27 2008 +0200

    * libs/core: Removed dummymode checks in sys
    * libs/sgi-webuci: Fixes

commit b870e8d345bc8912fd8ab61d463b9d68b924a6f4
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Wed May 28 15:40:10 2008 +0200

    fix path to theme

commit e3732926bd98db4cc38de6eb8018cd4e55176699
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Wed May 28 14:56:03 2008 +0200

    set the proper path to the config in dummy mode

commit a75aecf46f037c98bd6e49b9e48adb735d76d150
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Wed May 28 14:50:42 2008 +0200

    add some dummy mode support

commit 12bb39ef606bca6b403cc982213a6597b76dc1b3
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Wed May 28 14:41:56 2008 +0200

    normalize paths

commit 7aaad1103fd2bdc75aca158baa6ef191f9a961c6
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Wed May 28 14:27:26 2008 +0200

    add missing require statement

commit 5766274bd2511b00c42b474aeeeb3efaca6ded9b
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Wed May 28 14:19:54 2008 +0200

    add optional luaposix package (patched for darwin support)

commit 9e257a76d03722fc0ce8312aa9952641b21424bd
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Tue May 27 20:21:59 2008 +0200

    add missing files, more integration for the boa plugin, fix path to lua modules

commit dacc1a98ec946975fcb19f87076dfa7db865fca6
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Tue May 27 19:42:37 2008 +0200

    use "compile" instead of "source" and rename the old version of compile to "compile-all"

commit eb14777c4fee1eb5740aba1e5603e481320da7b1
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Tue May 27 19:41:59 2008 +0200

    more boa integration

commit df0afb965bf0a987b653e9d0acadf3151179a596
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Tue May 27 18:33:42 2008 +0200

    build boa and the webuci.so plugin along with sgi-webuci

commit 878161dabf32066631103d199e2cbaf3f5a7fb07
Author: Felix Fietkau <nbd@openwrt.org>
Date:   Tue May 27 18:03:16 2008 +0200

    add .gitignore
2008-05-28 15:28:13 +00:00

101 lines
2.4 KiB
Lua

--[[
LuCI - SGI-Module for Haserl
Description:
Server Gateway Interface for Haserl
FileId:
$Id: webuci.lua 2027 2008-05-07 21:16:35Z Cyrus $
License:
Copyright 2008 Steven Barth <steven@midlink.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]--
module("luci.sgi.webuci", package.seeall)
local status_set = false
-- Initialize the environment
function initenv(env, vars)
luci.http.env = env
luci.http.vars = vars
end
-- Returns the main dispatcher URL
function luci.http.dispatcher()
return luci.http.env.SCRIPT_NAME or ""
end
-- Returns the upload dispatcher URL
function luci.http.dispatcher_upload()
-- To be implemented
end
-- Returns a table of all COOKIE, GET and POST Parameters
function luci.http.formvalues()
return luci.http.vars
end
-- Gets form value from key
function luci.http.formvalue(key, default)
return luci.http.formvalues()[key] or default
end
-- Gets a table of values with a certain prefix
function luci.http.formvaluetable(prefix)
local vals = {}
prefix = prefix and prefix .. "." or "."
for k, v in pairs(luci.http.formvalues()) do
if k:find(prefix, 1, true) == 1 then
vals[k:sub(#prefix + 1)] = v
end
end
return vals
end
-- Sends a custom HTTP-Header
function luci.http.header(key, value)
print(key .. ": " .. value)
end
-- Set Content-Type
function luci.http.prepare_content(type)
if not status_set then
luci.http.status(200, "OK")
end
print("Content-Type: "..type.."\n")
end
-- Asks the browser to redirect to "url"
function luci.http.redirect(url)
luci.http.status(302, "Found")
luci.http.header("Location", url)
print()
end
-- Returns the path of an uploaded file
-- WARNING! File uploads can be easily spoofed! Do additional sanity checks!
function luci.http.upload(name)
-- To be implemented
end
-- Sets HTTP-Status-Header
function luci.http.status(code, message)
print(luci.http.env.SERVER_PROTOCOL .. " " .. tostring(code) .. " " .. message)
status_set = true
end