diff options
author | Manuel Munz <freifunk@somakoma.de> | 2011-04-13 00:33:42 +0000 |
---|---|---|
committer | Manuel Munz <freifunk@somakoma.de> | 2011-04-13 00:33:42 +0000 |
commit | bb2d7517eb3d2229331e11aab5c6c900259e0742 (patch) | |
tree | 72625b858eb52433a3b87000b895ef872510dbe1 /libs/web/luasrc/cbi | |
parent | 5a1e9354b41155b9604362c9a1ef8d7a899ba2b2 (diff) |
luci-firewall: Add support for negations for ip addresses/nets (#218)
Diffstat (limited to 'libs/web/luasrc/cbi')
-rw-r--r-- | libs/web/luasrc/cbi/datatypes.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index b543d9fe5..d4603cf2a 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 ) |