src_ip = s:taboption("advanced", Value, "src_ip", translate("Source IP address"))
src_ip.optional = true
-src_ip.datatype = "ip4addr"
+src_ip.datatype = "neg_ip4addr"
src_ip.placeholder = translate("any")
sport = s:taboption("advanced", Value, "src_port", translate("Source port"),
src_ip = s:taboption("general", Value, "src_ip", translate("Source address"))
src_ip.optional = true
-src_ip.datatype = has_v2 and "ipaddr" or "ip4addr"
+src_ip.datatype = has_v2 and "neg_ipaddr" or "neg_ip4addr"
src_ip.placeholder = translate("any")
sport = s:taboption("general", Value, "src_port", translate("Source port"))
dest_ip = s:taboption("general", Value, "dest_ip", translate("Destination address"))
dest_ip.optional = true
-dest_ip.datatype = has_v2 and "ipaddr" or "ip4addr"
+dest_ip.datatype = has_v2 and "neg_ipaddr" or "neg_ip4addr"
dest_ip.placeholder = translate("any")
dport = s:taboption("general", Value, "dest_port", translate("Destination port"))
translate("Restrict Masquerading to given source subnets"))
msrc.optional = true
-msrc.datatype = "ip4addr"
+msrc.datatype = "neg_ip4addr"
msrc.placeholder = "0.0.0.0/0"
msrc:depends("family", "")
msrc:depends("family", "ipv4")
translate("Restrict Masquerading to given destination subnets"))
mdest.optional = true
-mdest.datatype = "ip4addr"
+mdest.datatype = "neg_ip4addr"
mdest.placeholder = "0.0.0.0/0"
mdest:depends("family", "")
mdest:depends("family", "ipv4")
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+))?$/) )
return false;
},
+ 'neg_ip4addr': function(v)
+ {
+ return cbi_validators.ip4addr(v.replace(/^\s*!/, ""));
+ },
+
'ip6addr': function(v)
{
if( v.match(/^([a-fA-F0-9:.]+)(\/(\d+))?$/) )
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"
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
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 )