luci-proto-wireguard: add warning that allowed_ips must not be empty
authorFlorian Eckert <fe@dev.tdt.de>
Thu, 16 Apr 2020 14:51:41 +0000 (16:51 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Wed, 13 May 2020 13:34:27 +0000 (15:34 +0200)
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js

index 46cf5379893fe08e4d06d8ef7cfdaa716aa7f190..49f61c782a1459a2127f16202b0e905ee7eeb233 100644 (file)
@@ -124,7 +124,14 @@ return network.registerProtocol('wireguard', {
 
                o = ss.option(form.DynamicList, 'allowed_ips', _('Allowed IPs'), _("Required. IP addresses and prefixes that this peer is allowed to use inside the tunnel. Usually the peer's tunnel IP addresses and the networks the peer routes through the tunnel."));
                o.datatype = 'ipaddr';
-               o.rmempty = false;
+               o.validate = function(section, value) {
+                       var opt = this.map.lookupOption('allowed_ips', section);
+                       var ips = opt[0].formvalue(section);
+                       if (ips.length == 0) {
+                               return _('Value must not be empty');
+                       }
+                       return true;
+               };
 
                o = ss.option(form.Flag, 'route_allowed_ips', _('Route Allowed IPs'), _('Optional. Create routes for Allowed IPs for this peer.'));