From: Steven Barth Date: Fri, 15 Aug 2008 20:42:25 +0000 (+0000) Subject: Several escaping fixes X-Git-Tag: 0.8.0~408 X-Git-Url: http://git.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=8e4afe121087c05833ee7d567fe45f2ba270e54d Several escaping fixes Updated XML translation system Use the new Table widget for DHCP leases --- diff --git a/build/module.mk b/build/module.mk index 3a947546b0..f54037850f 100644 --- a/build/module.mk +++ b/build/module.mk @@ -8,16 +8,16 @@ all: build build: luabuild gccbuild -luabuild: lua$(LUA_TARGET) i18n +luabuild: i18n lua$(LUA_TARGET) gccbuild: compile compile: clean: luaclean -i18n: luasource - [ -n "$(XSLTPROC)" ] && for i in dist$(LUCI_MODULEDIR)/i18n/*.xml; do [ -f "$$i" ]\ - && { $(XSLTPROC) $(MAKEPATH)i18n-lua-xhtml1.xsl $$i > $${i/.xml/.lua}; rm $$i; }; done || true +i18n: + [ -n "$(XSLTPROC)" ] && for i in luasrc/i18n/*.xml; do [ -f "$$i" ]\ + && $(XSLTPROC) $(MAKEPATH)i18n-lua-xhtml1.xsl $$i > $${i/.xml/.lua}; done || true luasource: mkdir -p dist$(LUA_MODULEDIR) @@ -28,6 +28,7 @@ luasource: cp -a lua/* dist$(LUA_MODULEDIR) -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 dist$(LUCI_MODULEDIR)/i18n/*.xml; do [ -f "$$i" ] && rm $$i; done || true luastrip: luasource diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 7bcfceb2ef..ab342feec1 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -92,10 +92,10 @@ function Node._i18n(self, config, section, option, title, description) -- i18n loaded? 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 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.description = description or luci.i18n.translate( key .. "_desc", "" ) @@ -483,13 +483,15 @@ Table = class(AbstractSection) function Table.__init__(self, form, data, ...) local datasource = {} + datasource.config = "table" self.data = data function datasource.get(self, section, option) - return data[option] + return data[section][option] end - AbstractSection.__init__(self, datasource, nil, ...) + AbstractSection.__init__(self, datasource, "table", ...) + self.template = "cbi/tblsection" end function Table.cfgsections(self) diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 51d66e08e5..ef1b8fe279 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -199,6 +199,8 @@ end -- @param value String value containing the data to escape -- @return String value containing the escaped data function pcdata(value) + if not value then return end + value = tostring(value) value = value:gsub("&", "&") value = value:gsub('"', """) value = value:gsub("'", "'") diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua b/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua index 8ff1f5293b..25187ae90f 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua @@ -30,33 +30,19 @@ if leasefp then end 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.rowcolors = true - v.template = "cbi/tblsection" - function v.cfgsections(self) - local sections = {} - for i=1,#leases do - table.insert(sections, i) - end - return sections - end - - ip = v:option(DummyValue, "ip", translate("ipaddress")) - function ip.cfgvalue(self, section) - return leases[section][3] - end + ip = v:option(DummyValue, 3, translate("ipaddress")) - mac = v:option(DummyValue, "mac", translate("macaddress")) - function mac.cfgvalue(self, section) - return leases[section][2] - end + mac = v:option(DummyValue, 2, translate("macaddress")) - ltime = v:option(DummyValue, "time", translate("dhcp_timeremain")) - function ltime.cfgvalue(self, section) + ltime = v:option(DummyValue, 1, translate("dhcp_timeremain")) + function ltime.cfgvalue(self, ...) + local value = DummyValue.cfgvalue(self, ...) return luci.tools.webadmin.date_format( - os.difftime(tonumber(leases[section][1]), os.time()) + os.difftime(tonumber(value), os.time()) ) end end