neighbors.htm 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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, link in ipairs(links) do
  13. link.linkCost = tonumber(link.linkCost) or 0
  14. if link.linkCost == 4194304 then
  15. link.linkCost = 0
  16. end
  17. local color = olsrtools.etx_color(link.linkCost)
  18. local snr_color = olsrtools.snr_color(link.snr)
  19. defaultgw_color = ""
  20. if link.defaultgw == 1 then
  21. defaultgw_color = "#ffff99"
  22. end
  23. rv[#rv+1] = {
  24. rip = link.remoteIP,
  25. hn = link.hostname,
  26. lip = link.localIP,
  27. ifn = link.interface,
  28. lq = string.format("%.3f", link.linkQuality),
  29. nlq = string.format("%.3f",link.neighborLinkQuality),
  30. cost = string.format("%.3f", link.linkCost),
  31. snr = link.snr,
  32. signal = link.signal,
  33. noise = link.noise,
  34. color = color,
  35. snr_color = snr_color,
  36. dfgcolor = defaultgw_color,
  37. proto = link.proto
  38. }
  39. end
  40. luci.http.prepare_content("application/json")
  41. luci.http.write_json(rv)
  42. return
  43. end
  44. %>
  45. <%+header%>
  46. <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
  47. <script type="text/javascript">//<![CDATA[
  48. XHR.poll(10 , '<%=REQUEST_URI%>', { status: 1 },
  49. function(x, info)
  50. {
  51. var nt = document.getElementById('olsr_neigh_table');
  52. if (nt)
  53. {
  54. var s = '';
  55. for (var idx = 0; idx < info.length; idx++)
  56. {
  57. var neigh = info[idx];
  58. if (neigh.proto == '6') {
  59. s += String.format(
  60. '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
  61. '<td class="cbi-section-table-titles" style="background-color:%s"><a href="http://[%s]/cgi-bin-status.html">%s</a></td>',
  62. neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip
  63. );
  64. } else {
  65. s += String.format(
  66. '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
  67. '<td class="cbi-section-table-titles" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>',
  68. neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip
  69. );
  70. }
  71. if (neigh.hn) {
  72. s += String.format(
  73. '<td class="cbi-section-table-titles" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></td>',
  74. neigh.dfgcolor, neigh.hn, neigh.hn
  75. );
  76. } else {
  77. s += String.format(
  78. '<td class="cbi-section-table-titles" style="background-color:%s">?</td>',
  79. neigh.dfgcolor
  80. );
  81. }
  82. s += String.format(
  83. '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
  84. '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
  85. '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
  86. '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
  87. '<td class="cbi-section-table-titles" style="background-color:%s">%s</td>' +
  88. '<td class="cbi-section-table-titles" style="background-color:%s" title="Signal: %s Noise: %s">%s</td>' +
  89. '</tr>',
  90. neigh.dfgcolor, neigh.ifn, neigh.dfgcolor, neigh.lip, neigh.dfgcolor, neigh.lq, neigh.dfgcolor, neigh.nlq, neigh.color, neigh.cost, neigh.snr_color, neigh.signal, neigh.noise, neigh.snr || '?'
  91. );
  92. }
  93. nt.innerHTML = s;
  94. }
  95. }
  96. );
  97. //]]></script>
  98. <h2 name="content"><%:OLSR connections%></h2>
  99. <div id="togglebuttons"></div>
  100. <fieldset class="cbi-section">
  101. <legend><%:Overview of currently established OLSR connections%></legend>
  102. <table class="cbi-section-table">
  103. <thead>
  104. <tr class="cbi-section-table-titles">
  105. <th class="cbi-section-table-cell"><%:Neighbour IP%></th>
  106. <th class="cbi-section-table-cell"><%:Hostname%></th>
  107. <th class="cbi-section-table-cell"><%:Interface%></th>
  108. <th class="cbi-section-table-cell"><%:Local interface IP%></th>
  109. <th class="cbi-section-table-cell">LQ</th>
  110. <th class="cbi-section-table-cell">NLQ</th>
  111. <th class="cbi-section-table-cell">ETX</th>
  112. <th class="cbi-section-table-cell">SNR</th>
  113. </tr>
  114. </thead>
  115. <tbody id="olsr_neigh_table">
  116. <% local i = 1
  117. for k, link in ipairs(links) do
  118. link.linkCost = tonumber(link.linkCost) or 0
  119. if link.linkCost == 4194304 then
  120. link.linkCost = 0
  121. end
  122. color = olsrtools.etx_color(link.linkCost)
  123. snr_color = olsrtools.snr_color(link.snr)
  124. if link.snr == 0 then
  125. link.snr = '?'
  126. end
  127. defaultgw_color = ""
  128. if link.defaultgw == 1 then
  129. defaultgw_color = "#ffff99"
  130. end
  131. %>
  132. <tr class="cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=link.proto%>">
  133. <% if link.proto == "6" then %>
  134. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><a href="http://[<%=link.remoteIP%>]/cgi-bin-status.html"><%=link.remoteIP%></a></td>
  135. <% else %>
  136. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.remoteIP%>/cgi-bin-status.html"><%=link.remoteIP%></a></td>
  137. <% end %>
  138. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.hostname%>/cgi-bin-status.html"><%=link.hostname%></a></td>
  139. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=link.interface%></td>
  140. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=link.localIP%></td>
  141. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.linkQuality)%></td>
  142. <td class="cbi-section-table-titles" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.neighborLinkQuality)%></td>
  143. <td class="cbi-section-table-titles" style="background-color:<%=color%>"><%=string.format("%.3f", link.linkCost)%></td>
  144. <td class="cbi-section-table-titles" style="background-color:<%=snr_color%>" title="Signal: <%=link.signal%> Noise: <%=link.noise%>"><%=link.snr%></td>
  145. </tr>
  146. <%
  147. i = ((i % 2) + 1)
  148. end %>
  149. </tbody>
  150. </table>
  151. <br />
  152. <%+status-olsr/legend%>
  153. </fieldset>
  154. <%+status-olsr/common_js%>
  155. <%+footer%>