diff options
author | Daniel Dickinson <openwrt@daniel.thecshore.com> | 2015-12-14 22:51:29 -0500 |
---|---|---|
committer | Daniel Dickinson <openwrt@daniel.thecshore.com> | 2015-12-15 13:12:10 -0500 |
commit | 0ec3f91a0c7a8c71980f5e70f3322397e496a8d6 (patch) | |
tree | 670952c9572eb3f474a584acc7d66914bb5be97c /modules/luci-base/luasrc | |
parent | 38880407aa6c0246bc9af52073a79ff4a2096a6e (diff) |
validation: Add option ipv4only option to host and hostport datatypes
Some applications only support ipv4 so add ipv4only option
to host and hostport datatypes so that for thos applications
that when an IP address is specified only and ipv4 ip address
gets accepted.
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r-- | modules/luci-base/luasrc/cbi/datatypes.lua | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua index aafdc5c3c..d415c6f58 100644 --- a/modules/luci-base/luasrc/cbi/datatypes.lua +++ b/modules/luci-base/luasrc/cbi/datatypes.lua @@ -176,17 +176,22 @@ function hostname(val) return false end -function host(val) - return hostname(val) or ipaddr(val) +function host(val, ipv4only) + return hostname(val) or ((ipv4only == 1) and ip4addr(val)) or ((not (ipv4only == 1)) and ipaddr(val)) end function network(val) return uciname(val) or host(val) end -function hostport(val) +function hostport(val, ipv4only) local h, p = val:match("^([^:]+):([^:]+)$") - return not not (h and p and host(h) and port(p)) + return not not (h and p and host(h, ipv4only) and port(p)) +end + +function ip4addrport(val, bracket) + local h, p = val:match("^([^:]+):([^:]+)$") + return (h and p and ip4addr(h) and port(p)) end function ip4addrport(val) @@ -199,7 +204,7 @@ function ipaddrport(val, bracket) if (h and p and ip4addr(h) and port(p)) then return true elseif (bracket == 1) then - h, p = val:match("^(%[.+%]):([^:]+)$") + h, p = val:match("^%[(.+)%]:([^:]+)$") if (h and p and ip6addr(h) and port(p)) then return true end |