luci-mod-admin-full: properly skip over unused switch ports
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_network / lease_status.htm
1 <script type="text/javascript">//<![CDATA[
2         function duid2mac(duid) {
3                 // DUID-LLT / Ethernet
4                 if (duid.length === 28 && duid.substr(0, 8) === '00010001')
5                         return duid.substr(16).replace(/(..)(?=..)/g, '$1:').toUpperCase();
6
7                 // DUID-LL / Ethernet
8                 if (duid.length === 24 && duid.substr(0, 8) === '00030001')
9                         return duid.substr(8).replace(/(..)(?=..)/g, '$1:').toUpperCase();
10
11                 return null;
12         }
13
14         var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%>;
15
16         XHR.poll(5, '<%=url('admin/network/dhcplease_status')%>', null,
17                 function(x, st)
18                 {
19                         var tb = document.getElementById('lease_status_table');
20                         if (st && st[0] && tb)
21                         {
22                                 /* clear all rows */
23                                 while( tb.rows.length > 1 )
24                                         tb.deleteRow(1);
25
26                                 for( var i = 0; i < st[0].length; i++ )
27                                 {
28                                         var timestr;
29
30                                         if (st[0][i].expires <= 0)
31                                         {
32                                                 timestr = '<em><%:expired%></em>';
33                                         }
34                                         else
35                                         {
36                                                 timestr = String.format('%t', st[0][i].expires);
37                                         }
38
39                                         var tr = tb.insertRow(-1);
40                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
41
42                                         tr.insertCell(-1).innerHTML = st[0][i].hostname ? st[0][i].hostname : '?';
43                                         tr.insertCell(-1).innerHTML = st[0][i].ipaddr;
44                                         tr.insertCell(-1).innerHTML = st[0][i].macaddr;
45                                         tr.insertCell(-1).innerHTML = timestr;
46                                 }
47
48                                 if( tb.rows.length == 1 )
49                                 {
50                                         var tr = tb.insertRow(-1);
51                                                 tr.className = 'cbi-section-table-row';
52
53                                         var td = tr.insertCell(-1);
54                                                 td.colSpan = 4;
55                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
56                                 }
57                         }
58
59                         var tb6 = document.getElementById('lease6_status_table');
60                         if (st && st[1] && tb6)
61                         {
62                                 tb6.parentNode.style.display = 'block';
63
64                                 /* clear all rows */
65                                 while( tb6.rows.length > 1 )
66                                         tb6.deleteRow(1);
67
68                                 for( var i = 0; i < st[1].length; i++ )
69                                 {
70                                         var timestr;
71
72                                         if (st[1][i].expires <= 0)
73                                         {
74                                                 timestr = '<em><%:expired%></em>';
75                                         }
76                                         else
77                                         {
78                                                 timestr = String.format('%t', st[1][i].expires);
79                                         }
80
81                                         var tr = tb6.insertRow(-1);
82                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
83
84                                         var host = hosts[duid2mac(st[1][i].duid)];
85                                         if (host)
86                                                 tr.insertCell(-1).innerHTML = String.format(
87                                                         '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis">%s</div>',
88                                                         ((host.name && (host.ipv4 || host.ipv6))
89                                                                 ? '%h (%s)'.format(host.name, host.ipv4 || host.ipv6)
90                                                                 : '%h'.format(host.name || host.ipv4 || host.ipv6)).nobr()
91                                                 );
92                                         else
93                                                 tr.insertCell(-1).innerHTML = st[1][i].hostname ? st[1][i].hostname : '?';
94
95                                         tr.insertCell(-1).innerHTML = st[1][i].ip6addr;
96                                         tr.insertCell(-1).innerHTML = st[1][i].duid;
97                                         tr.insertCell(-1).innerHTML = timestr;
98                                 }
99
100                                 if( tb6.rows.length == 1 )
101                                 {
102                                         var tr = tb6.insertRow(-1);
103                                                 tr.className = 'cbi-section-table-row';
104
105                                         var td = tr.insertCell(-1);
106                                                 td.colSpan = 4;
107                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
108                                 }
109                         }
110                 }
111         );
112 //]]></script>
113
114 <fieldset class="cbi-section">
115         <legend><%:Active DHCP Leases%></legend>
116         <table class="cbi-section-table" id="lease_status_table">
117                 <tr class="cbi-section-table-titles">
118                         <th class="cbi-section-table-cell"><%:Hostname%></th>
119                         <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
120                         <th class="cbi-section-table-cell"><%:MAC-Address%></th>
121                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
122                 </tr>
123                 <tr class="cbi-section-table-row">
124                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
125                 </tr>
126         </table>
127 </fieldset>
128
129 <fieldset class="cbi-section" style="display:none">
130         <legend><%:Active DHCPv6 Leases%></legend>
131         <table class="cbi-section-table" id="lease6_status_table">
132                 <tr class="cbi-section-table-titles">
133                         <th class="cbi-section-table-cell"><%:Host%></th>
134                         <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
135                         <th class="cbi-section-table-cell"><%:DUID%></th>
136                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
137                 </tr>
138                 <tr class="cbi-section-table-row">
139                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
140                 </tr>
141         </table>
142 </fieldset>