luci-mod-admin-full: abbreviate "MAC-Address" as "MAC" to align with rest
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_network / iface_overview_status.htm
1 <%#
2 Copyright 2010-2018 Jo-Philipp Wich <jo@mein.io>
3 Licensed to the public under the Apache License 2.0.
4 -%>
5
6 <script type="text/javascript">//<![CDATA[
7 function iface_reconnect(id) {
8 XHR.halt();
9
10 var d = document.getElementById(id + '-ifc-description');
11 if (d) d.innerHTML = '<em><%:Interface is reconnecting...%></em>';
12
13 (new XHR()).post('<%=url('admin/network/iface_reconnect')%>/' + id,
14 { token: '<%=token%>' }, XHR.run);
15 }
16
17 function iface_delete(ev) {
18 if (!confirm(<%=luci.http.write_json(translate('Really delete this interface? The deletion cannot be undone! You might lose access to this device if you are connected via this interface'))%>)) {
19 ev.preventDefault();
20 return false;
21 }
22
23 ev.target.previousElementSibling.value = '1';
24 return true;
25 }
26
27 var networks = [];
28
29 document.querySelectorAll('[data-network]').forEach(function(n) {
30 networks.push(n.getAttribute('data-network'));
31 });
32
33 function render_iface(ifc) {
34 return E('span', { class: 'cbi-tooltip-container' }, [
35 E('img', { 'class' : 'middle', 'src': '<%=resource%>/icons/%s%s.png'.format(
36 ifc.is_alias ? 'alias' : ifc.type,
37 ifc.is_up ? '' : '_disabled') }),
38 E('span', { 'class': 'cbi-tooltip ifacebadge large' }, [
39 E('img', { 'src': '<%=resource%>/icons/%s%s.png'.format(
40 ifc.type, ifc.is_up ? '' : '_disabled') }),
41 E('span', { 'class': 'left' }, [
42 E('strong', '<%:Type%>: '), ifc.typename, E('br'),
43 E('strong', '<%:Device%>: '), ifc.ifname, E('br'),
44 E('strong', '<%:Connected%>: '), ifc.is_up ? '<%:yes%>' : '<%:no%>', E('br'),
45 ifc.macaddr ? E('strong', '<%:MAC%>: ') : '',
46 ifc.macaddr ? ifc.macaddr : '',
47 ifc.macaddr ? E('br') : '',
48 E('strong', '<%:RX%>: '), '%.2mB (%d <%:Pkts.%>)'.format(ifc.rx_bytes, ifc.rx_packets), E('br'),
49 E('strong', '<%:TX%>: '), '%.2mB (%d <%:Pkts.%>)'.format(ifc.tx_bytes, ifc.tx_packets)
50 ])
51 ])
52 ]);
53 }
54
55 XHR.poll(5, '<%=url('admin/network/iface_status')%>/' + networks.join(','), null,
56 function(x, ifcs)
57 {
58 if (ifcs)
59 {
60 for (var idx = 0; idx < ifcs.length; idx++)
61 {
62 var ifc = ifcs[idx];
63 var html = '';
64
65 var s = document.getElementById(ifc.id + '-ifc-devices');
66 if (s)
67 {
68 while (s.firstChild)
69 s.removeChild(s.firstChild);
70
71 s.appendChild(render_iface(ifc));
72
73 if (ifc.subdevices && ifc.subdevices.length)
74 {
75 var sifs = [ ' (' ];
76
77 for (var j = 0; j < ifc.subdevices.length; j++)
78 sifs.push(render_iface(ifc.subdevices[j]));
79
80 sifs.push(')');
81
82 s.appendChild(E('span', {}, sifs));
83 }
84
85 s.appendChild(E('br'));
86 s.appendChild(E('small', {}, ifc.is_alias ? '<%:Alias of "%s"%>'.format(ifc.is_alias) : ifc.name));
87 }
88
89 var d = document.getElementById(ifc.id + '-ifc-description');
90 if (d && ifc.proto && ifc.ifname)
91 {
92 var desc = null;
93
94 if (ifc.is_dynamic)
95 desc = '<%:Virtual dynamic interface%>';
96 else if (ifc.is_alias)
97 desc = '<%:Alias Interface%>';
98
99 if (ifc.desc)
100 desc = desc ? '%s (%s)'.format(desc, ifc.desc) : ifc.desc;
101
102 html += String.format('<strong><%:Protocol%>:</strong> %h<br />', desc || '?');
103
104 if (ifc.is_up)
105 {
106 html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
107 }
108
109
110 if (!ifc.is_dynamic && !ifc.is_alias)
111 {
112 if (ifc.macaddr)
113 html += String.format('<strong><%:MAC%>:</strong> %s<br />', ifc.macaddr);
114
115 html += String.format(
116 '<strong><%:RX%>:</strong> %.2mB (%d <%:Pkts.%>)<br />' +
117 '<strong><%:TX%>:</strong> %.2mB (%d <%:Pkts.%>)<br />',
118 ifc.rx_bytes, ifc.rx_packets,
119 ifc.tx_bytes, ifc.tx_packets
120 );
121 }
122
123 if (ifc.ipaddrs && ifc.ipaddrs.length)
124 {
125 for (var i = 0; i < ifc.ipaddrs.length; i++)
126 html += String.format(
127 '<strong><%:IPv4%>:</strong> %s<br />',
128 ifc.ipaddrs[i]
129 );
130 }
131
132 if (ifc.ip6addrs && ifc.ip6addrs.length)
133 {
134 for (var i = 0; i < ifc.ip6addrs.length; i++)
135 html += String.format(
136 '<strong><%:IPv6%>:</strong> %s<br />',
137 ifc.ip6addrs[i]
138 );
139 }
140
141 if (ifc.ip6prefix)
142 html += String.format('<strong><%:IPv6-PD%>:</strong> %s<br />', ifc.ip6prefix);
143
144 if (ifc.errors)
145 {
146 for (var i = 0; i < ifc.errors.length; i++)
147 html += String.format(
148 '<em class="error"><strong><%:Error%>:</strong> %h</em><br />',
149 ifc.errors[i]
150 );
151 }
152
153 d.innerHTML = html;
154 }
155 else if (d && !ifc.proto)
156 {
157 var e = document.getElementById(ifc.id + '-ifc-edit');
158 if (e)
159 e.disabled = true;
160
161 d.innerHTML = String.format(
162 '<em><%:Unsupported protocol type.%></em><br />' +
163 '<a href="%h"><%:Install protocol extensions...%></a>',
164 '<%=url("admin/system/packages")%>?query=luci-proto&display=available'
165 );
166 }
167 else if (d && !ifc.ifname)
168 {
169 d.innerHTML = String.format(
170 '<em><%:Network without interfaces.%></em><br />' +
171 '<a href="<%=url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',
172 ifc.name, ifc.name
173 );
174 }
175 else if (d)
176 {
177 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
178 }
179 }
180 }
181 }
182 );
183 //]]></script>