luci-base: add hostport and ipaddrport validation types
Add two new types 'hostport' and 'ipaddrport' to validate strings in the form 'sub.example.org:1234' and '0.0.0.0:80'. The 'hostport' accepts hostnames or IP addresses followed by a colon and a port number while the 'ipaddrport' type accepts numeric IP addresses only, followed by a colon and a port. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
ea9f25b63e
commit
9b30357454
2 changed files with 32 additions and 0 deletions
|
@ -161,6 +161,28 @@ var cbi_validators = {
|
||||||
cbi_validators.host.apply(this);
|
cbi_validators.host.apply(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'hostport': function()
|
||||||
|
{
|
||||||
|
var hp = this.split(/:/);
|
||||||
|
|
||||||
|
if (hp.length == 2)
|
||||||
|
return (cbi_validators.host.apply(hp[0]) &&
|
||||||
|
cbi_validators.port.apply(hp[1]));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
'ipaddrport': function()
|
||||||
|
{
|
||||||
|
var hp = this.split(/:/);
|
||||||
|
|
||||||
|
if (hp.length == 2)
|
||||||
|
return (cbi_validators.ipaddr.apply(hp[0]) &&
|
||||||
|
cbi_validators.port.apply(hp[1]));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
'wpakey': function()
|
'wpakey': function()
|
||||||
{
|
{
|
||||||
var v = this;
|
var v = this;
|
||||||
|
|
|
@ -184,6 +184,16 @@ function network(val)
|
||||||
return uciname(val) or host(val)
|
return uciname(val) or host(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function hostport(val)
|
||||||
|
local h, p = val:match("^([^:]+):([^:]+)$")
|
||||||
|
return not not (h and p and host(h) and port(p))
|
||||||
|
end
|
||||||
|
|
||||||
|
function ipaddrport(val)
|
||||||
|
local h, p = val:match("^([^:]+):([^:]+)$")
|
||||||
|
return not not (h and p and ipaddr(h) and port(p))
|
||||||
|
end
|
||||||
|
|
||||||
function wpakey(val)
|
function wpakey(val)
|
||||||
if #val == 64 then
|
if #val == 64 then
|
||||||
return (val:match("^[a-fA-F0-9]+$") ~= nil)
|
return (val:match("^[a-fA-F0-9]+$") ~= nil)
|
||||||
|
|
Loading…
Reference in a new issue