neighbors.htm 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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">//<![CDATA[
  47. XHR.poll(10 , '<%=REQUEST_URI%>', { status: 1 },
  48. function(x, info)
  49. {
  50. var nt = document.getElementById('olsr_neigh_table');
  51. if (nt)
  52. {
  53. var s = '<div class="tr cbi-section-table-cell">' +
  54. '<div class="th cbi-section-table-cell"><%:Neighbour IP%></div>' +
  55. '<div class="th cbi-section-table-cell"><%:Hostname%></div>' +
  56. '<div class="th cbi-section-table-cell"><%:Interface%></div>' +
  57. '<div class="th cbi-section-table-cell"><%:Local interface IP%></div>' +
  58. '<div class="th cbi-section-table-cell">LQ</div>' +
  59. '<div class="th cbi-section-table-cell">NLQ</div>' +
  60. '<div class="th cbi-section-table-cell">ETX</div>' +
  61. '<div class="th cbi-section-table-cell">SNR</div>' +
  62. '</div>';
  63. for (var idx = 0; idx < info.length; idx++)
  64. {
  65. var neigh = info[idx];
  66. if (neigh.proto == '6') {
  67. s += String.format(
  68. '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
  69. '<div class="td cbi-section-table-cell left" style="background-color:%s"><a href="http://[%s]/cgi-bin-status.html">%s</a></div>',
  70. neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip
  71. );
  72. } else {
  73. s += String.format(
  74. '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-%s">' +
  75. '<div class="td cbi-section-table-cell left" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></div>',
  76. neigh.proto, neigh.dfgcolor, neigh.rip, neigh.rip
  77. );
  78. }
  79. if (neigh.hn) {
  80. s += String.format(
  81. '<div class="td cbi-section-table-cell left" style="background-color:%s"><a href="http://%s/cgi-bin-status.html">%s</a></div>',
  82. neigh.dfgcolor, neigh.hn, neigh.hn
  83. );
  84. } else {
  85. s += String.format(
  86. '<div class="td cbi-section-table-cell left" style="background-color:%s">?</div>',
  87. neigh.dfgcolor
  88. );
  89. }
  90. s += String.format(
  91. '<div class="td cbi-section-table-cell left" style="background-color:%s">%s</div>' +
  92. '<div class="td cbi-section-table-cell left" style="background-color:%s">%s</div>' +
  93. '<div class="td cbi-section-table-cell left" style="background-color:%s">%s</div>' +
  94. '<div class="td cbi-section-table-cell left" style="background-color:%s">%s</div>' +
  95. '<div class="td cbi-section-table-cell left" style="background-color:%s">%s</div>' +
  96. '<div class="td cbi-section-table-cell left" style="background-color:%s" title="Signal: %s Noise: %s">%s</div>' +
  97. '</div>',
  98. 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 || '?'
  99. );
  100. }
  101. nt.innerHTML = s;
  102. }
  103. }
  104. );
  105. //]]></script>
  106. <h2 name="content"><%:OLSR connections%></h2>
  107. <div id="togglebuttons"></div>
  108. <fieldset class="cbi-section">
  109. <legend><%:Overview of currently established OLSR connections%></legend>
  110. <div class="table cbi-section-table" id="olsr_neigh_table">
  111. <div class="tr cbi-section-table-cell">
  112. <div class="th cbi-section-table-cell"><%:Neighbour IP%></div>
  113. <div class="th cbi-section-table-cell"><%:Hostname%></div>
  114. <div class="th cbi-section-table-cell"><%:Interface%></div>
  115. <div class="th cbi-section-table-cell"><%:Local interface IP%></div>
  116. <div class="th cbi-section-table-cell">LQ</div>
  117. <div class="th cbi-section-table-cell">NLQ</div>
  118. <div class="th cbi-section-table-cell">ETX</div>
  119. <div class="th cbi-section-table-cell">SNR</div>
  120. </div>
  121. <% local i = 1
  122. for k, link in ipairs(links) do
  123. link.linkCost = tonumber(link.linkCost) or 0
  124. if link.linkCost == 4194304 then
  125. link.linkCost = 0
  126. end
  127. color = olsrtools.etx_color(link.linkCost)
  128. snr_color = olsrtools.snr_color(link.snr)
  129. if link.snr == 0 then
  130. link.snr = '?'
  131. end
  132. defaultgw_color = ""
  133. if link.defaultgw == 1 then
  134. defaultgw_color = "#ffff99"
  135. end
  136. %>
  137. <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=link.proto%>">
  138. <% if link.proto == "6" then %>
  139. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><a href="http://[<%=link.remoteIP%>]/cgi-bin-status.html"><%=link.remoteIP%></a></div>
  140. <% else %>
  141. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.remoteIP%>/cgi-bin-status.html"><%=link.remoteIP%></a></div>
  142. <% end %>
  143. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><a href="http://<%=link.hostname%>/cgi-bin-status.html"><%=link.hostname%></a></div>
  144. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><%=link.interface%></div>
  145. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><%=link.localIP%></div>
  146. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.linkQuality)%></div>
  147. <div class="td cbi-section-table-cell left" style="background-color:<%=defaultgw_color%>"><%=string.format("%.3f", link.neighborLinkQuality)%></div>
  148. <div class="td cbi-section-table-cell left" style="background-color:<%=color%>"><%=string.format("%.3f", link.linkCost)%></div>
  149. <div class="td cbi-section-table-cell left" style="background-color:<%=snr_color%>" title="Signal: <%=link.signal%> Noise: <%=link.noise%>"><%=link.snr%></div>
  150. </div>
  151. <%
  152. i = ((i % 2) + 1)
  153. end %>
  154. </div>
  155. <br />
  156. <%+status-olsr/legend%>
  157. </fieldset>
  158. <%+status-olsr/common_js%>
  159. <%+footer%>