2
0

6in4.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. 'use strict';
  2. 'require uci';
  3. 'require form';
  4. 'require network';
  5. network.registerPatternVirtual(/^6in4-.+$/);
  6. return network.registerProtocol('6in4', {
  7. getI18n: function() {
  8. return _('IPv6-in-IPv4 (RFC4213)');
  9. },
  10. getIfname: function() {
  11. return this._ubus('l3_device') || '6in4-%s'.format(this.sid);
  12. },
  13. getOpkgPackage: function() {
  14. return '6in4';
  15. },
  16. isFloating: function() {
  17. return true;
  18. },
  19. isVirtual: function() {
  20. return true;
  21. },
  22. getDevices: function() {
  23. return null;
  24. },
  25. containsDevice: function(ifname) {
  26. return (network.getIfnameOf(ifname) == this.getIfname());
  27. },
  28. renderFormOptions: function(s) {
  29. var o;
  30. o = s.taboption('general', form.Value, 'ipaddr', _('Local IPv4 address'), _('Leave empty to use the current WAN address'));
  31. o.datatype = 'ip4addr("nomask")';
  32. o.load = function(section_id) {
  33. return network.getWANNetworks().then(L.bind(function(nets) {
  34. if (nets.length)
  35. this.placeholder = nets[0].getIPAddr();
  36. return form.Value.prototype.load.apply(this, [section_id]);
  37. }, this));
  38. };
  39. o = s.taboption('general', form.Value, 'peeraddr', _('Remote IPv4 address'), _('This is usually the address of the nearest PoP operated by the tunnel broker'));
  40. o.rmempty = false;
  41. o.datatype = 'ip4addr("nomask")';
  42. 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>'));
  43. o.datatype = 'cidr6';
  44. 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'));
  45. o.datatype = 'cidr6';
  46. o = s.taboption('general', form.Flag, '_update', _('Dynamic tunnel'), _('Enable HE.net dynamic endpoint update'));
  47. o.enabled = '1';
  48. o.disabled = '0';
  49. o.write = function() {};
  50. o.remove = function() {};
  51. o.cfgvalue = function(section_id) {
  52. return !isNaN(+uci.get('network', section_id, 'tunnelid')) ? this.enabled : this.disabled;
  53. };
  54. o = s.taboption('general', form.Value, 'tunnelid', _('Tunnel ID'));
  55. o.datatype = 'uinteger';
  56. o.depends('_update', '1');
  57. o = s.taboption('general', form.Value, 'username', _('HE.net username'), _('This is the plain username for logging into the account'));
  58. o.depends('_update', '1');
  59. o.validate = function(section_id, value) {
  60. if (/^[a-fA-F0-9]{32}$/.test(value))
  61. return _('The HE.net endpoint update configuration changed, you must now use the plain username instead of the user ID!');
  62. return true;
  63. };
  64. 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'));
  65. o.password = true;
  66. o.depends('_update', '1');
  67. o = s.taboption('advanced', form.Value, 'ttl', _('Use TTL on tunnel interface'));
  68. o.placeholder = '64';
  69. o.datatype = 'range(1,255)';
  70. o = s.taboption('advanced', form.Value, 'mtu', _('Use MTU on tunnel interface'));
  71. o.placeholder = '1280';
  72. o.datatype = 'max(9200)';
  73. }
  74. });