diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-08-20 15:31:35 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-09-10 15:28:16 +0200 |
commit | 6a2a53a82918ea2ccbbbe23510aa0279827b2783 (patch) | |
tree | 7f065f96cc0f255ced7256c1d9092f0e1433fda0 /protocols/luci-proto-ipv6/htdocs/luci-static | |
parent | 0674fc20414e575c346ceb2066ff3af7e8601a48 (diff) |
protocols: add client side protocol handler implementations
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'protocols/luci-proto-ipv6/htdocs/luci-static')
7 files changed, 540 insertions, 0 deletions
diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/464xlat.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/464xlat.js new file mode 100644 index 0000000000..a74708fd01 --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/464xlat.js @@ -0,0 +1,60 @@ +'use strict'; +'require form'; +'require network'; +'require tools.widgets as widgets'; + +network.registerPatternVirtual(/^464-.+$/); +network.registerErrorCode('CLAT_CONFIG_FAILED', _('CLAT configuration failed')); + +return network.registerProtocol('464xlat', { + getI18n: function() { + return _('464XLAT (CLAT)'); + }, + + getIfname: function() { + return this._ubus('l3_device') || '464-%s'.format(this.sid); + }, + + getOpkgPackage: function() { + return '464xlat'; + }, + + isFloating: function() { + return true; + }, + + isVirtual: function() { + return true; + }, + + getDevices: function() { + return null; + }, + + containsDevice: function(ifname) { + return (network.getIfnameOf(ifname) == this.getIfname()); + }, + + renderFormOptions: function(s) { + var o; + + o = s.taboption('general', form.Value, 'ip6prefix', _('NAT64 Prefix'), _('Leave empty to autodetect')); + o.datatype = 'cidr6'; + + o = s.taboption('advanced', widgets.NetworkSelect, 'tunlink', _('Tunnel Link')); + o.nocreate = true; + o.exclude = s.section; + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric')); + o.placeholder = '0'; + o.datatype = 'uinteger'; + o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface')); + o.placeholder = '1280'; + o.datatype = 'max(9200)'; + } +}); diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6in4.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6in4.js new file mode 100644 index 0000000000..536dd5222b --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6in4.js @@ -0,0 +1,101 @@ +'use strict'; +'require uci'; +'require form'; +'require network'; + +network.registerPatternVirtual(/^6in4-.+$/); + +return network.registerProtocol('6in4', { + getI18n: function() { + return _('IPv6-in-IPv4 (RFC4213)'); + }, + + getIfname: function() { + return this._ubus('l3_device') || '6in4-%s'.format(this.sid); + }, + + getOpkgPackage: function() { + return '6in4'; + }, + + isFloating: function() { + return true; + }, + + isVirtual: function() { + return true; + }, + + getDevices: function() { + return null; + }, + + containsDevice: function(ifname) { + return (network.getIfnameOf(ifname) == this.getIfname()); + }, + + renderFormOptions: function(s) { + var o; + + o = s.taboption('general', form.Value, 'ipaddr', _('Local IPv4 address'), _('Leave empty to use the current WAN address')); + o.datatype = 'ip4addr("nomask")'; + o.load = function(section_id) { + return network.getWANNetworks().then(L.bind(function(nets) { + if (nets.length) + this.placeholder = nets[0].getIPAddr(); + return form.Value.prototype.load.apply(this, [section_id]); + }, this)); + }; + + o = s.taboption('general', form.Value, 'peeraddr', _('Remote IPv4 address'), _('This is usually the address of the nearest PoP operated by the tunnel broker')); + o.rmempty = false; + o.datatype = 'ip4addr("nomask")'; + + o = s.taboption('general', form.Value, 'ip6addr', _('Local IPv6 address'), _('This is the local endpoint address assigned by the tunnel broker, it usually ends with <code>...:2/64</code>')); + o.datatype = 'cidr6'; + + o = s.taboption('general', form.DynamicList, 'ip6prefix', _('IPv6 routed prefix'), _('This is the prefix routed to you by the tunnel broker for use by clients')); + o.datatype = 'cidr6'; + + o = s.taboption('general', form.Flag, '_update', _('Dynamic tunnel'), _('Enable HE.net dynamic endpoint update')); + o.enabled = '1'; + o.disabled = '0'; + o.write = function() {}; + o.remove = function() {}; + o.cfgvalue = function(section_id) { + return !isNaN(+uci.get('network', section_id, 'tunnelid')) ? this.enabled : this.disabled; + }; + + o = s.taboption('general', form.Value, 'tunnelid', _('Tunnel ID')); + o.datatype = 'uinteger'; + o.depends('_update', '1'); + + o = s.taboption('general', form.Value, 'username', _('HE.net username'), _('This is the plain username for logging into the account')); + o.depends('_update', '1'); + o.validate = function(section_id, value) { + if (/^[a-fA-F0-9]{32}$/.test(value)) + return _('The HE.net endpoint update configuration changed, you must now use the plain username instead of the user ID!'); + return true; + }; + + o = s.taboption('general', form.Value, 'password', _('HE.net password'), _('This is either the \'Update Key\' configured for the tunnel or the account password if no update key has been configured')); + o.password = true; + o.depends('_update', '1'); + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric')); + o.placeholder = '0'; + o.datatype = 'uinteger'; + o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.Value, 'ttl', _('Use TTL on tunnel interface')); + o.placeholder = '64'; + o.datatype = 'range(1,255)'; + + o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface')); + o.placeholder = '1280'; + o.datatype = 'max(9200)'; + } +}); diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6rd.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6rd.js new file mode 100644 index 0000000000..6a8f506bc9 --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6rd.js @@ -0,0 +1,81 @@ +'use strict'; +'require form'; +'require network'; + +network.registerPatternVirtual(/^6rd-.+$/); + +return network.registerProtocol('6rd', { + getI18n: function() { + return _('IPv6-over-IPv4 (6rd)'); + }, + + getIfname: function() { + return this._ubus('l3_device') || '6rd-%s'.format(this.sid); + }, + + getOpkgPackage: function() { + return '6rd'; + }, + + isFloating: function() { + return true; + }, + + isVirtual: function() { + return true; + }, + + getDevices: function() { + return null; + }, + + containsDevice: function(ifname) { + return (network.getIfnameOf(ifname) == this.getIfname()); + }, + + renderFormOptions: function(s) { + var o; + + o = s.taboption('general', form.Value, 'ipaddr', _('Local IPv4 address'), _('Leave empty to use the current WAN address')); + o.datatype = 'ip4addr("nomask")'; + o.load = function(section_id) { + return network.getWANNetworks().then(L.bind(function(nets) { + if (nets.length) + this.placeholder = nets[0].getIPAddr(); + return form.Value.prototype.load.apply(this, [section_id]); + }, this)); + }; + + o = s.taboption('general', form.Value, 'peeraddr', _('Remote IPv4 address'), _('This IPv4 address of the relay')); + o.rmempty = false; + o.datatype = 'ip4addr("nomask")'; + + o = s.taboption('general', form.Value, 'ip6prefix', _('IPv6 prefix'), _('The IPv6 prefix assigned to the provider, usually ends with <code>::</code>')); + o.rmempty = false; + o.datatype = 'ip6addr'; + + o = s.taboption('general', form.Value, 'ip6prefixlen', _('IPv6 prefix length'), _('The length of the IPv6 prefix in bits')); + o.placeholder = '16'; + o.datatype = 'range(0,128)'; + + o = s.taboption('general', form.Value, 'ip4prefixlen', _('IPv4 prefix length'), _('The length of the IPv4 prefix in bits, the remainder is used in the IPv6 addresses.')); + o.placeholder = '0'; + o.datatype = 'range(0,32)'; + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric')); + o.placeholder = '0'; + o.datatype = 'uinteger'; + o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.Value, 'ttl', _('Use TTL on tunnel interface')); + o.placeholder = '64'; + o.datatype = 'range(1,255)'; + + o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface')); + o.placeholder = '1280'; + o.datatype = 'max(9200)'; + } +}); diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6to4.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6to4.js new file mode 100644 index 0000000000..abfe1c8fc4 --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/6to4.js @@ -0,0 +1,65 @@ +'use strict'; +'require form'; +'require network'; + +network.registerPatternVirtual(/^6to4-.+$/); + +return network.registerProtocol('6to4', { + getI18n: function() { + return _('IPv6-over-IPv4 (6to4)'); + }, + + getIfname: function() { + return this._ubus('l3_device') || '6to4-%s'.format(this.sid); + }, + + getOpkgPackage: function() { + return '6rd'; + }, + + isFloating: function() { + return true; + }, + + isVirtual: function() { + return true; + }, + + getDevices: function() { + return null; + }, + + containsDevice: function(ifname) { + return (network.getIfnameOf(ifname) == this.getIfname()); + }, + + renderFormOptions: function(s) { + var o; + + o = s.taboption('general', form.Value, 'ipaddr', _('Local IPv4 address'), _('Leave empty to use the current WAN address')); + o.datatype = 'ip4addr("nomask")'; + o.load = function(section_id) { + return network.getWANNetworks().then(L.bind(function(nets) { + if (nets.length) + this.placeholder = nets[0].getIPAddr(); + return form.Value.prototype.load.apply(this, [section_id]); + }, this)); + }; + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric')); + o.placeholder = '0'; + o.datatype = 'uinteger'; + o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.Value, 'ttl', _('Use TTL on tunnel interface')); + o.placeholder = '64'; + o.datatype = 'range(1,255)'; + + o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface')); + o.placeholder = '1280'; + o.datatype = 'max(9200)'; + } +}); diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/dhcpv6.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/dhcpv6.js new file mode 100644 index 0000000000..eba58f4248 --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/dhcpv6.js @@ -0,0 +1,58 @@ +'use strict'; +'require form'; +'require network'; + +return network.registerProtocol('dhcpv6', { + getI18n: function() { + return _('DHCPv6 client'); + }, + + getOpkgPackage: function() { + return 'odhcp6c'; + }, + + renderFormOptions: function(s) { + var dev = this.getL2Device() || this.getDevice(), o; + + o = s.taboption('general', form.ListValue, 'reqaddress', _('Request IPv6-address')); + o.value('try'); + o.value('force'); + o.value('none', 'disabled'); + o.default = 'try'; + + o = s.taboption('general', form.Value, 'reqprefix', _('Request IPv6-prefix of length')); + o.value('auto', _('Automatic')); + o.value('no', _('disabled')); + o.value('48'); + o.value('52'); + o.value('56'); + o.value('60'); + o.value('64'); + o.default = 'auto'; + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Use default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.DynamicList, 'ip6prefix', _('Custom delegated IPv6-prefix')); + o.datatype = 'cidr6'; + + o = s.taboption('advanced', form.Flag, 'peerdns', _('Use DNS servers advertised by peer'), _('If unchecked, the advertised DNS server addresses are ignored')); + o.default = o.enabled; + + o = s.taboption('advanced', form.DynamicList, 'dns', _('Use custom DNS servers')); + o.depends('peerdns', '0'); + o.datatype = 'ipaddr'; + o.cast = 'string'; + + o = s.taboption('advanced', form.Value, 'clientid', _('Client ID to send when requesting DHCP')); + o.datatype = 'hexstring'; + + o = s.taboption('advanced', form.Value, 'macaddr', _('Override MAC address')); + o.datatype = 'macaddr'; + o.placeholder = dev ? (dev.getMAC() || '') : ''; + + o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU')); + o.placeholder = dev ? (dev.getMTU() || '1500') : '1500'; + o.datatype = 'max(9200)'; + } +}); diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/dslite.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/dslite.js new file mode 100644 index 0000000000..fa0e68ddc3 --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/dslite.js @@ -0,0 +1,79 @@ +'use strict'; +'require form'; +'require network'; +'require tools.widgets as widgets'; + +network.registerPatternVirtual(/^ds-.+$/); +network.registerErrorCode('AFTR_DNS_FAIL', _('Unable to resolve AFTR host name')); + +return network.registerProtocol('dslite', { + getI18n: function() { + return _('Dual-Stack Lite (RFC6333)'); + }, + + getIfname: function() { + return this._ubus('l3_device') || 'ds-%s'.format(this.sid); + }, + + getOpkgPackage: function() { + return 'ds-lite'; + }, + + isFloating: function() { + return true; + }, + + isVirtual: function() { + return true; + }, + + getDevices: function() { + return null; + }, + + containsDevice: function(ifname) { + return (network.getIfnameOf(ifname) == this.getIfname()); + }, + + renderFormOptions: function(s) { + var o; + + o = s.taboption('general', form.Value, 'peeraddr', _('DS-Lite AFTR address')); + o.rmempty = false; + o.datatype = 'or(hostname,ip6addr("nomask"))'; + + o = s.taboption('general', form.Value, 'ip6addr', _('Local IPv6 address'), _('Leave empty to use the current WAN address')); + o.datatype = 'ip6addr("nomask")'; + o.load = function(section_id) { + return network.getWAN6Networks().then(L.bind(function(nets) { + if (Array.isArray(nets) && nets.length) + this.placeholder = nets[0].getIP6Addr(); + return form.Value.prototype.load.apply(this, [section_id]); + }, this)); + }; + + o = s.taboption('advanced', widgets.NetworkSelect, 'tunlink', _('Tunnel Link')); + o.nocreate = true; + o.exclude = s.section; + + o = s.taboption('advanced', form.ListValue, 'encaplimit', _('Encapsulation limit')); + o.rmempty = false; + o.default = 'ignore'; + o.datatype = 'or("ignore",range(0,255))'; + o.value('ignore', _('ignore')); + for (var i = 0; i < 256; i++) + o.value(i); + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric')); + o.placeholder = '0'; + o.datatype = 'uinteger'; + o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface')); + o.placeholder = '1280'; + o.datatype = 'max(9200)'; + } +}); diff --git a/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/map.js b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/map.js new file mode 100644 index 0000000000..006ebfbf08 --- /dev/null +++ b/protocols/luci-proto-ipv6/htdocs/luci-static/resources/protocol/map.js @@ -0,0 +1,96 @@ +'use strict'; +'require form'; +'require network'; +'require tools.widgets as widgets'; + +network.registerPatternVirtual(/^map-.+$/); +network.registerErrorCode('INVALID_MAP_RULE', _('MAP rule is invalid')); +network.registerErrorCode('NO_MATCHING_PD', _('No matching prefix delegation')); +network.registerErrorCode('UNSUPPORTED_TYPE', _('Unsupported MAP type')); + +return network.registerProtocol('map', { + getI18n: function() { + return _('MAP / LW4over6'); + }, + + getIfname: function() { + return this._ubus('l3_device') || 'map-%s'.format(this.sid); + }, + + getOpkgPackage: function() { + return 'map-t'; + }, + + isFloating: function() { + return true; + }, + + isVirtual: function() { + return true; + }, + + getDevices: function() { + return null; + }, + + containsDevice: function(ifname) { + return (network.getIfnameOf(ifname) == this.getIfname()); + }, + + renderFormOptions: function(s) { + var o; + + o = s.taboption('general', form.ListValue, 'type', _('Type')); + o.value('map-e', 'MAP-E'); + o.value('map-t', 'MAP-T'); + o.value('lw4o6', 'LW4over6'); + + o = s.taboption('general', form.Value, 'peeraddr', _('BR / DMR / AFTR')); + o.rmempty = false; + o.datatype = 'ip6addr'; + + o = s.taboption('general', form.Value, 'ipaddr', _('IPv4 prefix')); + o.datatype = 'ip4addr'; + + o = s.taboption('general', form.Value, 'ip4prefixlen', _('IPv4 prefix length'), _('The length of the IPv4 prefix in bits, the remainder is used in the IPv6 addresses.')); + o.placeholder = '32'; + o.datatype = 'range(0,32)'; + + o = s.taboption('general', form.Value, 'ip6prefix', _('IPv6 prefix'), _('The IPv6 prefix assigned to the provider, usually ends with <code>::</code>')); + o.rmempty = false; + o.datatype = 'ip6addr'; + + o = s.taboption('general', form.Value, 'ip6prefixlen', _('IPv6 prefix length'), _('The length of the IPv6 prefix in bits')); + o.placeholder = '16'; + o.datatype = 'range(0,64)'; + + o = s.taboption('general', form.Value, 'ealen', _('EA-bits length')); + o.datatype = 'range(0,48)'; + + o = s.taboption('general', form.Value, 'psidlen', _('PSID-bits length')); + o.datatype = 'range(0,16)'; + + o = s.taboption('general', form.Value, 'offset', _('PSID offset')); + o.datatype = 'range(0,16)'; + + o = s.taboption('advanced', widgets.NetworkSelect, 'tunlink', _('Tunnel Link')); + o.nocreate = true; + o.exclude = s.section; + + o = s.taboption('advanced', form.Flag, 'defaultroute', _('Default gateway'), _('If unchecked, no default route is configured')); + o.default = o.enabled; + + o = s.taboption('advanced', form.Value, 'metric', _('Use gateway metric')); + o.placeholder = '0'; + o.datatype = 'uinteger'; + o.depends('defaultroute', '1'); + + o = s.taboption('advanced', form.Value, 'ttl', _('Use TTL on tunnel interface')); + o.placeholder = '64'; + o.datatype = 'range(1,255)'; + + o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface')); + o.placeholder = '1280'; + o.datatype = 'max(9200)'; + } +}); |