X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=libs%2Fweb%2Fluasrc%2Ftemplate.lua;h=83efd220092309d6b75c937d4638db7725240db5;hb=30b216f774c2404a965807ddb93a4a4b2aaeac04;hp=4aa9b0933ab6f41bc130c9063a5caa6ccb42c971;hpb=37b5ef40df48bb7d4023e66f09a68c1c0e229b8d;p=project%2Fluci.git diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua index 4aa9b0933a..83efd22009 100644 --- a/libs/web/luasrc/template.lua +++ b/libs/web/luasrc/template.lua @@ -31,6 +31,7 @@ local table = require "table" local string = require "string" local config = require "luci.config" local coroutine = require "coroutine" +local nixio = require "nixio", require "nixio.util" local tostring, pairs, loadstring = tostring, pairs, loadstring local setmetatable, loadfile = setmetatable, loadfile @@ -63,7 +64,7 @@ function compile(template) -- Search all <% %> expressions local function expr_add(ws1, skip1, command, skip2, ws2) - table.insert(expr, command) + expr[#expr+1] = command return ( #skip1 > 0 and "" or ws1 ) .. "<%" .. tostring(#expr) .. "%>" .. ( #skip2 > 0 and "" or ws2 ) @@ -177,7 +178,7 @@ function Template.__init__(self, name) if not fs.mtime(cdir) then fs.mkdir(cdir, true) - fs.chmod(fs.dirname(cdir), "a+rxw") + fs.chmod(fs.dirname(cdir), 777) end assert(tplmt or commt, "No such template: " .. name) @@ -190,14 +191,15 @@ function Template.__init__(self, name) if source then local compiled, err = compile(source) - fs.writefile(compiledfile, util.get_bytecode(compiled)) - fs.chmod(compiledfile, "a-rwx,u+rw") + local f = nixio.open(compiledfile, "w", 600) + f:writeall(util.get_bytecode(compiled)) + f:close() self.template = compiled end else assert( sys.process.info("uid") == fs.stat(compiledfile, "uid") - and fs.stat(compiledfile, "mode") == "rw-------", + and fs.stat(compiledfile, "modestr") == "rw-------", "Fatal: Cachefile is not sane!" ) self.template, err = loadfile(compiledfile)