luci-mod-network: dhcp.js: fix validation logic

The `server` option allows plain IPs besides the `/domain/addr` format.

Fixes: #3870
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2020-04-11 18:19:59 +02:00
parent f2749c7314
commit 137db1c4d1

View file

@ -99,7 +99,7 @@ function validateServerSpec(sid, s) {
if (s == null || s == '')
return true;
var m = s.match(/^\/(.+)\/(.*)$/);
var m = s.match(/^(?:\/(.+)\/)?(.*)$/);
if (!m)
return _('Expecting: %s').format(_('valid hostname'));
@ -116,11 +116,20 @@ function validateServerSpec(sid, s) {
if (!m)
return _('Expecting: %s').format(_('valid IP address'));
else if (validation.parseIPv4(m[1]) && m[3] != null && !validation.parseIPv4(m[3]))
if (validation.parseIPv4(m[1])) {
if (m[3] != null && !validation.parseIPv4(m[3]))
return _('Expecting: %s').format(_('valid IPv4 address'));
else if (validation.parseIPv6(m[1]) && m[3] != null && !validation.parseIPv6(m[3]))
}
else if (validation.parseIPv6(m[1])) {
if (m[3] != null && !validation.parseIPv6(m[3]))
return _('Expecting: %s').format(_('valid IPv6 address'));
else if ((m[2] != null && +m[2] > 65535) || (m[4] != null && +m[4] > 65535))
}
else {
return _('Expecting: %s').format(_('valid IP address'));
}
if ((m[2] != null && +m[2] > 65535) || (m[4] != null && +m[4] > 65535))
return _('Expecting: %s').format(_('valid port value'));
return true;