routes.htm 4.4 KB

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