1
0

routes.htm 4.0 KB

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