Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / package / luci / modules / luci-mod-network / htdocs / luci-static / resources / view / network / network.js
1 function iface_reconnect(id) {
2         L.halt();
3         L.dom.content(document.getElementById(id + '-ifc-description'), E('em', _('Interface is reconnecting...')));
4         L.post(L.url('admin/network/iface_reconnect', id), L.run);
5 }
6
7 function iface_delete(ev) {
8         if (!confirm(_('Really delete this interface? The deletion cannot be undone! You might lose access to this device if you are connected via this interface'))) {
9                 ev.preventDefault();
10                 return false;
11         }
12
13         ev.target.previousElementSibling.value = '1';
14         return true;
15 }
16
17 var networks = [];
18
19 document.querySelectorAll('[data-network]').forEach(function(n) {
20         networks.push(n.getAttribute('data-network'));
21 });
22
23 function render_iface(ifc) {
24         return E('span', { class: 'cbi-tooltip-container' }, [
25                 E('img', { 'class' : 'middle', 'src': L.resource('icons/%s%s.png').format(
26                         ifc.is_alias ? 'alias' : ifc.type,
27                         ifc.is_up ? '' : '_disabled') }),
28                 E('span', { 'class': 'cbi-tooltip ifacebadge large' }, [
29                         E('img', { 'src': L.resource('icons/%s%s.png').format(
30                                 ifc.type, ifc.is_up ? '' : '_disabled') }),
31                         L.itemlist(E('span', { 'class': 'left' }), [
32                                 _('Type'),      ifc.typename,
33                                 _('Device'),    ifc.ifname,
34                                 _('Connected'), ifc.is_up ? _('yes') : _('no'),
35                                 _('MAC'),       ifc.macaddr,
36                                 _('RX'),        '%.2mB (%d %s)'.format(ifc.rx_bytes, ifc.rx_packets, _('Pkts.')),
37                                 _('TX'),        '%.2mB (%d %s)'.format(ifc.tx_bytes, ifc.tx_packets, _('Pkts.'))
38                         ])
39                 ])
40         ]);
41 }
42
43 L.poll(5, L.url('admin/network/iface_status', networks.join(',')), null,
44         function(x, ifcs) {
45                 if (ifcs) {
46                         for (var idx = 0; idx < ifcs.length; idx++) {
47                                 var ifc = ifcs[idx];
48
49                                 var s = document.getElementById(ifc.id + '-ifc-devices');
50                                 if (s) {
51                                         var c = [ render_iface(ifc) ];
52
53                                         if (ifc.subdevices && ifc.subdevices.length)
54                                         {
55                                                 var sifs = [ ' (' ];
56
57                                                 for (var j = 0; j < ifc.subdevices.length; j++)
58                                                         sifs.push(render_iface(ifc.subdevices[j]));
59
60                                                 sifs.push(')');
61
62                                                 c.push(E('span', {}, sifs));
63                                         }
64
65                                         c.push(E('br'));
66                                         c.push(E('small', {}, ifc.is_alias ? _('Alias of "%s"').format(ifc.is_alias) : ifc.name));
67
68                                         L.dom.content(s, c);
69                                 }
70
71                                 var d = document.getElementById(ifc.id + '-ifc-description');
72                                 if (d && ifc.proto && ifc.ifname) {
73                                         var desc = null, c = [];
74
75                                         if (ifc.is_dynamic)
76                                                 desc = _('Virtual dynamic interface');
77                                         else if (ifc.is_alias)
78                                                 desc = _('Alias Interface');
79
80                                         if (ifc.desc)
81                                                 desc = desc ? '%s (%s)'.format(desc, ifc.desc) : ifc.desc;
82
83                                         L.itemlist(d, [
84                                                 _('Protocol'), '%h'.format(desc || '?'),
85                                                 _('Uptime'),   ifc.is_up ? '%t'.format(ifc.uptime) : null,
86                                                 _('MAC'),      (!ifc.is_dynamic && !ifc.is_alias && ifc.macaddr) ? ifc.macaddr : null,
87                                                 _('RX'),       (!ifc.is_dynamic && !ifc.is_alias) ? '%.2mB (%d %s)'.format(ifc.rx_bytes, ifc.rx_packets, _('Pkts.')) : null,
88                                                 _('TX'),       (!ifc.is_dynamic && !ifc.is_alias) ? '%.2mB (%d %s)'.format(ifc.tx_bytes, ifc.tx_packets, _('Pkts.')) : null,
89                                                 _('IPv4'),     ifc.ipaddrs ? ifc.ipaddrs[0] : null,
90                                                 _('IPv4'),     ifc.ipaddrs ? ifc.ipaddrs[1] : null,
91                                                 _('IPv4'),     ifc.ipaddrs ? ifc.ipaddrs[2] : null,
92                                                 _('IPv4'),     ifc.ipaddrs ? ifc.ipaddrs[3] : null,
93                                                 _('IPv4'),     ifc.ipaddrs ? ifc.ipaddrs[4] : null,
94                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[0] : null,
95                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[1] : null,
96                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[2] : null,
97                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[3] : null,
98                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[4] : null,
99                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[5] : null,
100                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[6] : null,
101                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[7] : null,
102                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[8] : null,
103                                                 _('IPv6'),     ifc.ip6addrs ? ifc.ip6addrs[9] : null,
104                                                 _('IPv6-PD'),  ifc.ip6prefix,
105                                                 _('Error'),    ifc.errors ? ifc.errors[0] : null,
106                                                 _('Error'),    ifc.errors ? ifc.errors[1] : null,
107                                                 _('Error'),    ifc.errors ? ifc.errors[2] : null,
108                                                 _('Error'),    ifc.errors ? ifc.errors[3] : null,
109                                                 _('Error'),    ifc.errors ? ifc.errors[4] : null,
110                                         ]);
111                                 }
112                                 else if (d && !ifc.proto) {
113                                         var e = document.getElementById(ifc.id + '-ifc-edit');
114                                         if (e) e.disabled = true;
115
116                                         var link = L.url('admin/system/opkg') + '?query=luci-proto';
117                                         L.dom.content(d, [
118                                                 E('em', _('Unsupported protocol type.')), E('br'),
119                                                 E('a', { href: link }, _('Install protocol extensions...'))
120                                         ]);
121                                 }
122                                 else if (d && !ifc.ifname) {
123                                         var link = L.url('admin/network/network', ifc.name) + '?tab.network.%s=physical'.format(ifc.name);
124                                         L.dom.content(d, [
125                                                 E('em', _('Network without interfaces.')), E('br'),
126                                                 E('a', { href: link }, _('Assign interfaces...'))
127                                         ]);
128                                 }
129                                 else if (d) {
130                                         L.dom.content(d, E('em' ,_('Interface not present or not connected yet.')));
131                                 }
132                         }
133                 }
134         }
135 );