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