2
0

smartgw.htm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.ipv4, gws.ipv6) do
  17. gw.cost = tonumber(gw.cost)/1024 or 0
  18. if gw.cost >= 100 then
  19. gw.cost = 0
  20. end
  21. rv[#rv+1] = {
  22. proto = gw.IPv4 and '4' or '6',
  23. originator = gw.originator,
  24. selected = gw.selected and luci.i18n.translate('yes') or luci.i18n.translate('no'),
  25. cost = gw.cost > 0 and string.format("%.3f", gw.cost) or luci.i18n.translate('infinite'),
  26. hops = gw.hops,
  27. uplink = gw.uplink,
  28. downlink = gw.downlink,
  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. prefix = gw.prefix
  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">//<![CDATA[
  41. XHR.poll(10, '<%=REQUEST_URI%>', { status: 1 },
  42. function(x, info)
  43. {
  44. var smartgwdiv = document.getElementById('olsrd_smartgw');
  45. if (smartgwdiv)
  46. {
  47. var s = '<div class="tr cbi-section-table-titles">' +
  48. '<div class="th cbi-section-table-cell"><%:Gateway%></div>' +
  49. '<div class="th cbi-section-table-cell"><%:Selected%></div>' +
  50. '<div class="th cbi-section-table-cell"><%:ETX%></div>' +
  51. '<div class="th cbi-section-table-cell"><%:Hops%></div>' +
  52. '<div class="th cbi-section-table-cell"><%:Uplink%></div>' +
  53. '<div class="th cbi-section-table-cell"><%:Downlink%></div>' +
  54. '<div class="th cbi-section-table-cell"><%:IPv4%></div>' +
  55. '<div class="th cbi-section-table-cell"><%:IPv6%></div>' +
  56. '<div class="th cbi-section-table-cell"><%:Prefix%></div>' +
  57. '</div>';
  58. for (var idx = 0; idx < info.length; idx++)
  59. {
  60. var smartgw = info[idx];
  61. var linkgw;
  62. s += '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + smartgw.proto + '">'
  63. if (smartgw.proto == '6') {
  64. linkgw = '<a href="http://[' + smartgw.originator + ']/cgi-bin-status.html">' + smartgw.originator + '</a>'
  65. } else {
  66. linkgw = '<a href="http://' + smartgw.originator + '/cgi-bin-status.html">' + smartgw.originator + '</a>'
  67. }
  68. s += String.format(
  69. '<div class="td cbi-section-table-cell left">%s</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">%s</div>' +
  73. '<div class="td cbi-section-table-cell left">%s</div>' +
  74. '<div class="td cbi-section-table-cell left">%s</div>' +
  75. '<div class="td cbi-section-table-cell left">%s</div>' +
  76. '<div class="td cbi-section-table-cell left">%s</div>' +
  77. '<div class="td cbi-section-table-cell left">%s</div>',
  78. linkgw, smartgw.selected, smartgw.cost, smartgw.hops, smartgw.uplink, smartgw.downlink, smartgw.v4, smartgw.v6, smartgw.prefix
  79. )
  80. s += '</div>'
  81. }
  82. smartgwdiv.innerHTML = s;
  83. }
  84. }
  85. );
  86. //]]></script>
  87. <h2 name="content"><%:SmartGW announcements%></h2>
  88. <div id="togglebuttons"></div>
  89. <% if has_smartgw then %>
  90. <fieldset class="cbi-section">
  91. <legend><%:Overview of smart gateways in this network%></legend>
  92. <div class="table cbi-section-table" id="olsrd_smartgw">
  93. <div class="tr cbi-section-table-titles">
  94. <div class="th cbi-section-table-cell"><%:Gateway%></div>
  95. <div class="th cbi-section-table-cell"><%:Selected%></div>
  96. <div class="th cbi-section-table-cell"><%:ETX%></div>
  97. <div class="th cbi-section-table-cell"><%:Hops%></div>
  98. <div class="th cbi-section-table-cell"><%:Uplink%></div>
  99. <div class="th cbi-section-table-cell"><%:Downlink%></div>
  100. <div class="th cbi-section-table-cell"><%:IPv4%></div>
  101. <div class="th cbi-section-table-cell"><%:IPv6%></div>
  102. <div class="th cbi-section-table-cell"><%:Prefix%></div>
  103. </div>
  104. <% for k, gw in ipairs(gws.ipv4, gws.ipv6) do
  105. gw.cost = tonumber(gw.cost)/1024 or 0
  106. if gw.cost >= 100 then
  107. gw.cost = 0
  108. end
  109. %>
  110. <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=proto%>">
  111. <% if gw.proto == '6' then %>
  112. <div class="td cbi-section-table-cell left"><a href="http://[<%=gw.originator%>]/cgi-bin-status.html"><%=gw.originator%></a></div>
  113. <% else %>
  114. <div class="td cbi-section-table-cell left"><a href="http://<%=gw.originator%>/cgi-bin-status.html"><%=gw.originator%></a></div>
  115. <% end %>
  116. <div class="td cbi-section-table-cell left"><%=gw.selected and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
  117. <div class="td cbi-section-table-cell left"><%=gw.cost > 0 and string.format("%.3f", gw.cost) or luci.i18n.translate('infinite')%></div>
  118. <div class="td cbi-section-table-cell left"><%=gw.hops%></div>
  119. <div class="td cbi-section-table-cell left"><%=gw.uplink%></div>
  120. <div class="td cbi-section-table-cell left"><%=gw.downlink%></div>
  121. <div class="td cbi-section-table-cell left"><%=gw.IPv4 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
  122. <div class="td cbi-section-table-cell left"><%=gw.IPv6 and luci.i18n.translate('yes') or luci.i18n.translate('no')%></div>
  123. <div class="td cbi-section-table-cell left"><%=gw.prefix%></div>
  124. </div>
  125. <% i = ((i % 2) + 1)
  126. end %>
  127. </div>
  128. </fieldset>
  129. <% else %>
  130. <%:SmartGateway is not configured on this system.%>
  131. <% end %>
  132. <%+status-olsr/common_js%>
  133. <%+footer%>