summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-04-11 18:19:59 +0200
committerJo-Philipp Wich <jo@mein.io>2020-04-11 18:27:36 +0200
commit137db1c4d1bac4000f9c17150ac286b73787ce20 (patch)
tree5f089920886f0c1b527501fd913b05b4895c4144 /modules
parentf2749c7314eb5129bba3ef6d5e0947b33dc2101c (diff)
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>
Diffstat (limited to 'modules')
-rw-r--r--modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js21
1 files 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;