1
0

smartgw.htm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 i = 1
  9. require("luci.model.uci")
  10. local uci = luci.model.uci.cursor_state()
  11. uci:foreach("olsrd", "olsrd", function(s)
  12. if s.SmartGateway and s.SmartGateway == "yes" then has_smartgw = true end
  13. end)
  14. if luci.http.formvalue("status") == "1" then
  15. local rv = {}
  16. for k, gw in ipairs(gws) do
  17. gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0
  18. if gw.tcPathCost == 4096 then
  19. gw.tcPathCost = 0
  20. end
  21. rv[#rv+1] = {
  22. proto = gw.proto,
  23. ipAddress = gw.ipAddress,
  24. status = gw.ipv4Status or gw.ipv6Status,
  25. tcPathCost = string.format("%.3f", gw.tcPathCost),
  26. hopCount = gw.hopCount,
  27. uplinkSpeed = gw.uplinkSpeed,
  28. downlinkSpeed = gw.downlinkSpeed,
  29. v4 = gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no'),
  30. v6 = gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no'),
  31. externalPrefix = gw.externalPrefix
  32. }
  33. end
  34. luci.http.prepare_content("application/json")
  35. luci.http.write_json(rv)
  36. return
  37. end
  38. %>
  39. <%+header%>
  40. <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
  41. <script type="text/javascript">//<![CDATA[
  42. XHR.poll(10, '<%=REQUEST_URI%>', { status: 1 },
  43. function(x, info)
  44. {
  45. var smartgwdiv = document.getElementById('olsrd_smartgw');
  46. if (smartgwdiv)
  47. {
  48. var s = '';
  49. for (var idx = 0; idx < info.length; idx++)
  50. {
  51. var smartgw = info[idx];
  52. s += '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + smartgw.proto + '">'
  53. if (smartgw.proto == '6') {
  54. linkgw = '<a href="http://[' + smartgw.ipAddress + ']/cgi-bin-status.html">' + smartgw.ipAddress + '</a>'
  55. } else {
  56. linkgw = '<a href="http://' + smartgw.ipAddress + '/cgi-bin-status.html">' + smartgw.ipAddress + '</a>'
  57. }
  58. s += String.format(
  59. '<td class="cbi-section-table-cell">%s</td>' +
  60. '<td class="cbi-section-table-cell">%s</td>' +
  61. '<td class="cbi-section-table-cell">%s</td>' +
  62. '<td class="cbi-section-table-cell">%s</td>' +
  63. '<td class="cbi-section-table-cell">%s</td>' +
  64. '<td class="cbi-section-table-cell">%s</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">%s</td>',
  68. linkgw, smartgw.status, smartgw.tcPathCost, smartgw.hopCount, smartgw.uplinkSpeed, smartgw.downlinkSpeed, smartgw.v4, smartgw.v6, smartgw.externalPrefix
  69. )
  70. s += '</tr>'
  71. }
  72. smartgwdiv.innerHTML = s;
  73. }
  74. }
  75. );
  76. //]]></script>
  77. <%+header%>
  78. <h2 name="content"><%:SmartGW announcements%></h2>
  79. <div id="togglebuttons"></div>
  80. <% if has_smartgw then %>
  81. <fieldset class="cbi-section">
  82. <legend><%:Overview of smart gateways in this network%></legend>
  83. <table class="cbi-section-table">
  84. <thead>
  85. <tr class="cbi-section-table-titles">
  86. <th class="cbi-section-table-cell"><%:Gateway%></th>
  87. <th class="cbi-section-table-cell"><%:Status%></th>
  88. <th class="cbi-section-table-cell"><%:ETX%></th>
  89. <th class="cbi-section-table-cell"><%:Hops%></th>
  90. <th class="cbi-section-table-cell"><%:Uplink%></th>
  91. <th class="cbi-section-table-cell"><%:Downlink%></th>
  92. <th class="cbi-section-table-cell"><%:IPv4%></th>
  93. <th class="cbi-section-table-cell"><%:IPv6%></th>
  94. <th class="cbi-section-table-cell"><%:Prefix%></th>
  95. </tr>
  96. </thead>
  97. <tbody id="olsrd_smartgw">
  98. <% for k, gw in ipairs(gws) do
  99. gw.tcPathCost = tonumber(gw.tcPathCost)/1024 or 0
  100. if gw.tcPathCost == 4096 then
  101. gw.tcPathCost = 0
  102. end
  103. %>
  104. <tr class="cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=proto%>">
  105. <% if gw.proto == '6' then %>
  106. <td class="cbi-section-table-cell"><a href="http://[<%=gw.ipAddress%>]/cgi-bin-status.html"><%=gw.ipAddress%></a></td>
  107. <% else %>
  108. <td class="cbi-section-table-cell"><a href="http://<%=gw.ipAddress%>/cgi-bin-status.html"><%=gw.ipAddress%></a></td>
  109. <% end %>
  110. <td class="cbi-section-table-cell"><%=gw.ipv4Status or gw.ipv6Status or '-' %></td>
  111. <td class="cbi-section-table-cell"><%=string.format("%.3f", gw.tcPathCost)%></td>
  112. <td class="cbi-section-table-cell"><%=gw.hopCount%></td>
  113. <td class="cbi-section-table-cell"><%=gw.uplinkSpeed%></td>
  114. <td class="cbi-section-table-cell"><%=gw.downlinkSpeed%></td>
  115. <td class="cbi-section-table-cell"><%=gw.ipv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></td>
  116. <td class="cbi-section-table-cell"><%=gw.ipv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></td>
  117. <td class="cbi-section-table-cell"><%=gw.externalPrefix%></td>
  118. </tr>
  119. <% i = ((i % 2) + 1)
  120. end %>
  121. </tbody>
  122. </table>
  123. </fieldset>
  124. <% else %>
  125. <%:SmartGateway is not configured on this system.%>
  126. <% end %>
  127. <%+status-olsr/common_js%>
  128. <%+footer%>