* General code cleanup
* Removed unnecessary module dependencies * Completed SGI abstraction * Reworked ffluci.sgi.webuci
This commit is contained in:
parent
21bd8ca76d
commit
fc65325c17
16 changed files with 107 additions and 42 deletions
15
contrib/package/lua-luci/patches/200-lua-path
Normal file
15
contrib/package/lua-luci/patches/200-lua-path
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
--- b/src/luaconf.h 2008-05-06 20:10:46.000000000 +0200
|
||||||
|
+++ a/src/luaconf.h 2008-05-06 20:10:27.000000000 +0200
|
||||||
|
@@ -95,9 +95,9 @@
|
||||||
|
".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
|
||||||
|
|
||||||
|
#else
|
||||||
|
-#define LUA_ROOT "/usr/local/"
|
||||||
|
-#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
|
||||||
|
-#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
|
||||||
|
+#define LUA_ROOT "/usr/"
|
||||||
|
+#define LUA_LDIR LUA_ROOT "share/lua/"
|
||||||
|
+#define LUA_CDIR LUA_ROOT "lib/lua/"
|
||||||
|
#define LUA_PATH_DEFAULT \
|
||||||
|
"./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
|
||||||
|
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
|
|
@ -1,2 +1,22 @@
|
||||||
package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path
|
package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path
|
||||||
package.cpath = "/usr/lib/lua/?.so;" .. package.cpath
|
package.cpath = "/usr/lib/lua/?.so;" .. package.cpath
|
||||||
|
module("webuci", package.seeall)
|
||||||
|
|
||||||
|
function prepare_req(uri)
|
||||||
|
require("ffluci.menu").get()
|
||||||
|
REQUEST_URI = uri
|
||||||
|
end
|
||||||
|
|
||||||
|
function init_req(context)
|
||||||
|
SERVER_PROTOCOL = context.server_proto
|
||||||
|
REMOTE_ADDR = context.remote_addr
|
||||||
|
REQUEST_METHOD = context.request_method
|
||||||
|
PATH_INFO = "/" .. context.uri
|
||||||
|
REMOTE_PORT = context.remote_port
|
||||||
|
SERVER_ADDR = context.server_addr
|
||||||
|
SCRIPT_NAME = REQUEST_URI:sub(1, #REQUEST_URI - #context.uri)
|
||||||
|
end
|
||||||
|
|
||||||
|
function handle_req(context)
|
||||||
|
require("ffluci.dispatcher").httpdispatch()
|
||||||
|
end
|
|
@ -39,8 +39,9 @@ function load(cbimap)
|
||||||
require("ffluci.fs")
|
require("ffluci.fs")
|
||||||
require("ffluci.i18n")
|
require("ffluci.i18n")
|
||||||
require("ffluci.config")
|
require("ffluci.config")
|
||||||
|
require("ffluci.sys")
|
||||||
|
|
||||||
local cbidir = ffluci.config.path .. "/model/cbi/"
|
local cbidir = ffluci.sys.libpath() .. "/model/cbi/"
|
||||||
local func, err = loadfile(cbidir..cbimap..".lua")
|
local func, err = loadfile(cbidir..cbimap..".lua")
|
||||||
|
|
||||||
if not func then
|
if not func then
|
||||||
|
|
|
@ -28,10 +28,7 @@ limitations under the License.
|
||||||
module("ffluci.config", package.seeall)
|
module("ffluci.config", package.seeall)
|
||||||
require("ffluci.model.uci")
|
require("ffluci.model.uci")
|
||||||
require("ffluci.util")
|
require("ffluci.util")
|
||||||
require("ffluci.debug")
|
require("ffluci.sys")
|
||||||
|
|
||||||
-- Our path (wtf Lua lacks __file__ support)
|
|
||||||
path = ffluci.debug.path
|
|
||||||
|
|
||||||
-- Warning! This is only for fallback and compatibility purporses! --
|
-- Warning! This is only for fallback and compatibility purporses! --
|
||||||
main = {}
|
main = {}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
module("ffluci.debug", package.seeall)
|
module("ffluci.debug", package.seeall)
|
||||||
path = require("ffluci.fs").dirname(debug.getinfo(1, 'S').source:sub(2))
|
__file__ = debug.getinfo(1, 'S').source:sub(2)
|
|
@ -150,7 +150,7 @@ end
|
||||||
|
|
||||||
-- Dispatches a request depending on the PATH_INFO variable
|
-- Dispatches a request depending on the PATH_INFO variable
|
||||||
function httpdispatch()
|
function httpdispatch()
|
||||||
local pathinfo = os.getenv("PATH_INFO") or ""
|
local pathinfo = ffluci.http.get_path_info() or ""
|
||||||
local parts = pathinfo:gmatch("/[%w-]+")
|
local parts = pathinfo:gmatch("/[%w-]+")
|
||||||
|
|
||||||
local sanitize = function(s, default)
|
local sanitize = function(s, default)
|
||||||
|
|
|
@ -28,6 +28,11 @@ module("ffluci.fs", package.seeall)
|
||||||
|
|
||||||
require("posix")
|
require("posix")
|
||||||
|
|
||||||
|
-- Glob
|
||||||
|
function glob(pattern)
|
||||||
|
return posix.glob(pattern)
|
||||||
|
end
|
||||||
|
|
||||||
-- Checks whether a file exists
|
-- Checks whether a file exists
|
||||||
function isfile(filename)
|
function isfile(filename)
|
||||||
local fp = io.open(path, "r")
|
local fp = io.open(path, "r")
|
||||||
|
|
|
@ -25,11 +25,11 @@ limitations under the License.
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
module("ffluci.i18n", package.seeall)
|
module("ffluci.i18n", package.seeall)
|
||||||
|
|
||||||
require("ffluci.config")
|
require("ffluci.config")
|
||||||
|
require("ffluci.sys")
|
||||||
|
|
||||||
table = {}
|
table = {}
|
||||||
i18ndir = ffluci.config.path .. "/i18n/"
|
i18ndir = ffluci.sys.libpath() .. "/i18n/"
|
||||||
|
|
||||||
-- Clears the translation table
|
-- Clears the translation table
|
||||||
function clear()
|
function clear()
|
||||||
|
|
|
@ -27,18 +27,15 @@ module("ffluci.menu", package.seeall)
|
||||||
|
|
||||||
require("ffluci.fs")
|
require("ffluci.fs")
|
||||||
require("ffluci.util")
|
require("ffluci.util")
|
||||||
require("ffluci.template")
|
require("ffluci.sys")
|
||||||
require("ffluci.i18n")
|
|
||||||
require("ffluci.config")
|
|
||||||
require("ffluci.model.ipkg")
|
|
||||||
|
|
||||||
-- Default modelpath
|
-- Default modelpath
|
||||||
modelpath = ffluci.config.path .. "/model/menu/"
|
modelpath = ffluci.sys.libpath() .. "/model/menu/"
|
||||||
|
|
||||||
-- Menu definition extra scope
|
-- Menu definition extra scope
|
||||||
scope = {
|
scope = {
|
||||||
translate = ffluci.i18n.translate,
|
translate = function(...) return require("ffluci.i18n").translate(...) end,
|
||||||
loadtrans = ffluci.i18n.loadc,
|
loadtrans = function(...) return require("ffluci.i18n").loadc(...) end,
|
||||||
isfile = ffluci.fs.mtime
|
isfile = ffluci.fs.mtime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +98,24 @@ end
|
||||||
|
|
||||||
-- Collect all menu information provided in the model dir
|
-- Collect all menu information provided in the model dir
|
||||||
function collect()
|
function collect()
|
||||||
|
local generators = {}
|
||||||
|
|
||||||
for k, menu in pairs(ffluci.fs.dir(modelpath)) do
|
for k, menu in pairs(ffluci.fs.dir(modelpath)) do
|
||||||
if menu:sub(1, 1) ~= "." then
|
if menu:sub(1, 1) ~= "." then
|
||||||
local f = loadfile(modelpath.."/"..menu)
|
local f = loadfile(modelpath.."/"..menu)
|
||||||
|
if f then
|
||||||
|
table.insert(generators, f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return generators
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Parse the collected information
|
||||||
|
function parse(generators)
|
||||||
|
menu = {}
|
||||||
|
for i, f in pairs(generators) do
|
||||||
local env = ffluci.util.clone(scope)
|
local env = ffluci.util.clone(scope)
|
||||||
|
|
||||||
env.add = add
|
env.add = add
|
||||||
|
@ -113,14 +125,13 @@ function collect()
|
||||||
setfenv(f, env)
|
setfenv(f, env)
|
||||||
f()
|
f()
|
||||||
end
|
end
|
||||||
end
|
return menu
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns the menu information
|
-- Returns the menu information
|
||||||
function get()
|
function get()
|
||||||
if not menu then
|
if not menu then
|
||||||
menu = {}
|
menu = parse(collect())
|
||||||
collect()
|
|
||||||
end
|
end
|
||||||
return menu
|
return menu
|
||||||
end
|
end
|
|
@ -54,12 +54,21 @@ function ffluci.http.formvaluetable(prefix)
|
||||||
return ffluci.http.formvalue(prefix, {})
|
return ffluci.http.formvalue(prefix, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the path info
|
||||||
|
function ffluci.http.get_path_info()
|
||||||
|
return ENV.PATH_INFO
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns the User's IP
|
-- Returns the User's IP
|
||||||
function ffluci.http.get_remote_addr()
|
function ffluci.http.get_remote_addr()
|
||||||
return ENV.REMOTE_ADDR
|
return ENV.REMOTE_ADDR
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the request URI
|
||||||
|
function ffluci.http.get_request_uri()
|
||||||
|
return ENV.REQUEST_URI
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns the script name
|
-- Returns the script name
|
||||||
function ffluci.http.get_script_name()
|
function ffluci.http.get_script_name()
|
||||||
return ENV.SCRIPT_NAME
|
return ENV.SCRIPT_NAME
|
||||||
|
|
|
@ -51,15 +51,25 @@ function ffluci.http.formvaluetable(prefix)
|
||||||
return vals
|
return vals
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the path info
|
||||||
|
function ffluci.http.get_path_info()
|
||||||
|
return webuci.PATH_INFO
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns the User's IP
|
-- Returns the User's IP
|
||||||
function ffluci.http.get_remote_addr()
|
function ffluci.http.get_remote_addr()
|
||||||
return os.getenv("REMOTE_ADDR")
|
return webuci.REMOTE_ADDR
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the request URI
|
||||||
|
function ffluci.http.get_request_uri()
|
||||||
|
return webuci.REQUEST_URI
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Returns the script name
|
-- Returns the script name
|
||||||
function ffluci.http.get_script_name()
|
function ffluci.http.get_script_name()
|
||||||
return os.getenv("SCRIPT_NAME")
|
return webuci.SCRIPT_NAME
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,5 +91,5 @@ end
|
||||||
|
|
||||||
-- Sets HTTP-Status-Header
|
-- Sets HTTP-Status-Header
|
||||||
function ffluci.http.set_status(code, message)
|
function ffluci.http.set_status(code, message)
|
||||||
print("Status: " .. tostring(code) .. " " .. message)
|
print(webuci.REQUEST_METHOD .. " " .. tostring(code) .. " " .. message)
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,6 +82,11 @@ function httpget(url)
|
||||||
return exec("wget -qO- '"..url:gsub("'", "").."'")
|
return exec("wget -qO- '"..url:gsub("'", "").."'")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the FFLuci-Basedir
|
||||||
|
function libpath()
|
||||||
|
return ffluci.fs.dirname(require("ffluci.debug").__file__)
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns the load average
|
-- Returns the load average
|
||||||
function loadavg()
|
function loadavg()
|
||||||
local loadavg = io.lines("/proc/loadavg")()
|
local loadavg = io.lines("/proc/loadavg")()
|
||||||
|
|
|
@ -28,11 +28,9 @@ module("ffluci.template", package.seeall)
|
||||||
require("ffluci.config")
|
require("ffluci.config")
|
||||||
require("ffluci.util")
|
require("ffluci.util")
|
||||||
require("ffluci.fs")
|
require("ffluci.fs")
|
||||||
require("ffluci.i18n")
|
|
||||||
require("ffluci.http")
|
require("ffluci.http")
|
||||||
require("ffluci.model.uci")
|
|
||||||
|
|
||||||
viewdir = ffluci.config.path .. "/view/"
|
viewdir = ffluci.sys.libpath() .. "/view/"
|
||||||
|
|
||||||
|
|
||||||
-- Compile modes:
|
-- Compile modes:
|
||||||
|
@ -52,8 +50,8 @@ compiler_enable_bytecode = false
|
||||||
|
|
||||||
-- Define the namespace for template modules
|
-- Define the namespace for template modules
|
||||||
viewns = {
|
viewns = {
|
||||||
translate = ffluci.i18n.translate,
|
translate = function(...) return require("ffluci.i18n").translate(...) end,
|
||||||
config = function(...) return ffluci.model.uci.get(...) or "" end,
|
config = function(...) return require("ffluci.model.uci").get(...) or "" end,
|
||||||
controller = ffluci.http.get_script_name(),
|
controller = ffluci.http.get_script_name(),
|
||||||
media = ffluci.config.main.mediaurlbase,
|
media = ffluci.config.main.mediaurlbase,
|
||||||
write = io.write,
|
write = io.write,
|
||||||
|
|
|
@ -139,12 +139,6 @@ function resfenv(f)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Returns the Haserl unique sessionid
|
|
||||||
function sessionid()
|
|
||||||
return ENV.SESSIONID
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Splits a string into an array
|
-- Splits a string into an array
|
||||||
function split(str, pat, max, regex)
|
function split(str, pat, max, regex)
|
||||||
pat = pat or "\n"
|
pat = pat or "\n"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%+header%>
|
<%+header%>
|
||||||
<form method="post" action="<%=os.getenv("REQUEST_URI")%>">
|
<form method="post" action="<%=ffluci.http.get_request_uri()%>">
|
||||||
<div>
|
<div>
|
||||||
<script type="text/javascript" src="<%=media%>/cbi.js"></script>
|
<script type="text/javascript" src="<%=media%>/cbi.js"></script>
|
||||||
<input type="hidden" name="cbi.submit" value="1" />
|
<input type="hidden" name="cbi.submit" value="1" />
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%+header%>
|
<%+header%>
|
||||||
<h1>404 Not Found</h1>
|
<h1>404 Not Found</h1>
|
||||||
<p>Sorry, the object you requested was not found.</p>
|
<p>Sorry, the object you requested was not found.</p>
|
||||||
<tt>Unable to dispatch: <%=os.getenv("PATH_INFO")%></tt>
|
<tt>Unable to dispatch: <%=ffluci.http.get_path_info()%></tt>
|
||||||
<%+footer%>
|
<%+footer%>
|
Loading…
Reference in a new issue