summaryrefslogtreecommitdiffhomepage
path: root/core
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-05-06 20:44:45 +0000
committerSteven Barth <steven@midlink.org>2008-05-06 20:44:45 +0000
commitfc65325c174e13cc1a9329d154e74069257ebb12 (patch)
tree1c5813fa25f538989802eacf6fe45a2ed7b06867 /core
parent21bd8ca76deec06b8e4f4dc3bc2ea75c7f9c3260 (diff)
* General code cleanup
* Removed unnecessary module dependencies * Completed SGI abstraction * Reworked ffluci.sgi.webuci
Diffstat (limited to 'core')
-rw-r--r--core/contrib/webuci_bootstrap.lua20
-rw-r--r--core/src/ffluci/cbi.lua3
-rw-r--r--core/src/ffluci/config.lua5
-rw-r--r--core/src/ffluci/debug.lua2
-rw-r--r--core/src/ffluci/dispatcher.lua2
-rw-r--r--core/src/ffluci/fs.lua5
-rw-r--r--core/src/ffluci/i18n.lua4
-rw-r--r--core/src/ffluci/menu.lua45
-rw-r--r--core/src/ffluci/sgi/haserl.lua9
-rw-r--r--core/src/ffluci/sgi/webuci.lua16
-rw-r--r--core/src/ffluci/sys.lua5
-rw-r--r--core/src/ffluci/template.lua8
-rw-r--r--core/src/ffluci/util.lua6
-rw-r--r--core/src/ffluci/view/cbi/header.htm2
-rw-r--r--core/src/ffluci/view/error404.htm2
15 files changed, 92 insertions, 42 deletions
diff --git a/core/contrib/webuci_bootstrap.lua b/core/contrib/webuci_bootstrap.lua
index 173343707..fd4c47ab5 100644
--- a/core/contrib/webuci_bootstrap.lua
+++ b/core/contrib/webuci_bootstrap.lua
@@ -1,2 +1,22 @@
package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path
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 \ No newline at end of file
diff --git a/core/src/ffluci/cbi.lua b/core/src/ffluci/cbi.lua
index 4d6d25c39..3384e5c38 100644
--- a/core/src/ffluci/cbi.lua
+++ b/core/src/ffluci/cbi.lua
@@ -39,8 +39,9 @@ function load(cbimap)
require("ffluci.fs")
require("ffluci.i18n")
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")
if not func then
diff --git a/core/src/ffluci/config.lua b/core/src/ffluci/config.lua
index 90fa6b1c9..0db45ac89 100644
--- a/core/src/ffluci/config.lua
+++ b/core/src/ffluci/config.lua
@@ -28,10 +28,7 @@ limitations under the License.
module("ffluci.config", package.seeall)
require("ffluci.model.uci")
require("ffluci.util")
-require("ffluci.debug")
-
--- Our path (wtf Lua lacks __file__ support)
-path = ffluci.debug.path
+require("ffluci.sys")
-- Warning! This is only for fallback and compatibility purporses! --
main = {}
diff --git a/core/src/ffluci/debug.lua b/core/src/ffluci/debug.lua
index f1132edcc..1be40348e 100644
--- a/core/src/ffluci/debug.lua
+++ b/core/src/ffluci/debug.lua
@@ -1,2 +1,2 @@
module("ffluci.debug", package.seeall)
-path = require("ffluci.fs").dirname(debug.getinfo(1, 'S').source:sub(2)) \ No newline at end of file
+__file__ = debug.getinfo(1, 'S').source:sub(2) \ No newline at end of file
diff --git a/core/src/ffluci/dispatcher.lua b/core/src/ffluci/dispatcher.lua
index 15ac3c7b3..813e35d59 100644
--- a/core/src/ffluci/dispatcher.lua
+++ b/core/src/ffluci/dispatcher.lua
@@ -150,7 +150,7 @@ end
-- Dispatches a request depending on the PATH_INFO variable
function httpdispatch()
- local pathinfo = os.getenv("PATH_INFO") or ""
+ local pathinfo = ffluci.http.get_path_info() or ""
local parts = pathinfo:gmatch("/[%w-]+")
local sanitize = function(s, default)
diff --git a/core/src/ffluci/fs.lua b/core/src/ffluci/fs.lua
index 6e8859a0d..3eb562b80 100644
--- a/core/src/ffluci/fs.lua
+++ b/core/src/ffluci/fs.lua
@@ -28,6 +28,11 @@ module("ffluci.fs", package.seeall)
require("posix")
+-- Glob
+function glob(pattern)
+ return posix.glob(pattern)
+end
+
-- Checks whether a file exists
function isfile(filename)
local fp = io.open(path, "r")
diff --git a/core/src/ffluci/i18n.lua b/core/src/ffluci/i18n.lua
index 11f4afe87..489308cc9 100644
--- a/core/src/ffluci/i18n.lua
+++ b/core/src/ffluci/i18n.lua
@@ -25,11 +25,11 @@ limitations under the License.
]]--
module("ffluci.i18n", package.seeall)
-
require("ffluci.config")
+require("ffluci.sys")
table = {}
-i18ndir = ffluci.config.path .. "/i18n/"
+i18ndir = ffluci.sys.libpath() .. "/i18n/"
-- Clears the translation table
function clear()
diff --git a/core/src/ffluci/menu.lua b/core/src/ffluci/menu.lua
index e55c0e76a..5cbb725a4 100644
--- a/core/src/ffluci/menu.lua
+++ b/core/src/ffluci/menu.lua
@@ -27,18 +27,15 @@ module("ffluci.menu", package.seeall)
require("ffluci.fs")
require("ffluci.util")
-require("ffluci.template")
-require("ffluci.i18n")
-require("ffluci.config")
-require("ffluci.model.ipkg")
+require("ffluci.sys")
-- Default modelpath
-modelpath = ffluci.config.path .. "/model/menu/"
+modelpath = ffluci.sys.libpath() .. "/model/menu/"
-- Menu definition extra scope
scope = {
- translate = ffluci.i18n.translate,
- loadtrans = ffluci.i18n.loadc,
+ translate = function(...) return require("ffluci.i18n").translate(...) end,
+ loadtrans = function(...) return require("ffluci.i18n").loadc(...) end,
isfile = ffluci.fs.mtime
}
@@ -101,26 +98,40 @@ end
-- Collect all menu information provided in the model dir
function collect()
+ local generators = {}
+
for k, menu in pairs(ffluci.fs.dir(modelpath)) do
if menu:sub(1, 1) ~= "." then
local f = loadfile(modelpath.."/"..menu)
- local env = ffluci.util.clone(scope)
-
- env.add = add
- env.sel = sel
- env.act = act
-
- setfenv(f, env)
- f()
+ 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)
+
+ env.add = add
+ env.sel = sel
+ env.act = act
+
+ setfenv(f, env)
+ f()
+ end
+ return menu
end
-- Returns the menu information
function get()
if not menu then
- menu = {}
- collect()
+ menu = parse(collect())
end
return menu
end \ No newline at end of file
diff --git a/core/src/ffluci/sgi/haserl.lua b/core/src/ffluci/sgi/haserl.lua
index 76dc3854a..e58189d1c 100644
--- a/core/src/ffluci/sgi/haserl.lua
+++ b/core/src/ffluci/sgi/haserl.lua
@@ -54,12 +54,21 @@ function ffluci.http.formvaluetable(prefix)
return ffluci.http.formvalue(prefix, {})
end
+-- Returns the path info
+function ffluci.http.get_path_info()
+ return ENV.PATH_INFO
+end
-- Returns the User's IP
function ffluci.http.get_remote_addr()
return ENV.REMOTE_ADDR
end
+-- Returns the request URI
+function ffluci.http.get_request_uri()
+ return ENV.REQUEST_URI
+end
+
-- Returns the script name
function ffluci.http.get_script_name()
return ENV.SCRIPT_NAME
diff --git a/core/src/ffluci/sgi/webuci.lua b/core/src/ffluci/sgi/webuci.lua
index 297780295..c60964662 100644
--- a/core/src/ffluci/sgi/webuci.lua
+++ b/core/src/ffluci/sgi/webuci.lua
@@ -51,15 +51,25 @@ function ffluci.http.formvaluetable(prefix)
return vals
end
+-- Returns the path info
+function ffluci.http.get_path_info()
+ return webuci.PATH_INFO
+end
-- Returns the User's IP
function ffluci.http.get_remote_addr()
- return os.getenv("REMOTE_ADDR")
+ return webuci.REMOTE_ADDR
+end
+
+-- Returns the request URI
+function ffluci.http.get_request_uri()
+ return webuci.REQUEST_URI
end
+
-- Returns the script name
function ffluci.http.get_script_name()
- return os.getenv("SCRIPT_NAME")
+ return webuci.SCRIPT_NAME
end
@@ -81,5 +91,5 @@ end
-- Sets HTTP-Status-Header
function ffluci.http.set_status(code, message)
- print("Status: " .. tostring(code) .. " " .. message)
+ print(webuci.REQUEST_METHOD .. " " .. tostring(code) .. " " .. message)
end
diff --git a/core/src/ffluci/sys.lua b/core/src/ffluci/sys.lua
index d71bce71b..376654893 100644
--- a/core/src/ffluci/sys.lua
+++ b/core/src/ffluci/sys.lua
@@ -82,6 +82,11 @@ function httpget(url)
return exec("wget -qO- '"..url:gsub("'", "").."'")
end
+-- Returns the FFLuci-Basedir
+function libpath()
+ return ffluci.fs.dirname(require("ffluci.debug").__file__)
+end
+
-- Returns the load average
function loadavg()
local loadavg = io.lines("/proc/loadavg")()
diff --git a/core/src/ffluci/template.lua b/core/src/ffluci/template.lua
index 04cc07dbb..a972f2bc4 100644
--- a/core/src/ffluci/template.lua
+++ b/core/src/ffluci/template.lua
@@ -28,11 +28,9 @@ module("ffluci.template", package.seeall)
require("ffluci.config")
require("ffluci.util")
require("ffluci.fs")
-require("ffluci.i18n")
require("ffluci.http")
-require("ffluci.model.uci")
-viewdir = ffluci.config.path .. "/view/"
+viewdir = ffluci.sys.libpath() .. "/view/"
-- Compile modes:
@@ -52,8 +50,8 @@ compiler_enable_bytecode = false
-- Define the namespace for template modules
viewns = {
- translate = ffluci.i18n.translate,
- config = function(...) return ffluci.model.uci.get(...) or "" end,
+ translate = function(...) return require("ffluci.i18n").translate(...) end,
+ config = function(...) return require("ffluci.model.uci").get(...) or "" end,
controller = ffluci.http.get_script_name(),
media = ffluci.config.main.mediaurlbase,
write = io.write,
diff --git a/core/src/ffluci/util.lua b/core/src/ffluci/util.lua
index 3ff7bc203..b76278dda 100644
--- a/core/src/ffluci/util.lua
+++ b/core/src/ffluci/util.lua
@@ -139,12 +139,6 @@ function resfenv(f)
end
--- Returns the Haserl unique sessionid
-function sessionid()
- return ENV.SESSIONID
-end
-
-
-- Splits a string into an array
function split(str, pat, max, regex)
pat = pat or "\n"
diff --git a/core/src/ffluci/view/cbi/header.htm b/core/src/ffluci/view/cbi/header.htm
index 1b69a3a31..97542f031 100644
--- a/core/src/ffluci/view/cbi/header.htm
+++ b/core/src/ffluci/view/cbi/header.htm
@@ -1,5 +1,5 @@
<%+header%>
- <form method="post" action="<%=os.getenv("REQUEST_URI")%>">
+ <form method="post" action="<%=ffluci.http.get_request_uri()%>">
<div>
<script type="text/javascript" src="<%=media%>/cbi.js"></script>
<input type="hidden" name="cbi.submit" value="1" />
diff --git a/core/src/ffluci/view/error404.htm b/core/src/ffluci/view/error404.htm
index adc671de0..1a9d74a9f 100644
--- a/core/src/ffluci/view/error404.htm
+++ b/core/src/ffluci/view/error404.htm
@@ -1,5 +1,5 @@
<%+header%>
<h1>404 Not Found</h1>
<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%> \ No newline at end of file