qos.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. 'use strict';
  2. 'require form';
  3. 'require network';
  4. 'require rpc';
  5. 'require tools.widgets as widgets';
  6. 'require view';
  7. var callHostHints = rpc.declare({
  8. object: 'luci-rpc',
  9. method: 'getHostHints',
  10. expect: { '': {} }
  11. });
  12. return view.extend({
  13. load: function() {
  14. return Promise.all([
  15. network.getNetworks(),
  16. callHostHints(),
  17. ]);
  18. },
  19. render: function (loaded_promises) {
  20. var m, s, o;
  21. const networks = loaded_promises[0];
  22. const hosts = loaded_promises[1];
  23. m = new form.Map('qos', _('Quality of Service'),
  24. _('With %s you can prioritize network traffic selected by addresses, ports or services.'.format('<abbr title=\"Quality of Service\">QoS</abbr>')));
  25. s = m.section(form.TypedSection, 'interface', _('Interfaces'));
  26. s.anonymous = false;
  27. s.addremove = true;
  28. o = s.option(form.Flag, 'enabled', _('Enable'));
  29. o = s.option(form.ListValue, 'classgroup', _('Classification group'));
  30. o.placeholder = 'Default';
  31. o.value('Default', _('default'));
  32. o.rmempty = true;
  33. o.depends({ enabled: '1' });
  34. o = s.option(form.Flag, 'overhead', _('Calculate overhead'));
  35. o.depends({ enabled: '1' });
  36. o = s.option(form.Flag, 'halfduplex', _('Half-duplex'));
  37. o.depends({ enabled: '1' });
  38. o = s.option(form.Value, 'download', _('Download speed (kbit/s)'));
  39. o.rmempty = true;
  40. o.placeholder = 1024;
  41. o.datatype = 'and(uinteger,min(1))';
  42. o.depends({ enabled: '1' });
  43. o = s.option(form.Value, 'upload', _('Upload speed (kbit/s)'));
  44. o.rmempty = true;
  45. o.placeholder = 128;
  46. o.datatype = 'and(uinteger,min(1))';
  47. o.depends({ enabled: '1' });
  48. s = m.section(form.TableSection, 'classify', _('Classification Rules'));
  49. s.anonymous = true;
  50. s.addremove = true;
  51. s.sortable = true;
  52. s.rowcolors = true;
  53. s.nodescriptions = true;
  54. o = s.option(form.ListValue, 'target', _('Target'));
  55. o.value('Priority', _('priority'));
  56. o.value('Express', _('express'));
  57. o.value('Normal', _('normal'));
  58. o.value('Low', _('low'));
  59. Object.values(L.uci.sections('qos', 'class')).forEach(function(val, index) {
  60. const n = val['.name'];
  61. if (!n.endsWith('_down'))
  62. o.value(n);
  63. });
  64. var ipaddrs = {};
  65. Object.keys(hosts).forEach(function(mac) {
  66. L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4).forEach(function(ip) {
  67. ipaddrs[ip] = mac;
  68. });
  69. L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6).forEach(function(ip) {
  70. ipaddrs[ip] = mac;
  71. });
  72. });
  73. o = s.option(form.Value, 'srchost', _('Source host'));
  74. o.rmempty = true;
  75. o.width = '15%';
  76. o.datatype = 'ipaddr';
  77. o.value('', _('all'));
  78. L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
  79. o.value(ipv4, '%s (%s)'.format(ipv4, ipaddrs[ipv4]));
  80. });
  81. o = s.option(form.Value, 'dsthost', _('Destination host'));
  82. o.rmempty = true;
  83. o.width = '15%';
  84. o.datatype = 'ipaddr';
  85. o.value('', _('all'));
  86. L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
  87. o.value(ipv4, '%s (%s)'.format(ipv4, ipaddrs[ipv4]));
  88. });
  89. o = s.option(form.Value, 'proto', _('Protocol'));
  90. o.rmempty = true;
  91. o.width = '15%';
  92. o.value('', _('all'));
  93. o.value('tcp');
  94. o.value('udp');
  95. o.value('icmp');
  96. o = s.option(form.Value, 'ports', _('Ports'));
  97. o.rmempty = true;
  98. o.width = '15%';
  99. o.value('', _('all'));
  100. o.validate = function(section, value) {
  101. if (!value) return true
  102. const valuesArray = value.split(',').map(v => v.trim());
  103. return valuesArray.every(v => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) < 65536);
  104. };
  105. o = s.option(form.Value, 'connbytes', _('Number of bytes'));
  106. o.datatype = 'uinteger';
  107. o.width = '5%';
  108. o = s.option(form.Value, 'comment', _('Comment'));
  109. o.rmempty = true;
  110. return m.render();
  111. }
  112. });