overview_status_interface.htm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <%#
  2. Copyright 2014 Aedan Renner <chipdankly@gmail.com>
  3. Copyright 2018 Florian Eckert <fe@dev.tdt.de>
  4. Licensed to the public under the GNU General Public License v2.
  5. -%>
  6. <script type="text/javascript">//<![CDATA[
  7. function secondsToString(time) {
  8. var seconds = parseInt(time, 10);
  9. var hrs = Math.floor(seconds / 3600);
  10. seconds -= hrs*3600;
  11. var mnts = Math.floor(seconds / 60);
  12. seconds -= mnts*60;
  13. return String.format("%sh:%sm:%ss", hrs, mnts, seconds);
  14. }
  15. XHR.poll(-1, '<%=luci.dispatcher.build_url("admin", "status", "mwan", "interface_status")%>', null,
  16. function(x, status)
  17. {
  18. var statusDiv = document.getElementById('mwan_status_text');
  19. if (status.interfaces)
  20. {
  21. var statusview = '';
  22. for ( var iface in status.interfaces)
  23. {
  24. var state = '';
  25. var css = '';
  26. var time = '';
  27. switch (status.interfaces[iface].status)
  28. {
  29. case 'online':
  30. state = '<%:Online%>';
  31. time = String.format(
  32. '<div><strong>Uptime: </strong>%s</div>',
  33. secondsToString(status.interfaces[iface].online)
  34. );
  35. css = 'success';
  36. break;
  37. case 'offline':
  38. state = '<%:Offline%>';
  39. time = String.format(
  40. '<div><strong>Downtime: </strong>%s</div>',
  41. secondsToString(status.interfaces[iface].offline)
  42. );
  43. css = 'danger';
  44. break;
  45. default:
  46. state = '<%:Disabled%>';
  47. css = 'warning';
  48. break;
  49. }
  50. statusview += String.format(
  51. '<div class="alert-message %s">',
  52. css
  53. );
  54. statusview += String.format(
  55. '<div><strong>Interface: </strong>%s</div>',
  56. iface
  57. );
  58. statusview += String.format(
  59. '<div><strong>Status: </strong>%s</div>',
  60. state
  61. );
  62. if (time)
  63. {
  64. statusview += time;
  65. }
  66. statusview += '</div>'
  67. }
  68. statusDiv.innerHTML = statusview;
  69. }
  70. else
  71. {
  72. statusDiv.innerHTML = '<strong><%:No MWAN interfaces found%></strong>';
  73. }
  74. }
  75. );
  76. //]]></script>
  77. <style type="text/css">
  78. #mwan_status_text > div {
  79. display: inline-block;
  80. margin: 1rem;
  81. padding: 1rem;
  82. width: 10rem;
  83. float: left;
  84. line-height: 125%;
  85. }
  86. </style>
  87. <fieldset id="interface_field" class="cbi-section">
  88. <legend><%:MWAN Interfaces%></legend>
  89. <div id="mwan_status_text">
  90. <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
  91. <%:Collecting data...%>
  92. </div>
  93. </fieldset>