luci-base: view.htm: catch and render exceptions on view instantiation
[oweals/luci.git] / modules / luci-base / luasrc / view / lease_status.htm
1 <script type="text/javascript">//<![CDATA[
2         XHR.poll(-1, '<%=url('admin/dhcplease_status')%>', null,
3                 function(x, st)
4                 {
5                         var tb = document.getElementById('lease_status_table');
6                         if (st && st[0] && tb)
7                         {
8                                 var rows = [];
9
10                                 for (var i = 0; i < st[0].length; i++)
11                                 {
12                                         var timestr;
13
14                                         if (st[0][i].expires === false)
15                                                 timestr = '<em><%:unlimited%></em>';
16                                         else if (st[0][i].expires <= 0)
17                                                 timestr = '<em><%:expired%></em>';
18                                         else
19                                                 timestr = String.format('%t', st[0][i].expires);
20
21                                         rows.push([
22                                                 st[0][i].hostname || '?',
23                                                 st[0][i].ipaddr,
24                                                 st[0][i].macaddr,
25                                                 timestr
26                                         ]);
27                                 }
28
29                                 cbi_update_table(tb, rows, '<em><%:There are no active leases.%></em>');
30                         }
31
32                         var tb6 = document.getElementById('lease6_status_table');
33                         if (st && st[1] && tb6)
34                         {
35                                 tb6.parentNode.style.display = 'block';
36
37                                 var rows = [];
38
39                                 for (var i = 0; i < st[1].length; i++)
40                                 {
41                                         var timestr;
42
43                                         if (st[1][i].expires === false)
44                                                 timestr = '<em><%:unlimited%></em>';
45                                         else if (st[1][i].expires <= 0)
46                                                 timestr = '<em><%:expired%></em>';
47                                         else
48                                                 timestr = String.format('%t', st[1][i].expires);
49
50                                         var name = st[1][i].hostname,
51                                             hint = st[1][i].host_hint;
52
53                                         rows.push([
54                                                 hint ? '%h (%h)'.format(name || '?', hint) : (name || '?'),
55                                                 st[1][i].ip6addr,
56                                                 st[1][i].duid,
57                                                 timestr
58                                         ]);
59                                 }
60
61                                 cbi_update_table(tb6, rows, '<em><%:There are no active leases.%></em>');
62                         }
63                 }
64         );
65 //]]></script>
66
67 <div class="cbi-section">
68         <h3><%:Active DHCP Leases%></h3>
69         <div class="table" id="lease_status_table">
70                 <div class="tr table-titles">
71                         <div class="th"><%:Hostname%></div>
72                         <div class="th"><%:IPv4-Address%></div>
73                         <div class="th"><%:MAC-Address%></div>
74                         <div class="th"><%:Leasetime remaining%></div>
75                 </div>
76                 <div class="tr placeholder">
77                         <div class="td"><em><%:Collecting data...%></em></div>
78                 </div>
79         </div>
80 </div>
81
82 <%
83         local fs = require "nixio.fs"
84         local has_ipv6 = fs.access("/proc/net/ipv6_route")
85
86         if has_ipv6 then
87 -%>
88         <div class="cbi-section" style="display:none">
89                 <h3><%:Active DHCPv6 Leases%></h3>
90                 <div class="table" id="lease6_status_table">
91                         <div class="tr table-titles">
92                                 <div class="th"><%:Host%></div>
93                                 <div class="th"><%:IPv6-Address%></div>
94                                 <div class="th"><%:DUID%></div>
95                                 <div class="th"><%:Leasetime remaining%></div>
96                         </div>
97                         <div class="tr placeholder">
98                                 <div class="td"><em><%:Collecting data...%></em></div>
99                         </div>
100                 </div>
101         </div>
102 <% end -%>