c75b94fceffed0251317dc96b5f326b858b197da
[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 '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
54 '<div class="td cbi-section-table-cell">%s/%s</div>' +
55 '<div class="td 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 '</div>' +
76 '<div class="td cbi-section-table-cell">%s</div>' +
77 '<div class="td cbi-section-table-cell">%s</div>' +
78 '<div class="td cbi-section-table-cell" style="background-color:%s">%s</div>' +
79 '</div>',
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 <div class="table cbi-section-table">
100 <div class="thead">
101 <div class="tr cbi-section-table-titles">
102 <div class="th cbi-section-table-cell"><%:Announced network%></div>
103 <div class="th cbi-section-table-cell"><%:OLSR gateway%></div>
104 <div class="th cbi-section-table-cell"><%:Interface%></div>
105 <div class="th cbi-section-table-cell"><%:Metric%></div>
106 <div class="th cbi-section-table-cell">ETX</div>
107 </div>
108 </div>
109
110 <div class="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 <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=route.proto%>">
118 <div class="td cbi-section-table-cell"><%=route.destination%>/<%=route.genmask%></div>
119 <div class="td 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 </div>
129 <div class="td cbi-section-table-cell"><%=route.networkInterface%></div>
130 <div class="td cbi-section-table-cell"><%=route.metric%></div>
131 <div class="td cbi-section-table-cell" style="background-color:<%=color%>"><%=string.format("%.3f", ETX)%></div>
132 </div>
133 <%
134 i = ((i % 2) + 1)
135 end %>
136 </div>
137 </div>
138
139 <%+status-olsr/legend%>
140 </fieldset>
141 <%+status-olsr/common_js%>
142 <%+footer%>