luci-mod-admin-full: cleanup markup
[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 === 20 && 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.firstElementChild !== tb.lastElementChild)
24 tb.removeChild(tb.lastElementChild);
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 tb.appendChild(E('<div class="tr 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)
42 ]));
43 }
44
45 if (tb.firstElementChild === tb.lastElementChild)
46 tb.appendChild(E('<div class="tr"><div class="td"><em><br /><%:There are no active leases.%></em></div></div>'));
47 }
48
49 var tb6 = document.getElementById('lease6_status_table');
50 if (st && st[1] && tb6)
51 {
52 tb6.parentNode.style.display = 'block';
53
54 /* clear all rows */
55 while (tb6.firstElementChild !== tb6.lastElementChild)
56 tb6.removeChild(tb6.lastElementChild);
57
58 for (var i = 0; i < st[1].length; i++)
59 {
60 var timestr;
61
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>';
66 else
67 timestr = String.format('%t', st[1][i].expires);
68
69 var host = hosts[duid2mac(st[1][i].duid)],
70 name = st[1][i].hostname,
71 hint = null;
72
73 if (!name) {
74 if (host)
75 hint = host.name || host.ipv4 || host.ipv6;
76 }
77 else {
78 if (host && host.name && st[1][i].hostname != host.name)
79 hint = host.name;
80 }
81
82 tb6.appendChild(E('<div class="tr cbi-rowstyle-%d">'.format((i % 2) + 1), [
83 E('<div class="td nowrap">', hint ? '%h (%h)'.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)
87 ]));
88 }
89
90 if (tb6.firstElementChild === tb6.lastElementChild)
91 tb6.appendChild(E('<div class="tr"><div class="td"><em><br /><%:There are no active leases.%></em></div></div>'));
92 }
93 }
94 );
95 //]]></script>
96
97 <fieldset class="cbi-section">
98 <legend><%:Active DHCP Leases%></legend>
99 <div class="table" id="lease_status_table">
100 <div class="tr">
101 <div class="th"><%:Hostname%></div>
102 <div class="th"><%:IPv4-Address%></div>
103 <div class="th"><%:MAC-Address%></div>
104 <div class="th"><%:Leasetime remaining%></div>
105 </div>
106 <div class="tr">
107 <div class="td" colspan="4"><em><br /><%:Collecting data...%></em></div>
108 </div>
109 </div>
110 </fieldset>
111
112 <fieldset class="cbi-section" style="display:none">
113 <legend><%:Active DHCPv6 Leases%></legend>
114 <div class="table" id="lease6_status_table">
115 <div class="tr">
116 <div class="th"><%:Host%></div>
117 <div class="th"><%:IPv6-Address%></div>
118 <div class="th"><%:DUID%></div>
119 <div class="th"><%:Leasetime remaining%></div>
120 </div>
121 <div class="tr">
122 <div class="td" colspan="4"><em><br /><%:Collecting data...%></em></div>
123 </div>
124 </div>
125 </fieldset>