From 137db1c4d1bac4000f9c17150ac286b73787ce20 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 11 Apr 2020 18:19:59 +0200 Subject: [PATCH] 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 --- .../resources/view/network/dhcp.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js index 525526d62..6551b7273 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js @@ -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])) - return _('Expecting: %s').format(_('valid IPv4 address')); - else if (validation.parseIPv6(m[1]) && 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)) + + 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])) { + if (m[3] != null && !validation.parseIPv6(m[3])) + return _('Expecting: %s').format(_('valid IPv6 address')); + } + 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; -- 2.25.1