end
return s
+end
+
+function urldecode(str)
+ str = str:gsub("+", " ")
+ str = str:gsub("%%(%x%x)",
+ function(h) return string.char(tonumber(h,16)) end)
+ str = str:gsub("\r\n", "\n")
+ return str
+end
+
+function urlencode(str)
+ str = str:gsub("\n", "\r\n")
+ str = str:gsub("([^%w ])",
+ function (c) return string.format ("%%%02X", string.byte(c)) end)
+ str = str:gsub(" ", "+")
+ return str
end
\ No newline at end of file
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
-- 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))
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