luci-proto-wireguard: add warning that allowed_ips must not be empty
[oweals/luci.git] / protocols / luci-proto-wireguard / htdocs / luci-static / resources / protocol / wireguard.js
index c8e1f8403e3d283e40a86443b32e958b6045e504..49f61c782a1459a2127f16202b0e905ee7eeb233 100644 (file)
@@ -1,4 +1,5 @@
 'use strict';
+'require uci';
 'require form';
 'require network';
 
@@ -123,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.'));
 
@@ -138,5 +146,11 @@ return network.registerProtocol('wireguard', {
                o = ss.option(form.Value, 'persistent_keepalive', _('Persistent Keep Alive'), _('Optional. Seconds between keep alive messages. Default is 0 (disabled). Recommended value if this device is behind a NAT is 25.'));
                o.datatype = 'range(0,65535)';
                o.placeholder = '0';
+       },
+
+       deleteConfiguration: function() {
+               uci.sections('network', 'wireguard_%s'.format(this.sid), function(s) {
+                       uci.remove('network', s['.name']);
+               });
        }
 });