end
luci.http.close()
+
+ --context._disable_memtrace()
end
--- Dispatches a LuCI virtual path.
-- @param request Virtual path
function dispatch(request)
+ --context._disable_memtrace = require "luci.debug".trap_memtrace()
local ctx = context
ctx.path = request
-- Init template engine
if not track.notemplate then
local tpl = require("luci.template")
- local viewns = {}
+ local viewns = setmetatable({}, {__index=_G})
tpl.context.viewns = viewns
viewns.write = luci.http.write
+ viewns.include = function(name) tpl.Template(name):render(getfenv(2)) end
viewns.translate = function(...) return require("luci.i18n").translate(...) end
viewns.striptags = util.striptags
viewns.controller = luci.http.getenv("SCRIPT_NAME")
viewns.REQUEST_URI = (luci.http.getenv("SCRIPT_NAME") or "") .. (luci.http.getenv("PATH_INFO") or "")
end
+ track.dependent = (track.dependent ~= false)
assert(not track.dependent or not track.auto, "Access Violation")
if track.sysauth then
local def = (type(track.sysauth) == "string") and track.sysauth
local accs = def and {track.sysauth} or track.sysauth
- local sess = luci.http.getcookie("sysauth")
+ local sess = ctx.authsession or luci.http.getcookie("sysauth")
sess = sess and sess:match("^[A-F0-9]+$")
local user = sauth.read(sess)
if not sess then
sauth.write(sid, user)
end
+ ctx.authsession = sid
end
else
luci.http.status(403, "Forbidden")
context.dispatched = c
util.copcall(function()
- util.updfenv(c.target, require(c.module))
+ local oldenv = getfenv(c.target)
+ local module = require(c.module)
+ local env = setmetatable({}, {__index=
+
+ function(tbl, key)
+ return rawget(tbl, key) or module[key] or oldenv[key]
+ end})
+
+ setfenv(c.target, env)
end)
c.target(unpack(args))
if indexcache then
local cachedate = fs.mtime(indexcache)
if cachedate and cachedate > fs.mtime(path) then
+
+ assert(
+ sys.process.info("uid") == fs.stat(indexcache, "uid")
+ and fs.stat(indexcache, "mode") == "rw-------",
+ "Fatal: Indexcache is not sane!"
+ )
+
index = loadfile(indexcache)()
return index
end
if indexcache then
fs.writefile(indexcache, util.get_bytecode(index))
+ fs.chmod(indexcache, "a-rwx,u+rw")
end
end
-- Load default translation
require "luci.i18n".loadc("default")
- local scope = setmetatable({}, {__index = _G})
- for k,v in pairs(_M) do
- if type(v) == "function" then
- scope[k] = v
- end
- end
+ local scope = setmetatable({}, {__index = luci.dispatcher})
for k, v in pairs(index) do
scope._NAME = k
require("luci.cbi")
require("luci.template")
- local stat, maps = luci.util.copcall(luci.cbi.load, model, ...)
- if not stat then
- error500(maps)
- return true
- end
+ maps = luci.cbi.load(model, ...)
for i, res in ipairs(maps) do
- local stat, err = luci.util.copcall(res.parse, res)
- if not stat then
- error500(err)
- return true
- end
+ res:parse()
end
luci.template.render("cbi/header")
require("luci.cbi")
require("luci.template")
- local stat, maps = luci.util.copcall(luci.cbi.load, model, ...)
- if not stat then
- error500(maps)
- return true
- end
+ maps = luci.cbi.load(model, ...)
for i, res in ipairs(maps) do
- local stat, err = luci.util.copcall(res.parse, res)
- if not stat then
- error500(err)
- return true
- end
+ res:parse()
end
luci.template.render("header")