Several escaping fixes
authorSteven Barth <steven@midlink.org>
Fri, 15 Aug 2008 20:42:25 +0000 (20:42 +0000)
committerSteven Barth <steven@midlink.org>
Fri, 15 Aug 2008 20:42:25 +0000 (20:42 +0000)
Updated XML translation system
Use the new Table widget for DHCP leases

build/module.mk
libs/cbi/luasrc/cbi.lua
libs/core/luasrc/util.lua
modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua

index 3a94754..f540378 100644 (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
 compile:
 
 clean: luaclean
 
 
 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)
 
 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
        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
 
 
 luastrip: luasource
index 7bcfceb..ab342fe 100644 (file)
@@ -92,10 +92,10 @@ function Node._i18n(self, config, section, option, title, description)
        -- i18n loaded?
        if type(luci.i18n) == "table" then
 
        -- 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 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", "" )
 
                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 = {}
 
 function Table.__init__(self, form, data, ...)
        local datasource = {}
+       datasource.config = "table"
        self.data = data
        
        function datasource.get(self, section, option)
        self.data = data
        
        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
 
 function Table.cfgsections(self)
 end
 
 function Table.cfgsections(self)
index 51d66e0..ef1b8fe 100644 (file)
@@ -199,6 +199,8 @@ end
 -- @param value        String value containing the data to escape
 -- @return             String value containing the escaped data
 function pcdata(value)
 -- @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("&", "&amp;")
        value = value:gsub('"', "&quot;")
        value = value:gsub("'", "&apos;")
        value = value:gsub("&", "&amp;")
        value = value:gsub('"', "&quot;")
        value = value:gsub("'", "&apos;")
index 8ff1f52..25187ae 100644 (file)
@@ -30,33 +30,19 @@ if leasefp then
 end
 
 if leases 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.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(
                return luci.tools.webadmin.date_format(
-                os.difftime(tonumber(leases[section][1]), os.time())
+                os.difftime(tonumber(value), os.time())
                )
        end
 end
                )
        end
 end