modules/admin-full: rework interface overview
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / iface_status.htm
1 <%+cbi/valueheader%>
2
3 <script type="text/javascript">//<![CDATA[
4 var iwxhr = new XHR();
5
6 function iface_shutdown(id, reconnect) {
7 if (!reconnect && !confirm(String.format('<%_Really shutdown network ?\nYou might loose access to this router if you are connected via this interface.%>', id)))
8 return;
9
10 var a = document.getElementById(id + '-ifc-addrs');
11 if (a)
12 {
13 a.innerHTML = reconnect
14 ? '<em><%:Interface is reconnecting...%></em>'
15 : '<em><%:Interface is shutting down...%></em>';
16 }
17
18 var s = document.getElementById('ifc-rc-status');
19 if (s)
20 {
21 s.parentNode.style.display = 'block';
22 s.innerHTML = '<%:Waiting for router...%>';
23 }
24
25 var rcxhr = new XHR();
26 rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
27 function(x)
28 {
29 if (s)
30 {
31 s.innerHTML = reconnect
32 ? '<%:Interface reconnected%>'
33 : '<%:Interface shut down%>';
34
35 window.setTimeout(function() {
36 s.parentNode.style.display = 'none';
37 }, 1000);
38 }
39 }
40 );
41 }
42
43
44 (function() {
45 var func = arguments.callee;
46
47 iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null,
48 function(x, ifc)
49 {
50 if (ifc && (ifc = ifc[0]))
51 {
52 var rxb = ifc.rx_bytes || 0;
53 var txb = ifc.tx_bytes || 0;
54 var rxp = ifc.rx_packets || 0;
55 var txp = ifc.tx_packets || 0;
56 var mac = ifc.macaddr;
57
58 var html = '';
59 var upt, icon;
60
61 if (ifc.is_up)
62 {
63 if (ifc.uptime)
64 upt = String.format('%t', ifc.uptime);
65
66 icon = "<%=resource%>/icons/%s.png";
67 }
68 else
69 {
70 icon = "<%=resource%>/icons/%s_disabled.png";
71 }
72
73 var s = document.getElementById('<%=self.option%>-ifc-signal');
74 if (s)
75 s.innerHTML = String.format(
76 '<img src="%s" style="width:16px; height:16px" />' +
77 '<br /><small>%s</small>',
78 String.format(icon, ifc.type),
79 ifc.ifname ? ifc.ifname : '?'
80 );
81
82 var d = document.getElementById('<%=self.option%>-ifc-description');
83 if (d && ifc.ifname && mac != '00:00:00:00:00:00')
84 {
85 if (upt)
86 {
87 html += String.format('<strong><%:Uptime%>:</strong> %s<br />', upt);
88 }
89
90 if (ifc.type != 'tunnel')
91 {
92 html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', mac);
93 }
94
95 html += String.format(
96 '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
97 '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
98 rxb, rxp, txb, txp
99 );
100
101 if (ifc.ipaddrs && ifc.ipaddrs.length)
102 {
103 html += '<strong><%:IPv4%>: </strong>';
104
105 for (var i = 0; i < ifc.ipaddrs.length; i++)
106 html += String.format(
107 '%s%s/%d',
108 i ? ', ' : '',
109 ifc.ipaddrs[i].addr,
110 ifc.ipaddrs[i].prefix
111 );
112
113 html += '<br />';
114 }
115
116 if (ifc.ip6addrs && ifc.ip6addrs.length)
117 {
118 html += '<strong><%:IPv6%>: </strong>';
119
120 for (var i = 0; i < ifc.ip6addrs.length; i++)
121 html += String.format(
122 '%s%s/%d',
123 i ? ', ' : '',
124 ifc.ip6addrs[i].addr.toUpperCase(),
125 ifc.ip6addrs[i].prefix
126 );
127
128 html += '<br />';
129 }
130
131 d.innerHTML = html;
132 }
133 else if (d)
134 {
135 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
136 }
137 }
138
139 window.setTimeout(func, 5000);
140 }
141 )
142 })();
143 //]]></script>
144
145 <table>
146 <tr class="cbi-section-table">
147 <td></td>
148 <td class="cbi-value-field" style="min-width:16px; padding:3px; text-align:center" id="<%=self.option%>-ifc-signal">
149 <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
150 <small>?</small>
151 </td>
152 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=self.option%>-ifc-description">
153 <em><%:Collecting data...%></em>
154 </td>
155 </tr>
156 </table>
157
158 <%+cbi/valuefooter%>