b4baedff28b772158b20e093712960dd9b7abc82
[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 === false)
31                                                 timestr = '<em><%:unlimited%></em>';
32                                         else if (st[0][i].expires <= 0)
33                                                 timestr = '<em><%:expired%></em>';
34                                         else
35                                                 timestr = String.format('%t', st[0][i].expires);
36
37                                         var tr = tb.insertRow(-1);
38                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
39
40                                         tr.insertCell(-1).innerHTML = st[0][i].hostname ? st[0][i].hostname : '?';
41                                         tr.insertCell(-1).innerHTML = st[0][i].ipaddr;
42                                         tr.insertCell(-1).innerHTML = st[0][i].macaddr;
43                                         tr.insertCell(-1).innerHTML = timestr;
44                                 }
45
46                                 if( tb.rows.length == 1 )
47                                 {
48                                         var tr = tb.insertRow(-1);
49                                                 tr.className = 'cbi-section-table-row';
50
51                                         var td = tr.insertCell(-1);
52                                                 td.colSpan = 4;
53                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
54                                 }
55                         }
56
57                         var tb6 = document.getElementById('lease6_status_table');
58                         if (st && st[1] && tb6)
59                         {
60                                 tb6.parentNode.style.display = 'block';
61
62                                 /* clear all rows */
63                                 while( tb6.rows.length > 1 )
64                                         tb6.deleteRow(1);
65
66                                 for( var i = 0; i < st[1].length; i++ )
67                                 {
68                                         var timestr;
69
70                                         if (st[1][i].expires === false)
71                                                 timestr = '<em><%:unlimited%></em>';
72                                         else if (st[1][i].expires <= 0)
73                                                 timestr = '<em><%:expired%></em>';
74                                         else
75                                                 timestr = String.format('%t', st[1][i].expires);
76
77                                         var tr = tb6.insertRow(-1);
78                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
79
80                                         var host = hosts[duid2mac(st[1][i].duid)];
81                                         if (host)
82                                                 tr.insertCell(-1).innerHTML = String.format(
83                                                         '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis">%s</div>',
84                                                         ((host.name && (host.ipv4 || host.ipv6))
85                                                                 ? '%h (%s)'.format(host.name, host.ipv4 || host.ipv6)
86                                                                 : '%h'.format(host.name || host.ipv4 || host.ipv6)).nobr()
87                                                 );
88                                         else
89                                                 tr.insertCell(-1).innerHTML = st[1][i].hostname ? st[1][i].hostname : '?';
90
91                                         tr.insertCell(-1).innerHTML = st[1][i].ip6addr;
92                                         tr.insertCell(-1).innerHTML = st[1][i].duid;
93                                         tr.insertCell(-1).innerHTML = timestr;
94                                 }
95
96                                 if( tb6.rows.length == 1 )
97                                 {
98                                         var tr = tb6.insertRow(-1);
99                                                 tr.className = 'cbi-section-table-row';
100
101                                         var td = tr.insertCell(-1);
102                                                 td.colSpan = 4;
103                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
104                                 }
105                         }
106                 }
107         );
108 //]]></script>
109
110 <fieldset class="cbi-section">
111         <legend><%:Active DHCP Leases%></legend>
112         <table class="cbi-section-table" id="lease_status_table">
113                 <tr class="cbi-section-table-titles">
114                         <th class="cbi-section-table-cell"><%:Hostname%></th>
115                         <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
116                         <th class="cbi-section-table-cell"><%:MAC-Address%></th>
117                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
118                 </tr>
119                 <tr class="cbi-section-table-row">
120                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
121                 </tr>
122         </table>
123 </fieldset>
124
125 <fieldset class="cbi-section" style="display:none">
126         <legend><%:Active DHCPv6 Leases%></legend>
127         <table class="cbi-section-table" id="lease6_status_table">
128                 <tr class="cbi-section-table-titles">
129                         <th class="cbi-section-table-cell"><%:Host%></th>
130                         <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
131                         <th class="cbi-section-table-cell"><%:DUID%></th>
132                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
133                 </tr>
134                 <tr class="cbi-section-table-row">
135                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
136                 </tr>
137         </table>
138 </fieldset>