summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--libs/web/htdocs/luci-static/resources/cbi.js32
-rw-r--r--libs/web/luasrc/cbi/datatypes.lua29
2 files changed, 60 insertions, 1 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js
index a8814d451f..1cd49bc65d 100644
--- a/libs/web/htdocs/luci-static/resources/cbi.js
+++ b/libs/web/htdocs/luci-static/resources/cbi.js
@@ -2,7 +2,7 @@
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
- Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
+ Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -153,6 +153,8 @@ var cbi_validators = {
'hostname': function(v)
{ if ( v.length <= 253 )
return (v.match(/^[a-zA-Z0-9][a-zA-Z0-9\-.]*[a-zA-Z0-9]$/) != null);
+
+ return false;
},
'wpakey': function(v)
@@ -179,6 +181,12 @@ var cbi_validators = {
return (v.match(/^[a-zA-Z0-9_]+$/) != null);
},
+ 'neg_network_ip4addr': function(v)
+ {
+ v = v.replace(/^\s*!/, "");
+ return cbi_validators.uciname(v) || cbi_validators.ip4addr(v);
+ },
+
'range': function(v, args)
{
var min = parseInt(args[0]);
@@ -189,6 +197,28 @@ var cbi_validators = {
return ((val >= min) && (val <= max));
return false;
+ },
+
+ 'min': function(v, args)
+ {
+ var min = parseInt(args[0]);
+ var val = parseInt(v);
+
+ if (!isNaN(min) && !isNaN(val))
+ return (val >= min);
+
+ return false;
+ },
+
+ 'max': function(v, args)
+ {
+ var max = parseInt(args[0]);
+ var val = parseInt(v);
+
+ if (!isNaN(max) && !isNaN(val))
+ return (val <= max);
+
+ return false;
}
};
diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua
index d4603cf2a3..6640db6392 100644
--- a/libs/web/luasrc/cbi/datatypes.lua
+++ b/libs/web/luasrc/cbi/datatypes.lua
@@ -227,6 +227,13 @@ function uciname(val)
return (val:match("^[a-zA-Z0-9_]+$") ~= nil)
end
+function neg_network_ip4addr(val)
+ if type(v) == "string" then
+ v = v:gsub("^%s*!", "")
+ return (uciname(v) or ip4addr(v))
+ end
+end
+
function range(val, min, max)
val = tonumber(val)
min = tonumber(min)
@@ -238,3 +245,25 @@ function range(val, min, max)
return false
end
+
+function min(val, min)
+ val = tonumber(val)
+ min = tonumber(min)
+
+ if val ~= nil and min ~= nil then
+ return (val >= min)
+ end
+
+ return false
+end
+
+function max(val, max)
+ val = tonumber(val)
+ max = tonumber(max)
+
+ if val ~= nil and max ~= nil then
+ return (val <= max)
+ end
+
+ return false
+end