applications/splash: Fix error when replacing markers, delete file which contains the custom text if it is empty, #477

This commit is contained in:
Manuel Munz 2012-09-02 19:34:32 +00:00
parent 81b554b7a0
commit 4f126632a5
2 changed files with 6 additions and 6 deletions

View file

@ -33,6 +33,8 @@ function f.handle(self, state, data)
if state == FORM_VALID then if state == FORM_VALID then
if data.text then if data.text then
fs.writefile(splashtextfile, data.text:gsub("\r\n", "\n")) fs.writefile(splashtextfile, data.text:gsub("\r\n", "\n"))
else
fs.unlink(splashtextfile)
end end
end end
return true return true

View file

@ -14,11 +14,11 @@ You may obtain a copy of the License at
local fs = require "luci.fs" local fs = require "luci.fs"
local has_custom_splash = fs.access("/usr/lib/luci-splash/splashtext.html") local has_custom_splash = fs.access("/usr/lib/luci-splash/splashtext.html")
function expand (e) function expand (e, R)
return (string.gsub(e, "###([A-Z_]+)###", R)) return (string.gsub(e, "###([A-Z_]+)###", R))
end end
local community, homepage, leasetime, limit_up, limit_down, R local community, homepage, leasetime, limit_up, limit_down
local contacturl = luci.dispatcher.build_url("freifunk", "contact") local contacturl = luci.dispatcher.build_url("freifunk", "contact")
@ -50,8 +50,7 @@ if limit_up and limit_down then
end end
if has_custom_splash then if has_custom_splash then
local R = {
R = {
COMMUNITY = community, COMMUNITY = community,
COMMUNITY_URL = homepage, COMMUNITY_URL = homepage,
LEASETIME = leasetime, LEASETIME = leasetime,
@ -59,8 +58,7 @@ if has_custom_splash then
LIMIT = limit_text, LIMIT = limit_text,
CONTACTURL = contacturl CONTACTURL = contacturl
} }
local splashtext = expand(fs.readfile("/usr/lib/luci-splash/splashtext.html"), R)
local splashtext = expand(fs.readfile("/usr/lib/luci-splash/splashtext.html"))
%> %>
<%=splashtext%> <%=splashtext%>