4d84241fbd2d5c4132a9b2c78e06b440a5e07420
[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                         hn = link.hostname,
35                         lip = link.localIP,
36                         lq = string.format("%.3f", link.linkQuality),
37                         nlq = string.format("%.3f",link.neighborLinkQuality),
38                         cost = string.format("%.3f", link.linkCost),
39                         color = color,
40                         dfgcolor = defaultgw_color,
41                         proto = link.proto
42                         }
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                                         if (neigh.proto == '6') {
67                                                 s += String.format(
68                                                         '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
69                                                                 '<td class="cbi-section-table-cell" style="background-color:%s"><a href="http://[%s]/cgi-bin-status.html">%s</a></td>',
70                                                         neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip
71                                                         );
72                                         } else {
73                                                 s += String.format(
74                                                         '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
75                                                                 '<td class="cbi-section-table-cell" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>',
76                                                         neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip
77                                                         );
78                                         }
79                                         if (neigh.hn) {
80                                                 s += String.format(                                     
81                                                         '<td class="cbi-section-table-cell" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>',
82                                                         neigh.dfgcolor, neigh.hn, neigh.hn
83                                                         );
84                                                 }
85                                         else    {
86                                                 s += String.format(
87                                                         '<td class="cbi-section-table-cell" style="background-color:%s">?</td>',
88                                                         neigh.dfgcolor
89                                                         );
90                                                 }
91                                         s += String.format(
92                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
93                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
94                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
95                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
96                                                 '</tr>',
97                                                         
98                                                         neigh.dfgcolor, neigh.lip, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost || '?'
99                                                 );
100                                 }
101
102                                 nt.innerHTML = s;
103                         }
104                 }
105         );
106 //]]></script>
107
108
109 <h2><a id="content" name="content"><%:OLSR connections%></a></h2>
110
111 <div id="togglebuttons"></div>
112
113 <fieldset class="cbi-section">
114         <legend><%:Overview of currently established OLSR connections%></legend>
115
116         <table class="cbi-section-table">
117                 <thead>
118                         <tr class="cbi-section-table-titles">
119                                 <th class="cbi-section-table-cell"><%:Neighbour IP%></th>
120                                 <th class="cbi-section-table-cell"><%:Hostname%></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                         </tr>
126                 </thead>
127         
128                 <tbody id="olsr_neigh_table">
129                 <%      local i = 1
130                         for k, link in ipairs(links) do
131                         link.linkCost = tonumber(link.linkCost)/1024 or 0
132                         if link.linkCost == 4096 then
133                                 link.linkCost = 0
134                         end
135
136                         color = olsrtools.etx_color(link.linkCost)
137
138                         defaultgw_color = ""
139                         if link.defaultgw == 1 then
140                                 defaultgw_color = "#ffff99"
141                         end
142                 %>
143
144                 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=link.proto%>">
145                         <% if link.proto == "6" then %>
146                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><a href="http://[<%=link.remoteIP%>]/cgi-bin-status.html"><%=link.remoteIP%></a></td>
147                         <% else %>
148                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.remoteIP%>/cgi-bin-status.html"><%=link.remoteIP%></a></td>
149                         <% end %>
150                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.hostname%>/cgi-bin-status.html"><%=link.hostname%></a></td>
151                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=link.localIP%></td>
152                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.linkQuality)%></td>
153                         <td class="cbi-section-table-cell" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.neighborLinkQuality)%></td>
154                         <td class="cbi-section-table-cell" style="background-color:<%=color%>"><%=string.format("%.3f", link.linkCost)%></td>
155                 </tr>
156                 <% 
157                         i = ((i % 2) + 1)
158                 end %>
159                 </tbody>
160         </table>
161 <br />
162
163 <%+status-olsr/legend%>
164 </fieldset>
165 <%+status-olsr/common_js%>
166 <%+footer%>