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