Explorar o código

gluon-config-mode-*, gluon-luci-portconfig: improve validation

Make bandwidth limits unsigned; trim numbers, the validator accepts
trailing whitespace.
Matthias Schiffer %!s(int64=8) %!d(string=hai) anos
pai
achega
6a6eb6282f

+ 3 - 3
package/gluon-config-mode-geo-location/files/lib/gluon/config-mode/wizard/0400-geo-location.lua

@@ -45,10 +45,10 @@ function M.handle(data)
 
   uci:set("gluon-node-info", sname, "share_location", data._location)
   if data._location and data._latitude ~= nil and data._longitude ~= nil then
-    uci:set("gluon-node-info", sname, "latitude", data._latitude)
-    uci:set("gluon-node-info", sname, "longitude", data._longitude)
+    uci:set("gluon-node-info", sname, "latitude", data._latitude:trim())
+    uci:set("gluon-node-info", sname, "longitude", data._longitude:trim())
     if data._altitude ~= nil then
-      uci:set("gluon-node-info", sname, "altitude", data._altitude)
+      uci:set("gluon-node-info", sname, "altitude", data._altitude:trim())
     else
       uci:delete("gluon-node-info", sname, "altitude")
     end

+ 4 - 4
package/gluon-config-mode-mesh-vpn/files/lib/gluon/config-mode/wizard/0300-mesh-vpn.lua

@@ -28,13 +28,13 @@ function M.section(form)
   o:depends("_limit_enabled", "1")
   o.value = uci:get("simple-tc", "mesh_vpn", "limit_ingress")
   o.rmempty = false
-  o.datatype = "integer"
+  o.datatype = "uinteger"
 
   o = s:option(cbi.Value, "_limit_egress", i18n.translate("Upstream (kbit/s)"))
   o:depends("_limit_enabled", "1")
   o.value = uci:get("simple-tc", "mesh_vpn", "limit_egress")
   o.rmempty = false
-  o.datatype = "integer"
+  o.datatype = "uinteger"
 end
 
 function M.handle(data)
@@ -49,11 +49,11 @@ function M.handle(data)
     uci:set("simple-tc", "mesh_vpn", "ifname", "mesh-vpn")
 
     if data._limit_ingress ~= nil then
-      uci:set("simple-tc", "mesh_vpn", "limit_ingress", data._limit_ingress)
+      uci:set("simple-tc", "mesh_vpn", "limit_ingress", data._limit_ingress:trim())
     end
 
     if data._limit_egress ~= nil then
-      uci:set("simple-tc", "mesh_vpn", "limit_egress", data._limit_egress)
+      uci:set("simple-tc", "mesh_vpn", "limit_egress", data._limit_egress:trim())
     end
 
     uci:commit("simple-tc")

+ 5 - 5
package/gluon-luci-portconfig/files/usr/lib/lua/luci/model/cbi/admin/portconfig.lua

@@ -99,9 +99,9 @@ function f.handle(self, state, data)
   if state == FORM_VALID then
     uci:set("network", "wan", "proto", data.ipv4)
     if data.ipv4 == "static" then
-      uci:set("network", "wan", "ipaddr", data.ipv4_addr)
-      uci:set("network", "wan", "netmask", data.ipv4_netmask)
-      uci:set("network", "wan", "gateway", data.ipv4_gateway)
+      uci:set("network", "wan", "ipaddr", data.ipv4_addr:trim())
+      uci:set("network", "wan", "netmask", data.ipv4_netmask:trim())
+      uci:set("network", "wan", "gateway", data.ipv4_gateway:trim())
     else
       uci:delete("network", "wan", "ipaddr")
       uci:delete("network", "wan", "netmask")
@@ -110,8 +110,8 @@ function f.handle(self, state, data)
 
     uci:set("network", "wan6", "proto", data.ipv6)
     if data.ipv6 == "static" then
-      uci:set("network", "wan6", "ip6addr", data.ipv6_addr)
-      uci:set("network", "wan6", "ip6gw", data.ipv6_gateway)
+      uci:set("network", "wan6", "ip6addr", data.ipv6_addr:trim())
+      uci:set("network", "wan6", "ip6gw", data.ipv6_gateway:trim())
     else
       uci:delete("network", "wan6", "ip6addr")
       uci:delete("network", "wan6", "ip6gw")