diff options
author | Daniel Dickinson <openwrt@daniel.thecshore.com> | 2015-12-14 07:38:31 -0500 |
---|---|---|
committer | Daniel Dickinson <openwrt@daniel.thecshore.com> | 2015-12-15 20:40:14 -0500 |
commit | bbcfad7953489ed87336e3a1981c9cb19e390cdb (patch) | |
tree | 9a319b276e604b17316d449de10046a2aa8b261a /modules/luci-base/htdocs/luci-static | |
parent | f25c4e07bc9642e0491d3a4ab3942a69545891e9 (diff) |
modules/luci-base: Fix ipaddrport validator to support ipv6
The previous versiono of ipaddrport validator only worked for ipv4
due to disallowing colons (:) in ip address which obvious fails for
ipv6. We now instead allow either ipv4 address or an ipv6 address of
the form [<ipv6address>]:port
Diffstat (limited to 'modules/luci-base/htdocs/luci-static')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/cbi.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 4b7227f1a4..19a1edec4c 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -172,17 +172,38 @@ var cbi_validators = { return false; }, - 'ipaddrport': function() + 'ip4addrport': function() { var hp = this.split(/:/); if (hp.length == 2) return (cbi_validators.ipaddr.apply(hp[0]) && cbi_validators.port.apply(hp[1])); - return false; }, + 'ipaddrport': function(bracket) + { + if (this.match(/^([^\[\]:]+):([^:]+)$/)) { + var addr = RegExp.$1 + var port = RegExp.$2 + return (cbi_validators.ip4addr.apply(addr) && + cbi_validators.port.apply(port)); + } else if ((bracket == 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) { + var addr = RegExp.$1 + var port = RegExp.$2 + return (cbi_validators.ip6addr.apply(addr) && + cbi_validators.port.apply(port)); + } else if ((bracket != 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) { + var addr = RegExp.$1 + var port = RegExp.$2 + return (cbi_validators.ip6addr.apply(addr) && + cbi_validators.port.apply(port)); + } else { + return false; + } + }, + 'wpakey': function() { var v = this; |