1 <script type="text/javascript">//<![CDATA[
2 function duid2mac(duid) {
4 if (duid.length === 28 && duid.substr(0, 8) === '00010001')
5 return duid.substr(16).replace(/(..)(?=..)/g, '$1:').toUpperCase();
8 if (duid.length === 24 && duid.substr(0, 8) === '00030001')
9 return duid.substr(8).replace(/(..)(?=..)/g, '$1:').toUpperCase();
14 var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%>;
16 XHR.poll(5, '<%=url('admin/network/dhcplease_status')%>', null,
19 var tb = document.getElementById('lease_status_table');
20 if (st && st[0] && tb)
23 while( tb.rows.length > 1 )
26 for( var i = 0; i < st[0].length; i++ )
30 if (st[0][i].expires <= 0)
32 timestr = '<em><%:expired%></em>';
36 timestr = String.format('%t', st[0][i].expires);
39 var tr = tb.insertRow(-1);
40 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
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;
48 if( tb.rows.length == 1 )
50 var tr = tb.insertRow(-1);
51 tr.className = 'cbi-section-table-row';
53 var td = tr.insertCell(-1);
55 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
59 var tb6 = document.getElementById('lease6_status_table');
60 if (st && st[1] && tb6)
62 tb6.parentNode.style.display = 'block';
65 while( tb6.rows.length > 1 )
68 for( var i = 0; i < st[1].length; i++ )
72 if (st[1][i].expires <= 0)
74 timestr = '<em><%:expired%></em>';
78 timestr = String.format('%t', st[1][i].expires);
81 var tr = tb6.insertRow(-1);
82 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
84 var host = hosts[duid2mac(st[1][i].duid)];
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()
93 tr.insertCell(-1).innerHTML = st[1][i].hostname ? st[1][i].hostname : '?';
95 tr.insertCell(-1).innerHTML = st[1][i].ip6addr;
96 tr.insertCell(-1).innerHTML = st[1][i].duid;
97 tr.insertCell(-1).innerHTML = timestr;
100 if( tb6.rows.length == 1 )
102 var tr = tb6.insertRow(-1);
103 tr.className = 'cbi-section-table-row';
105 var td = tr.insertCell(-1);
107 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
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>
123 <tr class="cbi-section-table-row">
124 <td colspan="4"><em><br /><%:Collecting data...%></em></td>
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>
138 <tr class="cbi-section-table-row">
139 <td colspan="4"><em><br /><%:Collecting data...%></em></td>