vti.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. 'require form';
  3. 'require network';
  4. 'require tools.widgets as widgets';
  5. network.registerPatternVirtual(/^vti-.+$/);
  6. return network.registerProtocol('vti', {
  7. getI18n: function() {
  8. return _('VTI');
  9. },
  10. getIfname: function() {
  11. return this._ubus('l3_device') || 'vti-%s'.format(this.sid);
  12. },
  13. getOpkgPackage: function() {
  14. return 'vti';
  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 dev = this.getL3Device() || this.getDevice(), o;
  30. o = s.taboption('general', form.Value, 'peeraddr', _("Remote IPv4 address or FQDN"), _("The IPv4 address or the fully-qualified domain name of the remote tunnel end."));
  31. o.optional = false;
  32. o.datatype = 'or(hostname,ip4addr("nomask"))';
  33. o = s.taboption('general', form.Value, 'ipaddr', _("Local IPv4 address"), _("The local IPv4 address over which the tunnel is created (optional)."));
  34. o.optional = true;
  35. o.datatype = 'ip4addr("nomask")';
  36. o.load = function(section_id) {
  37. return network.getWANNetworks().then(L.bind(function(nets) {
  38. if (nets.length)
  39. this.placeholder = nets[0].getIPAddr();
  40. return form.Value.prototype.load.apply(this, [section_id]);
  41. }, this));
  42. };
  43. o = s.taboption('general', form.Value, 'mtu', _('Override MTU'));
  44. o.placeholder = dev ? (dev.getMTU() || '1280') : '1280';
  45. o.datatype = 'max(1500)';
  46. o = s.taboption('general', widgets.NetworkSelect, 'tunlink', _("Bind interface"), _("Bind the tunnel to this interface (optional)."));
  47. o.exclude = s.section;
  48. o.nocreate = true;
  49. o.optional = true;
  50. o = s.taboption('general', form.Value, 'ikey', _("Incoming key"), _("Key for incoming packets (optional)."));
  51. o.optional = true;
  52. o.datatype = 'uinteger';
  53. o = s.taboption('general', form.Value, 'okey', _("Outgoing key"), _("Key for outgoing packets (optional)."));
  54. o.optional = true;
  55. o.datatype = 'uinteger';
  56. }
  57. });