luci-olsr: add interface and wifi stats to public olsr-neighb site
[project/luci.git] / applications / luci-olsr / luasrc / view / status-olsr / neighbors.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 olsrtools = require "luci.tools.olsr"
17 local i = 1
18
19 if luci.http.formvalue("status") == "1" then
20         local rv = {}
21         for k, link in ipairs(links) do
22                 link.linkCost = tonumber(link.linkCost)/1024 or 0
23                 if link.linkCost == 4096 then
24                         link.linkCost = 0
25                 end
26                 local color = olsrtools.etx_color(link.linkCost)
27                 defaultgw_color = ""
28                 if link.defaultgw == 1 then
29                         defaultgw_color = "#ffff99"
30                 end
31
32                 rv[#rv+1] = {
33                         rip = link.remoteIP,
34                         rmac = link.remoteMAC,
35                         hn = link.hostname,
36                         lip = link.localIP,
37                         lmac = link.localMAC,
38                         ifn = link.interface,
39                         lq = string.format("%.3f", link.linkQuality),
40                         nlq = string.format("%.3f",link.neighborLinkQuality),
41                         cost = string.format("%.3f", link.linkCost),
42                         snr = string.format("%.3f", link.snr),
43                         signal = string.format("%.3f", link.signal),
44                         noise = string.format("%.3f", link.noise),
45                         color = color,
46                         dfgcolor = defaultgw_color,
47                         proto = link.proto
48                         }
49         end
50         luci.http.prepare_content("application/json")
51         luci.http.write_json(rv)
52         return
53 end
54 %>
55
56 <%+header%>
57
58 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
59 <script type="text/javascript">//<![CDATA[
60
61         XHR.poll(10 , '<%=REQUEST_URI%>', { status: 1 }, 
62                 function(x, info)
63                 {
64                 var nt = document.getElementById('olsr_neigh_table');
65                         if (nt)
66                         {
67                                 var s = '';
68                                 for (var idx = 0; idx < info.length; idx++)
69                                 {
70                                         var neigh = info[idx];
71
72                                         if (neigh.proto == '6') {
73                                                 s += String.format(
74                                                         '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
75                                                         '<td class="cbi-section-table-titles" style="background-color:%s"><a href="http://[%s]/cgi-bin-status.html">%s/%s</a></td>',
76                                                         neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip, neigh.rmac
77                                                         );
78                                         } else {
79                                                 s += String.format(
80                                                         '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
81                                                         '<td class="cbi-section-table-titles" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s/%s</a></td>',
82                                                         neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip, neigh.rmac
83                                                         );
84                                         }
85                                         if (neigh.hn) {
86                                                 s += String.format(
87                                                         '<td class="cbi-section-table-titles" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>' +
88                                                         neigh.dfgcolor, neigh.hn, neigh.hn
89                                                         );
90                                                 }
91                                         else    {
92                                                 s += String.format(
93                                                         '<td class="cbi-section-table-titles" style="background-color:%s">?</td>',
94                                                         neigh.dfgcolor
95                                                         );
96                                                 }
97                                         s += String.format(
98                                                         '<td class="cbi-section-table-titles" style="background-color:%s">%s/%s/%s</td>' +
99                                                         '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
100                                                         '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
101                                                         '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
102                                                         '<td class="cbi-section-table-titles" style="background-color:%s" title="Signal: %s Noise: %s">%s</td>' +
103                                                         '</tr>',
104                                                         neigh.dfgcolor, neigh.ifn, neigh.lip, neigh.lmac, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost, neigh.color, neigh.signal, neigh.noise, neigh.snr || '?'
105                                                 );
106                                 }
107
108                                 nt.innerHTML = s;
109                         }
110                 }
111         );
112 //]]></script>
113
114
115 <h2><a id="content" name="content"><%:OLSR connections%></a></h2>
116
117 <div id="togglebuttons"></div>
118
119 <fieldset class="cbi-section">
120         <legend><%:Overview of currently established OLSR connections%></legend>
121
122         <table class="cbi-section-table">
123                 <thead>
124                         <tr class="cbi-section-table-titles">
125                                 <th class="cbi-section-table-cell"><%:Neighbour IP%></th>
126                                 <th class="cbi-section-table-cell"><%:Hostname%></th>
127                                 <th class="cbi-section-table-cell"><%:Local interface IP%></th>
128                                 <th class="cbi-section-table-cell">LQ</th>
129                                 <th class="cbi-section-table-cell">NLQ</th>
130                                 <th class="cbi-section-table-cell">ETX</th>
131                                 <th class="cbi-section-table-cell">SNR</th>
132                         </tr>
133                 </thead>
134         
135                 <tbody id="olsr_neigh_table">
136                 <%      local i = 1
137                         for k, link in ipairs(links) do
138                         link.linkCost = tonumber(link.linkCost)/1024 or 0
139                         if link.linkCost == 4096 then
140                                 link.linkCost = 0
141                         end
142
143                         color = olsrtools.etx_color(link.linkCost)
144
145                         defaultgw_color = ""
146                         if link.defaultgw == 1 then
147                                 defaultgw_color = "#ffff99"
148                         end
149                 %>
150
151                 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=link.proto%>">
152                         <% if link.proto == "6" then %>
153                         <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><a href="http://[<%=link.remoteIP%>]/cgi-bin-status.html"><%=link.remoteIP%>/<%=link.remoteMAC%></a></td>
154                         <% else %>
155                         <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.remoteIP%>/cgi-bin-status.html"><%=link.remoteIP%>/<%=link.remoteMAC%></a></td>
156                         <% end %>
157                         <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.hostname%>/cgi-bin-status.html"><%=link.hostname%></a></td>
158                         <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=link.interface%>/<%=link.localIP%>/<%=link.localMAC%></td>
159                         <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.linkQuality)%></td>
160                         <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.neighborLinkQuality)%></td>
161                         <td class="cbi-section-table-titles" style="background-color:<%=color%>"><%=string.format("%.3f", link.linkCost)%></td>
162                         <td class="cbi-section-table-titles" style="background-color:<%=color%>" title="Signal: <%=string.format("%.3f", link.signal)%> Noise: <%=string.format("%.3f", link.noise)%>"><%=string.format("%.3f", link.snr)%></td>
163                 </tr>
164                 <% 
165                         i = ((i % 2) + 1)
166                 end %>
167                 </tbody>
168         </table>
169 <br />
170
171 <%+status-olsr/legend%>
172 </fieldset>
173 <%+status-olsr/common_js%>
174 <%+footer%>