523a780fabba923378d50f723748de336d8f66cf
[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 lose 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 html = '';
53
54                                         var s = document.getElementById('<%=self.option%>-ifc-signal');
55                                         if (s)
56                                                 s.innerHTML = String.format(
57                                                         '<img src="%s" style="width:16px; height:16px" />' +
58                                                         '<br /><small>%s</small>',
59                                                                 String.format(icon, ifc.type),
60                                                                 ifc.ifname ? ifc.ifname : '?'
61                                                 );
62
63                                         var d = document.getElementById('<%=self.option%>-ifc-description');
64                                         if (d && ifc.ifname && ifc.macaddr != '00:00:00:00:00:00')
65                                         {
66                                                 if (ifc.is_up)
67                                                 {
68                                                         html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
69                                                 }
70
71                                                 if (ifc.type != 'tunnel')
72                                                 {
73                                                         html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr);
74                                                 }
75
76                                                 html += String.format(
77                                                         '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
78                                                         '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
79                                                                 ifc.rx_bytes, ifc.rx_packets,
80                                                                 ifc.tx_bytes, ifc.tx_packets
81                                                 );
82
83                                                 if (ifc.ipaddrs && ifc.ipaddrs.length)
84                                                 {
85                                                         html += '<strong><%:IPv4%>: </strong>';
86
87                                                         for (var i = 0; i < ifc.ipaddrs.length; i++)
88                                                                 html += String.format(
89                                                                         '%s%s/%d',
90                                                                         i ? ', ' : '',
91                                                                         ifc.ipaddrs[i].addr,
92                                                                         ifc.ipaddrs[i].prefix
93                                                                 );
94
95                                                         html += '<br />';
96                                                 }
97
98                                                 if (ifc.ip6addrs && ifc.ip6addrs.length)
99                                                 {
100                                                         html += '<strong><%:IPv6%>: </strong>';
101
102                                                         for (var i = 0; i < ifc.ip6addrs.length; i++)
103                                                                 html += String.format(
104                                                                         '%s%s/%d',
105                                                                         i ? ', ' : '',
106                                                                         ifc.ip6addrs[i].addr.toUpperCase(),
107                                                                         ifc.ip6addrs[i].prefix
108                                                                 );
109
110                                                         html += '<br />';
111                                                 }
112
113                                                 d.innerHTML = html;
114                                         }
115                                         else if (d)
116                                         {
117                                                 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
118                                         }
119                                 }
120
121                                 window.setTimeout(func, 5000);
122                         }
123                 )
124         })();
125 //]]></script>
126
127 <table>
128         <tr class="cbi-section-table">
129                 <td></td>
130                 <td class="cbi-value-field" style="min-width:16px; padding:3px; text-align:center" id="<%=self.option%>-ifc-signal">
131                         <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
132                         <small>?</small>
133                 </td>
134                 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=self.option%>-ifc-description">
135                         <em><%:Collecting data...%></em>
136                 </td>
137         </tr>
138 </table>
139
140 <%+cbi/valuefooter%>