applications/luci-olsr: Update all statuspages; use json reloading on overview, neigh...
[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
18 if luci.http.formvalue("status") == "1" then
19         local rv = {}
20         local i = 1
21
22         for k, link in ipairs(links) do
23                 link.Cost = tonumber(link.Cost) or 0
24                 local color = olsrtools.etx_color(link.Cost)
25                 defaultgw_color = ""
26                 if link.defaultgw == 1 then
27                         defaultgw_color = "#ffff99"
28                 end
29
30                 rv[#rv+1] = {
31                         rip = link["Remote IP"],
32                         hn = link["Hostname"],
33                         lip = link["Local IP"],
34                         dev = link["Local Device"],
35                         lq = link.LQ,
36                         nlq = link.NLQ,
37                         cost = string.format("%.3f", link.Cost),
38                         color = color,
39                         rs = i,
40                         dfgcolor = defaultgw_color
41                         }
42                         if i == 1 then i = 0 elseif i == 0 then i = 1 end
43         end
44         luci.http.prepare_content("application/json")
45         luci.http.write_json(rv)
46         return
47 end
48 %>
49
50 <%+header%>
51
52 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
53 <script type="text/javascript">//<![CDATA[
54
55         XHR.poll(10 , '<%=REQUEST_URI%>', { status: 1 }, 
56                 function(x, info)
57                 {
58                 var nt = document.getElementById('olsr_neigh_table');
59                         if (nt)
60                         {
61                                 var s = '';
62                                 for (var idx = 0; idx < info.length; idx++)
63                                 {
64                                         var neigh = info[idx];
65
66                                         s += String.format(
67                                                 '<tr class="cbi-section-table-row cbi-rowstyle-%s">' +
68                                                         '<td class="cbi-section-table-cell" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>',
69                                                 neigh.rs, neigh.dfgcolor, neigh.rip, neigh.rip
70                                                 );
71                                         if (neigh.hn) {
72                                                 s += String.format(                                     
73                                                         '<td class="cbi-section-table-cell" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>',
74                                                         neigh.dfgcolor, neigh.hn, neigh.hn
75                                                         );
76                                                 }
77                                         else    {
78                                                 s += String.format(
79                                                         '<td class="cbi-section-table-cell" style="background-color:%s">?</td>',
80                                                         neigh.dfgcolor
81                                                         );
82                                                 }
83                                         s += String.format(
84                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
85                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
86                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
87                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
88                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
89                                                 '</tr>',
90                                                         
91                                                         neigh.dfgcolor, neigh.lip, neigh.dfgcolor, neigh.dev, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost || '?'
92                                                 );
93                                 }
94
95                                 nt.innerHTML = s;
96                         }
97                 }
98         );
99 //]]></script>
100
101
102 <h2><a id="content" name="content"><%:OLSR connections%></a></h2>
103
104 <fieldset class="cbi-section">
105         <legend><%:Overview of currently established OLSR connections%></legend>
106
107         <table class="cbi-section-table">
108                 <tr class="cbi-section-table-titles">
109                         <th class="cbi-section-table-cell"><%:Neighbour IP%></th>
110                         <th class="cbi-section-table-cell"><%:Hostname%></th>
111                         <th class="cbi-section-table-cell"><%:Local interface IP%></th>
112                         <th class="cbi-section-table-cell"><%:Device%></th>
113                         <th class="cbi-section-table-cell">LQ</th>
114                         <th class="cbi-section-table-cell">NLQ</th>
115                         <th class="cbi-section-table-cell">ETX</th>
116                 </tr>
117
118         
119                 <tbody id="olsr_neigh_table">
120                 <%      local i = 1
121                         for k, link in ipairs(links) do
122                         link.Cost = tonumber(link.Cost) or 0
123                         color = olsrtools.etx_color(link.Cost)
124
125                         defaultgw_color = ""
126                         if link.defaultgw == 1 then
127                                 defaultgw_color = "#ffff99"
128                         end
129                 %>
130
131                 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%>">
132                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link["Remote IP"]%>/cgi-bin-status.html"><%=link["Remote IP"]%></a></td>
133                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link["Hostname"]%>/cgi-bin-status.html"><%=link["Hostname"]%></a></td>
134                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=link["Local IP"]%></td>
135                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=link["Local Device"]%></td>
136                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=link.LQ%></td>
137                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=link.NLQ%></td>
138                         <td class="cbi-section-table-cell" style="background-color:<%=color%>"><%=string.format("%.3f", link.Cost)%></td>
139                 </tr>
140                 <% 
141                         if i == 1 then i = 0 elseif i == 0 then i = 1 end
142                 end %>
143                 </tbody>
144         </table>
145 <br />
146
147 <h3><%:Legend%>:</h3>
148 <ul>
149         <li><strong>LQ: </strong><%:Success rate of packages received from the neighbour%></li>
150         <li><strong>NLQ: </strong><%:Success rate of packages sent to the neighbour%></li>
151         <li><strong>ETX: </strong><%:Expected retransmission count%></li>
152 </ul>
153 </fieldset>
154 <%+footer%>