summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/web/htdocs/luci-static/resources/cbi.js10
-rw-r--r--libs/web/luasrc/cbi/datatypes.lua16
2 files changed, 25 insertions, 1 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js
index ddafd79180..a8814d451f 100644
--- a/libs/web/htdocs/luci-static/resources/cbi.js
+++ b/libs/web/htdocs/luci-static/resources/cbi.js
@@ -42,6 +42,11 @@ var cbi_validators = {
return cbi_validators.ip4addr(v) || cbi_validators.ip6addr(v);
},
+ 'neg_ipaddr': function(v)
+ {
+ return cbi_validators.ip4addr(v.replace(/^\s*!/, "")) || cbi_validators.ip6addr(v.replace(/^\s*!/, ""));
+ },
+
'ip4addr': function(v)
{
if( v.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)(\/(\d+))?$/) )
@@ -57,6 +62,11 @@ var cbi_validators = {
return false;
},
+ 'neg_ip4addr': function(v)
+ {
+ return cbi_validators.ip4addr(v.replace(/^\s*!/, ""));
+ },
+
'ip6addr': function(v)
{
if( v.match(/^([a-fA-F0-9:.]+)(\/(\d+))?$/) )
diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua
index b543d9fe5e..d4603cf2a3 100644
--- a/libs/web/luasrc/cbi/datatypes.lua
+++ b/libs/web/luasrc/cbi/datatypes.lua
@@ -17,8 +17,8 @@ local fs = require "nixio.fs"
local ip = require "luci.ip"
local math = require "math"
local util = require "luci.util"
+local tonumber, type = tonumber, type
-local tonumber = tonumber
module "luci.cbi.datatypes"
@@ -66,6 +66,13 @@ function ipaddr(val)
return ip4addr(val) or ip6addr(val)
end
+function neg_ipaddr(v)
+ if type(v) == "string" then
+ v = v:gsub("^%s*!", "")
+ end
+ return v and ipaddr(v)
+end
+
function ip4addr(val)
if val then
return ip.IPv4(val) and true or false
@@ -74,6 +81,13 @@ function ip4addr(val)
return false
end
+function neg_ip4addr(v)
+ if type(v) == "string" then
+ v = v:gsub("^%s*!", "")
+ end
+ return v and ip4addr(v)
+end
+
function ip4prefix(val)
val = tonumber(val)
return ( val and val >= 0 and val <= 32 )