Advertisement
Guest User

Untitled

a guest
Apr 11th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.56 KB | None | 0 0
  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.  
  7. <script type="text/javascript">//<![CDATA[
  8.  
  9. function secondsToString(time) {
  10.     var seconds = parseInt(time, 10);
  11.  
  12.     var hrs   = Math.floor(seconds / 3600);
  13.     seconds  -= hrs*3600;
  14.     var mnts = Math.floor(seconds / 60);
  15.     seconds  -= mnts*60;
  16.     return String.format("%sh:%sm:%ss", hrs, mnts, seconds);
  17. }
  18.  
  19. XHR.poll(-1, '<%=luci.dispatcher.build_url("admin", "status", "mwan", "interface_status")%>', null,
  20.         function(x, status)
  21.         {
  22.             var statusDiv = document.getElementById('mwan_status_text');
  23.             if (status.interfaces)
  24.             {
  25.                 var statusview = '';
  26.                 var wan0 = '';
  27.                 var wan1 = '';
  28.                 var wan2 = '';
  29.                 var wan3 = '';
  30.                 var wan4 = '';
  31.                 var wanX = '';
  32.  
  33.                 function makehtmlstuff() {
  34.                     var temphtml = '';
  35.                     switch (status.interfaces[iface].status)
  36.                     {
  37.                         case 'online':
  38.                             state = '<%:Online%>';
  39.                             time = String.format(
  40.                                 '<div><strong><%:Uptime%>:&nbsp;</strong>%s</div>',
  41.                                 secondsToString(status.interfaces[iface].online)
  42.                             );
  43.                             css = 'success';
  44.                             break;
  45.                         case 'offline':
  46.                             state = '<%:Offline%>';
  47.                             time = String.format(
  48.                                 '<div><strong><%:Downtime%>:&nbsp;</strong>%s</div>',
  49.                                 secondsToString(status.interfaces[iface].offline)
  50.                             );
  51.                             css = 'danger';
  52.                             break;
  53.                         case 'notracking':
  54.                             state = '<%:No Tracking%>';
  55.                             if ((status.interfaces[iface].uptime) > 0) {
  56.                                 time = String.format(
  57.                                     '<div><strong><%:Uptime%>:&nbsp;</strong>%s</div>',
  58.                                     secondsToString(status.interfaces[iface].uptime)
  59.                                 );
  60.                                 css = 'success';
  61.                             }
  62.                             else {
  63.                                 time = '<div>&nbsp;</div>'
  64.                                 css = 'warning';
  65.                             }
  66.                             break;
  67.                         default:
  68.                             state = '<%:Disabled%>';
  69.                             time = '<div>&nbsp;</div>'
  70.                             css = 'warning';
  71.                             break;
  72.                     }
  73.                     temphtml += String.format(
  74.                         '<div class="alert-message %s">',
  75.                         css
  76.                     );
  77.                     temphtml += String.format(
  78.                         '<div><strong><%:Interface%>:&nbsp;</strong>%s</div>',
  79.                         iface
  80.                     );
  81.  
  82.                     temphtml += String.format(
  83.                         '<div><strong><%:Status%>:&nbsp;</strong>%s</div>',
  84.                         state
  85.                     );
  86.                     if (time)
  87.                     {
  88.                         temphtml += time;
  89.                     }
  90.                     temphtml += '</div>'
  91.                     return temphtml;
  92.                 }
  93.  
  94.                 for ( var iface in status.interfaces)
  95.                 {
  96.                     var state = '';
  97.                     var css = '';
  98.                     var time = '';
  99.                
  100.                     if ( iface.includes("0") )
  101.                     { wan0 =makehtmlstuff();
  102.                     } else if ( iface.includes("1") )
  103.                     { wan1 =makehtmlstuff();
  104.                     } else if ( iface.includes("2") )
  105.                     { wan2 =makehtmlstuff();
  106.                     } else if ( iface.includes("3") )
  107.                     { wan3 =makehtmlstuff();
  108.                     } else if ( iface.includes("4") )
  109.                     { wan4 =makehtmlstuff();
  110.                     } else { wanX +=makehtmlstuff();
  111.                     }
  112.                 }
  113.                
  114.                 statusDiv.innerHTML =  wan0+wan1+wan2+wan3+wan4+wanX;
  115.             }
  116.             else
  117.             {
  118.                 statusDiv.innerHTML = '<strong><%:No MWAN interfaces found%></strong>';
  119.             }
  120.         }
  121.     );
  122. //]]></script>
  123.  
  124. <style type="text/css">
  125.     #mwan_status_text > div {
  126.         display: inline-block;
  127.         margin: 1rem;
  128.         padding: 1rem;
  129.         width: 15rem;
  130.         float: left;
  131.         line-height: 125%;
  132.     }
  133. </style>
  134.  
  135. <fieldset id="interface_field" class="cbi-section">
  136.     <legend><%:MWAN Interfaces%></legend>
  137.     <div id="mwan_status_text">
  138.         <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
  139.         <%:Collecting data...%>
  140.     </div>
  141. </fieldset>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement