e32b696d58a82a992bd52a3bad9cc4b31d6de52a
[project/luci.git] / applications / luci-olsr / luasrc / view / status-olsr / routes.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, route in ipairs(routes) do
22                 rv[#rv+1] = {
23                         hostname = route.Hostname,
24                         dest = route.Destination,
25                         gw = route["Gateway IP"],
26                         interface = route.Interface,
27                         metric = route.Metric,
28                         etx = tonumber(route.ETX),
29                         color = olsrtools.etx_color(tonumber(route.ETX)),
30                 }
31         end
32         luci.http.prepare_content("application/json")
33         luci.http.write_json(rv)
34         return
35 end
36
37 %>
38
39 <%+header%>
40
41 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
42 <script type="text/javascript">//<![CDATA[  
43
44 XHR.poll(20, '<%=REQUEST_URI%>', { status: 1 },
45                 function(x, info)
46                 {
47
48                 var rt = document.getElementById('olsrd_routes');
49                         if (rt)
50                         {
51                                 var s = '';
52                                 for (var idx = 0; idx < info.length; idx++)
53                                 {
54                                         var route = info[idx];
55
56                                         s += String.format(
57                                                 '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+'">' +
58                                                         '<td class="cbi-section-table-cell">%s</td>' +
59                                                         '<td class="cbi-section-table-cell">' +
60                                                                 '<a href="http://%s/cgi-bin-status.html">%s</a>',
61                                                                 route.dest, route.gw, route.gw
62                                                 )
63
64                                         if (route.hostname)
65                                                 {
66                                                 s += String.format(
67                                                                 ' / <a href="http://%s/cgi-bin-status.html">%s</a>',
68                                                                 route.hostname, route.hostname || '?'
69                                                                 );
70                                                 }
71                                         s += String.format(
72                                                         '</td>' +
73                                                         '<td class="cbi-section-table-cell">%s</td>' +
74                                                         '<td class="cbi-section-table-cell">%s</td>' +
75                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
76                                                 '</tr>',
77                                                 route.interface, route.metric, route.color, route.etx || '?'
78                                         );
79                                 }
80                         }
81                          rt.innerHTML = s;
82
83                 }
84         );
85 //]]></script>
86
87
88
89 <h2><a id="content" name="content"><%:Known OLSR routes%></a></h2>
90
91 <fieldset class="cbi-section">
92 <legend><%:Overview of currently known routes to other OLSR nodes%></legend>
93
94 <table class="cbi-section-table">
95         <thead>
96                 <tr class="cbi-section-table-titles">
97                         <th class="cbi-section-table-cell"><%:Announced network%></th>
98                         <th class="cbi-section-table-cell"><%:OLSR gateway%></th>
99                         <th class="cbi-section-table-cell"><%:Interface%></th>
100                         <th class="cbi-section-table-cell"><%:Metric%></th>
101                         <th class="cbi-section-table-cell">ETX</th>
102                 </tr>
103         </thead>
104
105         <tbody id="olsrd_routes">
106
107         <% for k, route in ipairs(routes) do
108                 color = olsrtools.etx_color(tonumber(route.ETX))
109         %>
110
111                 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%>">
112                         <td class="cbi-section-table-cell"><%=route.Destination%></td>
113                         <td class="cbi-section-table-cell">
114                                 <a href="http://<%=route["Gateway IP"]%>/cgi-bin-status.html"><%=route["Gateway IP"]%></a>
115                                 <% if route.Hostname then %>
116                                         / <a href="http://<%=route.Hostname%>/cgi-bin-status.html"><%=route.Hostname%></a>  
117                                 <% end %>
118                         </td>
119                         <td class="cbi-section-table-cell"><%=route.Interface%></td>
120                         <td class="cbi-section-table-cell"><%=route.Metric%></td>
121                         <td class="cbi-section-table-cell" style="background-color:<%=color%>"><%=string.format("%.3f", tonumber(route.ETX) or 0)%></td>
122                 </tr>
123         <% 
124                 i = ((i % 2) + 1)
125         end %>
126         </tbody>
127 </table>
128
129 </fieldset>
130 <%+footer%>