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 === 20 && 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.firstElementChild !== tb.lastElementChild)
24 tb.removeChild(tb.lastElementChild);
26 for (var i = 0; i < st[0].length; i++)
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>';
35 timestr = String.format('%t', st[0][i].expires);
37 tb.appendChild(E('<div class="tr cbi-section-table-row cbi-rowstyle-%d">'.format((i % 2) + 1), [
38 E('<div class="td">', st[0][i].hostname || '?'),
39 E('<div class="td">', st[0][i].ipaddr),
40 E('<div class="td">', st[0][i].macaddr),
41 E('<div class="td">', timestr)
45 if (tb.firstElementChild === tb.lastElementChild)
46 tb.appendChild(E('<div class="tr cbi-section-table-row"><div class="td"><em><br /><%:There are no active leases.%></em></div></div>'));
49 var tb6 = document.getElementById('lease6_status_table');
50 if (st && st[1] && tb6)
52 tb6.parentNode.style.display = 'block';
55 while (tb6.firstElementChild !== tb6.lastElementChild)
56 tb6.removeChild(tb6.lastElementChild);
58 for (var i = 0; i < st[1].length; i++)
62 if (st[1][i].expires === false)
63 timestr = '<em><%:unlimited%></em>';
64 else if (st[1][i].expires <= 0)
65 timestr = '<em><%:expired%></em>';
67 timestr = String.format('%t', st[1][i].expires);
69 var host = hosts[duid2mac(st[1][i].duid)],
70 name = st[1][i].hostname,
75 hint = host.name || host.ipv4 || host.ipv6;
78 if (host && host.name && st[1][i].hostname != host.name)
82 tb6.appendChild(E('<div class="tr cbi-section-table-row cbi-rowstyle-%d" style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">'.format((i % 2) + 1), [
83 E('<div class="td">', hint ? '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">%h (%h)</div>'.format(name || '?', hint) : (name || '?')),
84 E('<div class="td">', st[1][i].ip6addr),
85 E('<div class="td">', st[1][i].duid),
86 E('<div class="td">', timestr)
90 if (tb6.firstElementChild === tb6.lastElementChild)
91 tb6.appendChild(E('<div class="tr cbi-section-table-row"><div class="td"><em><br /><%:There are no active leases.%></em></div></div>'));
97 <fieldset class="cbi-section">
98 <legend><%:Active DHCP Leases%></legend>
99 <div class="table cbi-section-table" id="lease_status_table">
100 <div class="tr cbi-section-table-titles">
101 <div class="th cbi-section-table-cell"><%:Hostname%></div>
102 <div class="th cbi-section-table-cell"><%:IPv4-Address%></div>
103 <div class="th cbi-section-table-cell"><%:MAC-Address%></div>
104 <div class="th cbi-section-table-cell"><%:Leasetime remaining%></div>
106 <div class="tr cbi-section-table-row">
107 <div class="td" colspan="4"><em><br /><%:Collecting data...%></em></div>
112 <fieldset class="cbi-section" style="display:none">
113 <legend><%:Active DHCPv6 Leases%></legend>
114 <div class="table cbi-section-table" id="lease6_status_table">
115 <div class="tr cbi-section-table-titles">
116 <div class="th cbi-section-table-cell"><%:Host%></div>
117 <div class="th cbi-section-table-cell"><%:IPv6-Address%></div>
118 <div class="th cbi-section-table-cell"><%:DUID%></div>
119 <div class="th cbi-section-table-cell"><%:Leasetime remaining%></div>
121 <div class="tr cbi-section-table-row">
122 <div class="td" colspan="4"><em><br /><%:Collecting data...%></em></div>