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