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