overview.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. 'require view';
  3. 'require rpc';
  4. 'require form';
  5. 'require poll';
  6. var callLibreswanStatus = rpc.declare({
  7. object: 'libreswan',
  8. method: 'status',
  9. expect: { },
  10. });
  11. function secondsToString(seconds) {
  12. const numdays = Math.floor(seconds / 86400);
  13. seconds %= 86400;
  14. const numhours = Math.floor(seconds / 3600);
  15. seconds %= 3600;
  16. const numminutes = Math.floor(seconds / 60);
  17. const numseconds = seconds % 60;
  18. return [
  19. numdays ? `${numdays}d` : '',
  20. numhours ? `${numhours}h` : '',
  21. numminutes ? `${numminutes}m` : '',
  22. `${numseconds}s`
  23. ].filter(Boolean).join(' ');
  24. }
  25. return view.extend({
  26. render: function() {
  27. var table =
  28. E('table', { 'class': 'table lases' }, [
  29. E('tr', { 'class': 'tr table-titles' }, [
  30. E('th', { 'class': 'th' }, _('Name')),
  31. E('th', { 'class': 'th' }, _('Remote')),
  32. E('th', { 'class': 'th' }, _('Local Subnet')),
  33. E('th', { 'class': 'th' }, _('Remote Subnet')),
  34. E('th', { 'class': 'th' }, _('Tx')),
  35. E('th', { 'class': 'th' }, _('Rx')),
  36. E('th', { 'class': 'th' }, _('Phase1')),
  37. E('th', { 'class': 'th' }, _('Phase2')),
  38. E('th', { 'class': 'th' }, _('Status')),
  39. E('th', { 'class': 'th' }, _('Uptime')),
  40. E([])
  41. ])
  42. ]);
  43. poll.add(function() {
  44. return callLibreswanStatus().then(function(tunnelsInfo) {
  45. var tunnels = Array.isArray(tunnelsInfo.tunnels) ? tunnelsInfo.tunnels : [];
  46. cbi_update_table(table,
  47. tunnels.map(function(tunnel) {
  48. return [
  49. tunnel.name,
  50. tunnel.right,
  51. tunnel.leftsubnet,
  52. tunnel.rightsubnet,
  53. tunnel.tx,
  54. tunnel.rx,
  55. tunnel.phase1 ? _('Up') : _('Down'),
  56. tunnel.phase2 ? _('Up') : _('Down'),
  57. tunnel.connected ? _('Up') : _('Down'),
  58. secondsToString(tunnel.uptime),
  59. ];
  60. }),
  61. E('em', _('There are no active Tunnels'))
  62. );
  63. });
  64. });
  65. return E([
  66. E('h3', _('IPSec Tunnels Summary')),
  67. E('br'),
  68. table
  69. ]);
  70. },
  71. handleSave: null,
  72. handleSaveApply:null,
  73. handleReset: null
  74. });