9a4d85a7061bd9610edfbeb900fc18b820132bd5
[project/luci.git] / applications / luci-app-mwan3 / luasrc / view / mwan / overview_status_interface.htm
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 for ( var iface in status.interfaces)
27 {
28 var state = '';
29 var css = '';
30 var time = '';
31 switch (status.interfaces[iface].status)
32 {
33 case 'online':
34 state = '<%:Online%>';
35 time = String.format(
36 '<div><strong>Uptime:&nbsp;</strong>%s</div>',
37 secondsToString(status.interfaces[iface].online)
38 );
39 css = 'success';
40 break;
41 case 'offline':
42 state = '<%:Offline%>';
43 time = String.format(
44 '<div><strong>Downtime:&nbsp;</strong>%s</div>',
45 secondsToString(status.interfaces[iface].offline)
46 );
47 css = 'danger';
48 break;
49 case 'notracking':
50 state = '<%:No Tracking%>';
51 if ((status.interfaces[iface].uptime) > 0) {
52 time = String.format(
53 '<div><strong>Uptime:&nbsp;</strong>%s</div>',
54 secondsToString(status.interfaces[iface].uptime)
55 );
56 css = 'success';
57 }
58 else {
59 time = '<div>&nbsp;</div>'
60 css = 'warning';
61 }
62 break;
63 default:
64 state = '<%:Disabled%>';
65 time = '<div>&nbsp;</div>'
66 css = 'warning';
67 break;
68 }
69 statusview += String.format(
70 '<div class="alert-message %s">',
71 css
72 );
73 statusview += String.format(
74 '<div><strong>Interface:&nbsp;</strong>%s</div>',
75 iface
76 );
77 statusview += String.format(
78 '<div><strong>Status:&nbsp;</strong>%s</div>',
79 state
80 );
81 if (time)
82 {
83 statusview += time;
84 }
85 statusview += '</div>'
86 }
87 statusDiv.innerHTML = statusview;
88 }
89 else
90 {
91 statusDiv.innerHTML = '<strong><%:No MWAN interfaces found%></strong>';
92 }
93 }
94 );
95 //]]></script>
96
97 <style type="text/css">
98 #mwan_status_text > div {
99 display: inline-block;
100 margin: 1rem;
101 padding: 1rem;
102 width: 10rem;
103 float: left;
104 line-height: 125%;
105 }
106 </style>
107
108 <fieldset id="interface_field" class="cbi-section">
109 <legend><%:MWAN Interfaces%></legend>
110 <div id="mwan_status_text">
111 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
112 <%:Collecting data...%>
113 </div>
114 </fieldset>