X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=protocols%2Fluci-proto-wireguard%2Fhtdocs%2Fluci-static%2Fresources%2Fprotocol%2Fwireguard.js;h=e88c07c339ba532f4f319e600fbc9f31d92def6a;hb=5f54ad1b9c156a89f5c05a09106a784745da9943;hp=6742f2ab9964f7ed2f0cc863f93d603b1a193f9c;hpb=4eeded7051435eaabd22f0e9c2b9a13d700db2bd;p=oweals%2Fluci.git diff --git a/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js b/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js index 6742f2ab9..e88c07c33 100644 --- a/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js +++ b/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js @@ -1,9 +1,16 @@ 'use strict'; +'require uci'; 'require form'; 'require network'; function validateBase64(section_id, value) { - if (value.length != 44 || !value.match(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)) + if (value.length == 0) + return true; + + if (value.length != 44 || !value.match(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)) + return _('Invalid Base64 key string'); + + if (value[43] != "=" ) return _('Invalid Base64 key string'); return true; @@ -57,6 +64,8 @@ return network.registerProtocol('wireguard', { o.datatype = 'ipaddr'; o.optional = true; + o = s.taboption('general', form.Flag, 'nohostroute', _('No Host Routes'), _('Optional. Do not create host routes to peers.')); + o.optional = true; // -- advanced -------------------------------------------------------------------- @@ -118,7 +127,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.')); @@ -133,5 +149,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']); + }); } });