pppossh.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. 'require uci';
  3. 'require form';
  4. 'require network';
  5. network.registerPatternVirtual(/^pppossh-.+$/);
  6. function write_keepalive(section_id, value) {
  7. var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
  8. i_opt = this.map.lookupOption('_keepalive_interval', section_id),
  9. f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
  10. i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
  11. if (f == null || f == '' || isNaN(f))
  12. f = 0;
  13. if (i == null || i == '' || isNaN(i) || i < 1)
  14. i = 1;
  15. if (f > 0)
  16. uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
  17. else
  18. uci.unset('network', section_id, 'keepalive');
  19. }
  20. return network.registerProtocol('pppossh', {
  21. getI18n: function() {
  22. return _('PPPoSSH');
  23. },
  24. getIfname: function() {
  25. return this._ubus('l3_device') || 'pppossh-%s'.format(this.sid);
  26. },
  27. getOpkgPackage: function() {
  28. return 'pppossh';
  29. },
  30. isFloating: function() {
  31. return true;
  32. },
  33. isVirtual: function() {
  34. return true;
  35. },
  36. getDevices: function() {
  37. return null;
  38. },
  39. containsDevice: function(ifname) {
  40. return (network.getIfnameOf(ifname) == this.getIfname());
  41. },
  42. renderFormOptions: function(s) {
  43. var o;
  44. o = s.taboption('general', form.Value, 'sshuser', _('SSH username'));
  45. o.rmempty = false;
  46. o.validate = function(section_id, value) {
  47. var id_opt = this.section.children.filter(function(o) { return o.option == 'identity' })[0];
  48. if (id_opt && value.length) {
  49. var input = this.map.findElement('id', id_opt.cbid(section_id)).querySelector('input[type="text"]');
  50. if (input)
  51. input.placeholder = (value == 'root' ? '/root' : '/home/' + value) + '/.ssh/id_rsa';
  52. }
  53. return true;
  54. };
  55. o = s.taboption('general', form.Value, 'server', _('SSH server address'));
  56. o.datatype = 'host(0)';
  57. o.rmempty = false;
  58. o = s.taboption('general', form.Value, 'port', _('SSH server port'));
  59. o.datatype = 'port';
  60. o.optional = true;
  61. o.placeholder = 22;
  62. o = s.taboption('general', form.Value, 'ssh_options', _('Extra SSH command options'));
  63. o.optional = true;
  64. o = s.taboption('general', form.DynamicList, 'identity', _('List of SSH key files for auth'));
  65. o.optional = true;
  66. o.datatype = 'file';
  67. o = s.taboption('general', form.Value, 'ipaddr', _('Local IP address to assign'));
  68. o.datatype = 'ipaddr("nomask")';
  69. o = s.taboption('general', form.Value, 'peeraddr', _('Peer IP address to assign'));
  70. o.datatype = 'ipaddr("nomask")';
  71. if (L.hasSystemFeature('ipv6')) {
  72. o = s.taboption('advanced', form.Flag, 'ppp_ipv6', _('Obtain IPv6 address'), _('Enable IPv6 negotiation on the PPP link'));
  73. o.ucioption = 'ipv6';
  74. o.default = o.disabled;
  75. }
  76. o = s.taboption('advanced', form.Value, '_keepalive_failure', _('LCP echo failure threshold'), _('Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures'));
  77. o.placeholder = '0';
  78. o.datatype = 'uinteger';
  79. o.write = write_keepalive;
  80. o.remove = write_keepalive;
  81. o.cfgvalue = function(section_id) {
  82. var v = uci.get('network', section_id, 'keepalive');
  83. if (typeof(v) == 'string' && v != '') {
  84. var m = v.match(/^(\d+)[ ,]\d+$/);
  85. return m ? m[1] : v;
  86. }
  87. };
  88. o = s.taboption('advanced', form.Value, '_keepalive_interval', _('LCP echo interval'), _('Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold'));
  89. o.placeholder = '5';
  90. o.datatype = 'min(1)';
  91. o.write = write_keepalive;
  92. o.remove = write_keepalive;
  93. o.cfgvalue = function(section_id) {
  94. var v = uci.get('network', section_id, 'keepalive');
  95. if (typeof(v) == 'string' && v != '') {
  96. var m = v.match(/^\d+[ ,](\d+)$/);
  97. return m ? m[1] : v;
  98. }
  99. };
  100. o = s.taboption('advanced', form.Value, 'demand', _('Inactivity timeout'), _('Close inactive connection after the given amount of seconds, use 0 to persist connection'));
  101. o.placeholder = '0';
  102. o.datatype = 'uinteger';
  103. }
  104. });