summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/template.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-06-07 06:44:27 +0000
committerSteven Barth <steven@midlink.org>2008-06-07 06:44:27 +0000
commitf8925eefa3b487c4573da63f99f6f19292ae4297 (patch)
tree0911cb7c0c7d5cad806b0a3670ee2602b68e39ae /libs/web/luasrc/template.lua
parentcdd871d8347b82b4fbbcf95f8b79641e5d18d660 (diff)
* libs/web: Fixed Luci template cache
* libs/web: Added luci.http.urlencode, luci.http.urldecode * Minor enhancements
Diffstat (limited to 'libs/web/luasrc/template.lua')
-rw-r--r--libs/web/luasrc/template.lua14
1 files changed, 8 insertions, 6 deletions
diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua
index c672f16bf..ce54d17f3 100644
--- a/libs/web/luasrc/template.lua
+++ b/libs/web/luasrc/template.lua
@@ -35,6 +35,9 @@ luci.config.template = luci.config.template or {}
viewdir = luci.config.template.viewdir or luci.sys.libpath() .. "/view"
compiledir = luci.config.template.compiledir or luci.sys.libpath() .. "/view"
+-- Enforce cache security
+compiledir = compiledir .. "/" .. luci.sys.process.info("uid")
+
-- Compile modes:
-- none: Never compile, only use precompiled data from files
@@ -147,12 +150,16 @@ function Template.__init__(self, name)
-- Compile and build
local sourcefile = viewdir .. "/" .. name .. ".htm"
- local compiledfile = compiledir .. "/" .. name .. ".lua"
+ local compiledfile = compiledir .. "/" .. luci.http.urlencode(name) .. ".lua"
local err
if compiler_mode == "file" then
local tplmt = luci.fs.mtime(sourcefile)
local commt = luci.fs.mtime(compiledfile)
+
+ if not luci.fs.mtime(compiledir) then
+ luci.fs.mkdir(compiledir, true)
+ end
-- Build if there is no compiled file or if compiled file is outdated
if ((commt == nil) and not (tplmt == nil))
@@ -163,11 +170,6 @@ function Template.__init__(self, name)
if source then
local compiled, err = compile(source)
- local compiledfile_dir = luci.fs.dirname(compiledfile)
- if not luci.fs.mtime(compiledfile_dir) then
- luci.fs.mkdir(compiledfile_dir)
- end
-
luci.fs.writefile(compiledfile, luci.util.dump(compiled))
self.template = compiled
end