1f50db5b9e45ac3df63d7c61926ad5513b093f5b
[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 (!st[1][i].hostname)
82                                                 tr.insertCell(-1).innerHTML =
83                                                         (host && (host.name || host.ipv4 || host.ipv6))
84                                                                 ? '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">? (%h)</div>'.format(host.name || host.ipv4 || host.ipv6)
85                                                                 : '?';
86                                         else
87                                                 tr.insertCell(-1).innerHTML = st[1][i].hostname;
88
89                                         tr.insertCell(-1).innerHTML = st[1][i].ip6addr;
90                                         tr.insertCell(-1).innerHTML = st[1][i].duid;
91                                         tr.insertCell(-1).innerHTML = timestr;
92                                 }
93
94                                 if( tb6.rows.length == 1 )
95                                 {
96                                         var tr = tb6.insertRow(-1);
97                                                 tr.className = 'cbi-section-table-row';
98
99                                         var td = tr.insertCell(-1);
100                                                 td.colSpan = 4;
101                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
102                                 }
103                         }
104                 }
105         );
106 //]]></script>
107
108 <fieldset class="cbi-section">
109         <legend><%:Active DHCP Leases%></legend>
110         <table class="cbi-section-table" id="lease_status_table">
111                 <tr class="cbi-section-table-titles">
112                         <th class="cbi-section-table-cell"><%:Hostname%></th>
113                         <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
114                         <th class="cbi-section-table-cell"><%:MAC-Address%></th>
115                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
116                 </tr>
117                 <tr class="cbi-section-table-row">
118                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
119                 </tr>
120         </table>
121 </fieldset>
122
123 <fieldset class="cbi-section" style="display:none">
124         <legend><%:Active DHCPv6 Leases%></legend>
125         <table class="cbi-section-table" id="lease6_status_table">
126                 <tr class="cbi-section-table-titles">
127                         <th class="cbi-section-table-cell"><%:Host%></th>
128                         <th class="cbi-section-table-cell"><%:IPv6-Address%></th>
129                         <th class="cbi-section-table-cell"><%:DUID%></th>
130                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
131                 </tr>
132                 <tr class="cbi-section-table-row">
133                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
134                 </tr>
135         </table>
136 </fieldset>