applications/luci-olsr: Use jsoninfo instead of txtinfo as data source.
[project/luci.git] / applications / luci-olsr / luasrc / view / status-olsr / hna.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 -%>
14
15 <%
16 local i = 1
17
18 if luci.http.formvalue("status") == "1" then
19         local rv = {}
20         for k, hna in ipairs(hna) do
21                 rv[#rv+1] = {
22                         proto = hna["proto"],
23                         destination = hna["destination"],
24                         genmask = hna["genmask"],
25                         gateway = hna["gateway"],
26                         hostname = hna["hostname"],
27                         validityTime = hna["validityTime"]
28                         }
29         end
30         luci.http.prepare_content("application/json")
31         luci.http.write_json(rv)
32         return
33 end
34 %>
35
36 <%+header%>
37
38 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
39 <script type="text/javascript">//<![CDATA[
40 XHR.poll(10, '<%=REQUEST_URI%>', { status: 1 },
41         function(x, info)
42         {
43         var hnadiv = document.getElementById('olsrd_hna');
44         if (hnadiv)
45         {
46                 var s = '';
47                 for (var idx = 0; idx < info.length; idx++)
48                 {
49                         var hna = info[idx];
50                         var linkgw = ''
51                         s += '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + hna.proto + '">'
52                         if (hna.proto == '6') {
53                                 linkgw = '<a href="http://[' + hna.gateway + ']/cgi-bin-status.html">' + hna.gateway + '</a>'
54                         } else {
55                                 linkgw = '<a href="http://' + hna.gateway + '/cgi-bin-status.html">' + hna.gateway + '</a>'
56                         }
57
58                         if (hna.validityTime != undefined) {
59                                 validity = hna.validityTime + 's'
60                         } else {
61                                 validity = '-'
62                         }
63
64                         if (hna.hostname != undefined) {
65                                 hostname = ' / <a href="http://' + hna.hostname + '/cgi-bin-status.html">' + hna.hostname + '</a>'
66                         } else {
67                                 hostname = ''
68                         }
69
70                         s += String.format(
71                                 '<td class="cbi-section-table-cell">%s</td>' +
72                                 '<td class="cbi-section-table-cell">%s</td>' +
73                                 '<td class="cbi-section-table-cell">%s</td>', hna.destination + '/' + hna.genmask, linkgw + hostname, validity
74                                 )
75                         s += '</tr>'
76                 }
77                 hnadiv.innerHTML = s;
78         }
79 }
80 );
81 //]]></script>
82
83 <h2><a id="content" name="content"><%:Active host net announcements%></a></h2>
84
85 <div id="togglebuttons"></div>
86 <fieldset class="cbi-section">
87
88         <legend><%:Overview of currently active OLSR host net announcements%></legend>
89         <table class="cbi-section-table">
90                 <thead>
91                 <tr class="cbi-section-table-titles">
92                         <th class="cbi-section-table-cell"><%:Announced network%></th>
93                         <th class="cbi-section-table-cell"><%:OLSR gateway%></th>
94                         <th class="cbi-section-table-cell"><%:Validity Time%></th>
95                 </tr>
96
97                 </thead>
98                 <tbody id="olsrd_hna">
99                 <% for k, route in ipairs(hna) do %>
100
101                 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=hna[k].proto%>">
102                         <td class="cbi-section-table-cell"><%=hna[k].destination%>/<%=hna[k].genmask%> </td>
103                         <td class="cbi-section-table-cell">
104                                 <% if hna[k].proto == '6' then %>
105                                 <a href="http://[<%=hna[k].gateway%>]/cgi-bin-status.html"><%=hna[k].gateway%></a>
106                                 <% else %>
107                                 <a href="http://<%=hna[k].gateway%>/cgi-bin-status.html"><%=hna[k].gateway%></a>
108                                 <% end %>
109                                 <% if hna[k].hostname then %>
110                                  / <a href="http://<%=hna[k].hostname%>/cgi-bin-status.html"><%=hna[k].hostname%></a>
111                                 <% end %>
112                         </td>
113                         <% if hna[k].validityTime then
114                                 validity = hna[k].validityTime .. 's'
115                         else
116                                 validity = '-'
117                         end %>
118
119                         <td class="cbi-section-table-cell"><%=validity%></td>
120                 </tr>
121
122                 <% i = ((i % 2) + 1)
123                 end %>
124                 </tbody>
125         </table>
126 </fieldset>
127
128 <%+status-olsr/common_js%>
129 <%+footer%>