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