ssh_tunnels.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. 'use strict';
  2. 'require form';
  3. 'require fs';
  4. 'require uci';
  5. 'require ui';
  6. 'require view';
  7. return view.extend({
  8. load: function () {
  9. return Promise.all([
  10. uci.load('sshtunnel'),
  11. ]);
  12. },
  13. render: function (data) {
  14. var m, s, o;
  15. m = new form.Map('sshtunnel', _('SSH Tunnels'),
  16. _('This configures <a %s>SSH Tunnels</a>.')
  17. .format('href="https://openwrt.org/docs/guide-user/services/ssh/sshtunnel"')
  18. );
  19. s = m.section(form.GridSection, 'tunnelR', _('Remote Tunnels'),
  20. _('Forward a port on the remote host to a service on the local host.')
  21. );
  22. s.anonymous = true;
  23. s.addremove = true;
  24. s.nodescriptions = true;
  25. o = s.option(form.Flag, 'enabled', _('Enabled'));
  26. o.default = '1';
  27. o = _addServerOption(s);
  28. o = s.option(form.Value, 'remoteaddress', _('Remote address'),
  29. _('Bind IP address e.g. <code>192.168.1.1</code> or hostname e.g. <code>localhost</code>.') + '<br/>' +
  30. _('<code>*</code> means to listen all interfaces <b>including public</b>.')
  31. );
  32. o.datatype = 'or(host, "*")';
  33. o.default = '*';
  34. o.rmempty = false;
  35. o = s.option(form.Value, 'remoteport', _('Remote port'));
  36. o.placeholder = '80';
  37. o.datatype = 'port';
  38. o.rmempty = false;
  39. o = s.option(form.Value, 'localaddress', _('Local address'),
  40. _('Bind IP address e.g. <code>192.168.1.1</code> or hostname e.g. <code>localhost</code>.')
  41. );
  42. o.datatype = 'host';
  43. o.default = 'localhost';
  44. o.rmempty = false;
  45. o = s.option(form.Value, 'localport', _('Local port'));
  46. o.datatype = 'port';
  47. o.placeholder = '80';
  48. o.rmempty = false;
  49. s = m.section(form.GridSection, 'tunnelL', _('Local Tunnels'),
  50. _('Forward a port on the local host to a service on the remote host.')
  51. );
  52. s.anonymous = true;
  53. s.addremove = true;
  54. s.nodescriptions = true;
  55. o = s.option(form.Flag, 'enabled', _('Enabled'));
  56. o.default = '1';
  57. o = _addServerOption(s);
  58. o = s.option(form.Value, 'localaddress', _('Local address'),
  59. _('Bind IP address e.g. <code>192.168.1.1</code> or hostname e.g. <code>localhost</code>.') + '<br/>' +
  60. _('<code>*</code> means to listen all interfaces <b>including public</b>.')
  61. );
  62. o.datatype = 'or(host, "*")';
  63. o.placeholder = '192.168.1.1'; // not the default * public iface because a user must explicitly configure it
  64. o.rmempty = false;
  65. o = s.option(form.Value, 'localport', _('Local port'));
  66. o.datatype = 'port';
  67. o.placeholder = '80';
  68. o.rmempty = false;
  69. o = s.option(form.Value, 'remoteaddress', _('Remote address'),
  70. _('Bind IP address e.g. <code>192.168.1.1</code> or hostname e.g. <code>localhost</code>.')
  71. );
  72. o.datatype = 'host';
  73. o.default = 'localhost';
  74. o.rmempty = false;
  75. o = s.option(form.Value, 'remoteport', _('Remote port'));
  76. o.datatype = 'port';
  77. o.default = '80';
  78. o.rmempty = false;
  79. s = m.section(form.GridSection, 'tunnelD', _('Dynamic Tunnels'),
  80. _('SOCKS proxy via remote host.')
  81. );
  82. s.anonymous = true;
  83. s.addremove = true;
  84. s.nodescriptions = true;
  85. o = s.option(form.Flag, 'enabled', _('Enabled'));
  86. o.default = '1';
  87. o = _addServerOption(s);
  88. o = s.option(form.Value, 'localaddress', _('Local address'),
  89. _('Bind IP address e.g. <code>192.168.1.1</code> or hostname e.g. <code>localhost</code>.') + '<br/>' +
  90. _('<code>*</code> means to listen all interfaces <b>including public</b>.')
  91. );
  92. o.datatype = 'or(host, "*")';
  93. o.placeholder = '192.168.1.1'; // not the default * public iface because a user must explicitly configure it
  94. o.rmempty = false;
  95. o = s.option(form.Value, 'localport', _('Local port'));
  96. o.datatype = 'port';
  97. o.default = '1080';
  98. o.rmempty = false;
  99. s = m.section(form.GridSection, 'tunnelW', _('VPN Tunnels'),
  100. _('Configure TUN/TAP devices for VPN tunnels.')
  101. );
  102. s.anonymous = true;
  103. s.addremove = true;
  104. s.nodescriptions = true;
  105. o = s.option(form.Flag, 'enabled', _('Enabled'));
  106. o.default = '1';
  107. o = _addServerOption(s);
  108. o = s.option(form.ListValue, 'vpntype', _('VPN type'));
  109. o.value('point-to-point', 'TUN (point-to-point)');
  110. o.value('ethernet', 'TAP (ethernet)');
  111. o.default = 'point-to-point';
  112. o = s.option(form.Value, 'localdev', _('Local dev'));
  113. o.default = 'any';
  114. o.datatype = 'or("any", min(0))';
  115. o.rmempty = false;
  116. o = s.option(form.Value, 'remotedev', _('Remote dev'));
  117. o.default = 'any';
  118. o.datatype = 'or("any", min(0))';
  119. o.rmempty = false;
  120. return m.render();
  121. },
  122. });
  123. function _addServerOption(s) {
  124. var o = s.option(form.ListValue, 'server', _('Server'));
  125. o.datatype = 'uciname';
  126. o.rmempty = false;
  127. uci.sections('sshtunnel', 'server', function (s, sectionName) {
  128. o.value(sectionName, s.hostname ? '%s (%s)'.format(sectionName, s.hostname) : sectionName);
  129. });
  130. return o;
  131. }