ppp.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict';
  2. 'require rpc';
  3. 'require uci';
  4. 'require form';
  5. 'require network';
  6. var callFileList = rpc.declare({
  7. object: 'file',
  8. method: 'list',
  9. params: [ 'path' ],
  10. expect: { entries: [] },
  11. filter: function(list, params) {
  12. var rv = [];
  13. for (var i = 0; i < list.length; i++)
  14. if (list[i].name.match(/^tty[A-Z]/) || list[i].name.match(/^cdc-wdm/) || list[i].name.match(/^[0-9]+$/))
  15. rv.push(params.path + list[i].name);
  16. return rv.sort();
  17. }
  18. });
  19. network.registerPatternVirtual(/^ppp-.+$/);
  20. function write_keepalive(section_id, value) {
  21. var f_opt = this.map.lookupOption('_keepalive_failure', section_id),
  22. i_opt = this.map.lookupOption('_keepalive_interval', section_id),
  23. f = (f_opt != null) ? +f_opt[0].formvalue(section_id) : null,
  24. i = (i_opt != null) ? +i_opt[0].formvalue(section_id) : null;
  25. if (f == null || f == '' || isNaN(f))
  26. f = 0;
  27. if (i == null || i == '' || isNaN(i) || i < 1)
  28. i = 1;
  29. if (f > 0)
  30. uci.set('network', section_id, 'keepalive', '%d %d'.format(f, i));
  31. else
  32. uci.unset('network', section_id, 'keepalive');
  33. }
  34. return network.registerProtocol('ppp', {
  35. getI18n: function() {
  36. return _('PPP');
  37. },
  38. getIfname: function() {
  39. return this._ubus('l3_device') || 'ppp-%s'.format(this.sid);
  40. },
  41. getOpkgPackage: function() {
  42. return 'ppp';
  43. },
  44. isFloating: function() {
  45. return true;
  46. },
  47. isVirtual: function() {
  48. return true;
  49. },
  50. getDevices: function() {
  51. return null;
  52. },
  53. containsDevice: function(ifname) {
  54. return (network.getIfnameOf(ifname) == this.getIfname());
  55. },
  56. renderFormOptions: function(s) {
  57. var dev = this.getL3Device() || this.getDevice(), o;
  58. o = s.taboption('general', form.Value, '_modem_device', _('Modem device'));
  59. o.ucioption = 'device';
  60. o.rmempty = false;
  61. o.load = function(section_id) {
  62. return callFileList('/dev/').then(L.bind(function(devices) {
  63. for (var i = 0; i < devices.length; i++)
  64. this.value(devices[i]);
  65. return callFileList('/dev/tts/');
  66. }, this)).then(L.bind(function(devices) {
  67. for (var i = 0; i < devices.length; i++)
  68. this.value(devices[i]);
  69. return form.Value.prototype.load.apply(this, [section_id]);
  70. }, this));
  71. };
  72. s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
  73. o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
  74. o.password = true;
  75. if (L.hasSystemFeature('ipv6')) {
  76. o = s.taboption('advanced', form.ListValue, 'ppp_ipv6', _('Obtain IPv6 address'), _('Enable IPv6 negotiation on the PPP link'));
  77. o.ucioption = 'ipv6';
  78. o.value('auto', _('Automatic'));
  79. o.value('0', _('Disabled'));
  80. o.value('1', _('Manual'));
  81. o.default = 'auto';
  82. }
  83. 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'));
  84. o.placeholder = '5';
  85. o.datatype = 'uinteger';
  86. o.write = write_keepalive;
  87. o.remove = write_keepalive;
  88. o.cfgvalue = function(section_id) {
  89. var v = uci.get('network', section_id, 'keepalive');
  90. if (typeof(v) == 'string' && v != '') {
  91. var m = v.match(/^(\d+)[ ,]\d+$/);
  92. return m ? m[1] : v;
  93. }
  94. };
  95. 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'));
  96. o.placeholder = '1';
  97. o.datatype = 'min(1)';
  98. o.write = write_keepalive;
  99. o.remove = write_keepalive;
  100. o.cfgvalue = function(section_id) {
  101. var v = uci.get('network', section_id, 'keepalive');
  102. if (typeof(v) == 'string' && v != '') {
  103. var m = v.match(/^\d+[ ,](\d+)$/);
  104. return m ? m[1] : v;
  105. }
  106. };
  107. o = s.taboption('advanced', form.Value, 'demand', _('Inactivity timeout'), _('Close inactive connection after the given amount of seconds, use 0 to persist connection'));
  108. o.placeholder = '0';
  109. o.datatype = 'uinteger';
  110. o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
  111. o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
  112. o.datatype = 'max(9200)';
  113. }
  114. });