Several escaping fixes

Updated XML translation system
Use the new Table widget for DHCP leases
This commit is contained in:
Steven Barth 2008-08-15 20:42:25 +00:00
parent 1d4196b3ff
commit 8e4afe1210
4 changed files with 20 additions and 29 deletions

View file

@ -8,16 +8,16 @@ all: build
build: luabuild gccbuild build: luabuild gccbuild
luabuild: lua$(LUA_TARGET) i18n luabuild: i18n lua$(LUA_TARGET)
gccbuild: compile gccbuild: compile
compile: compile:
clean: luaclean clean: luaclean
i18n: luasource i18n:
[ -n "$(XSLTPROC)" ] && for i in dist$(LUCI_MODULEDIR)/i18n/*.xml; do [ -f "$$i" ]\ [ -n "$(XSLTPROC)" ] && for i in luasrc/i18n/*.xml; do [ -f "$$i" ]\
&& { $(XSLTPROC) $(MAKEPATH)i18n-lua-xhtml1.xsl $$i > $${i/.xml/.lua}; rm $$i; }; done || true && $(XSLTPROC) $(MAKEPATH)i18n-lua-xhtml1.xsl $$i > $${i/.xml/.lua}; done || true
luasource: luasource:
mkdir -p dist$(LUA_MODULEDIR) mkdir -p dist$(LUA_MODULEDIR)
@ -28,6 +28,7 @@ luasource:
cp -a lua/* dist$(LUA_MODULEDIR) -R 2>/dev/null || true cp -a lua/* dist$(LUA_MODULEDIR) -R 2>/dev/null || true
cp -a htdocs/* dist$(HTDOCS) -R 2>/dev/null || true cp -a htdocs/* dist$(HTDOCS) -R 2>/dev/null || true
for i in $$(find dist -name .svn); do rm $$i -rf || true; done for i in $$(find dist -name .svn); do rm $$i -rf || true; done
for i in dist$(LUCI_MODULEDIR)/i18n/*.xml; do [ -f "$$i" ] && rm $$i; done || true
luastrip: luasource luastrip: luasource

View file

@ -92,10 +92,10 @@ function Node._i18n(self, config, section, option, title, description)
-- i18n loaded? -- i18n loaded?
if type(luci.i18n) == "table" then if type(luci.i18n) == "table" then
local key = config:gsub("[^%w]+", "") local key = config and config:gsub("[^%w]+", "") or ""
if section then key = key .. "_" .. section:lower():gsub("[^%w]+", "") end if section then key = key .. "_" .. section:lower():gsub("[^%w]+", "") end
if option then key = key .. "_" .. option:lower():gsub("[^%w]+", "") end if option then key = key .. "_" .. tostring(option):lower():gsub("[^%w]+", "") end
self.title = title or luci.i18n.translate( key, option or section or config ) self.title = title or luci.i18n.translate( key, option or section or config )
self.description = description or luci.i18n.translate( key .. "_desc", "" ) self.description = description or luci.i18n.translate( key .. "_desc", "" )
@ -483,13 +483,15 @@ Table = class(AbstractSection)
function Table.__init__(self, form, data, ...) function Table.__init__(self, form, data, ...)
local datasource = {} local datasource = {}
datasource.config = "table"
self.data = data self.data = data
function datasource.get(self, section, option) function datasource.get(self, section, option)
return data[option] return data[section][option]
end end
AbstractSection.__init__(self, datasource, nil, ...) AbstractSection.__init__(self, datasource, "table", ...)
self.template = "cbi/tblsection"
end end
function Table.cfgsections(self) function Table.cfgsections(self)

View file

@ -199,6 +199,8 @@ end
-- @param value String value containing the data to escape -- @param value String value containing the data to escape
-- @return String value containing the escaped data -- @return String value containing the escaped data
function pcdata(value) function pcdata(value)
if not value then return end
value = tostring(value)
value = value:gsub("&", "&") value = value:gsub("&", "&")
value = value:gsub('"', """) value = value:gsub('"', """)
value = value:gsub("'", "'") value = value:gsub("'", "'")

View file

@ -30,33 +30,19 @@ if leasefp then
end end
if leases then if leases then
v = m2:section(TypedSection, "_virtual", translate("dhcp_leases_active")) v = m2:section(Table, leases, translate("dhcp_leases_active"))
v.anonymous = true v.anonymous = true
v.rowcolors = true v.rowcolors = true
v.template = "cbi/tblsection"
function v.cfgsections(self) ip = v:option(DummyValue, 3, translate("ipaddress"))
local sections = {}
for i=1,#leases do
table.insert(sections, i)
end
return sections
end
ip = v:option(DummyValue, "ip", translate("ipaddress")) mac = v:option(DummyValue, 2, translate("macaddress"))
function ip.cfgvalue(self, section)
return leases[section][3]
end
mac = v:option(DummyValue, "mac", translate("macaddress")) ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
function mac.cfgvalue(self, section) function ltime.cfgvalue(self, ...)
return leases[section][2] local value = DummyValue.cfgvalue(self, ...)
end
ltime = v:option(DummyValue, "time", translate("dhcp_timeremain"))
function ltime.cfgvalue(self, section)
return luci.tools.webadmin.date_format( return luci.tools.webadmin.date_format(
os.difftime(tonumber(leases[section][1]), os.time()) os.difftime(tonumber(value), os.time())
) )
end end
end end