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