overview.htm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. has_ipv4_conf = luci.model.uci.cursor():get_first("olsrd", "olsrd", "IpVersion")
  9. has_ipv6_conf = luci.model.uci.cursor():get_first("olsrd6", "olsrd", "IpVersion")
  10. function write_conf(conf, file)
  11. local fs = require "nixio.fs"
  12. if fs.access(conf) then
  13. luci.http.header("Content-Disposition", "attachment; filename="..file)
  14. luci.http.prepare_content("text/plain")
  15. luci.http.write(fs.readfile(conf))
  16. end
  17. end
  18. conf = luci.http.formvalue()
  19. if conf.openwrt_v4 then
  20. write_conf("/etc/config/olsrd", "olsrd")
  21. return false
  22. end
  23. if conf.openwrt_v6 then
  24. write_conf("/etc/config/olsrd6", "olsrd6")
  25. return false
  26. end
  27. if conf.conf_v4 then
  28. write_conf("/var/etc/olsrd.conf", "olsrd.conf")
  29. return false
  30. end
  31. if conf.conf_v6 then
  32. write_conf("/var/etc/olsrd6.conf", "olsrd6.conf")
  33. return false
  34. end
  35. %>
  36. <%+header%>
  37. <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
  38. <script type="text/javascript">//<![CDATA[
  39. XHR.poll(10, '<%=REQUEST_URI%>/json', { },
  40. function(x, info)
  41. {
  42. var e;
  43. if (! info) {
  44. document.getElementById('error').innerHTML = '<%:Could not get any data. Make sure the jsoninfo plugin is installed and allows connections from localhost.%>';
  45. return
  46. }
  47. document.getElementById('error').innerHTML = '';
  48. if (e = document.getElementById('version'))
  49. var version;
  50. var date;
  51. if (info.v4.config.olsrdVersion != undefined) {
  52. version = info.v4.config.olsrdVersion
  53. date = info.v4.config.olsrdBuildDate
  54. } else if (info.v6.config.olsrdVersion != undefined) {
  55. version = info.v6.config.olsrdVersion
  56. date = info.v6.config.olsrdBuildDate
  57. } else {
  58. version = 'unknown'
  59. date = 'unknown'
  60. }
  61. e.innerHTML = version + '<br />' + date;
  62. if (e = document.getElementById('nr_neigh'))
  63. var neigh = 0;
  64. if (info.v4.links != undefined) {
  65. neigh = neigh + info.v4.links.length
  66. }
  67. if (info.v6.links != undefined) {
  68. neigh = neigh + info.v6.links.length
  69. }
  70. e.innerHTML = neigh;
  71. if (e = document.getElementById('nr_hna'))
  72. var hna = 0;
  73. if (info.v4.hna != undefined) {
  74. hna = hna + info.v4.hna.length
  75. }
  76. if (info.v6.hna != undefined) {
  77. hna = hna + info.v6.hna.length
  78. }
  79. e.innerHTML = hna;
  80. if (e = document.getElementById('nr_ifaces'))
  81. var nrint = 0
  82. if (info.v4.interfaces != undefined) {
  83. nrint = nrint + info.v4.interfaces.length
  84. }
  85. if (info.v6.interfaces != undefined) {
  86. nrint = nrint + info.v6.interfaces.length
  87. }
  88. e.innerHTML = nrint
  89. if (e = document.getElementById('nr_topo'))
  90. var topo = 0;
  91. var nodes = [];
  92. Array.prototype.contains = function (element) {
  93. for (var i = 0; i < this.length; i++) {
  94. if (this[i] == element) {
  95. return true;
  96. }
  97. }
  98. return false;
  99. }
  100. if (info.v4.topology != undefined) {
  101. topo = topo + info.v4.topology.length;
  102. for (var i = 0; i < info.v4.topology.length; i++) {
  103. var destip = info.v4.topology[i].destinationIP
  104. if (! nodes.contains(destip) ) {
  105. nodes.push(destip)
  106. }
  107. }
  108. }
  109. if (info.v6.topology != undefined) {
  110. topo = topo + info.v6.topology.length
  111. for (var i = 0; i < info.v6.topology.length; i++) {
  112. var destip = info.v6.topology[i].destinationIP
  113. if (! nodes.contains(destip) ) {
  114. nodes.push(destip)
  115. }
  116. }
  117. }
  118. e.innerHTML = topo;
  119. if (e = document.getElementById('nr_nodes'))
  120. e.innerHTML = nodes.length;
  121. if (e = document.getElementById('meshfactor'))
  122. var meshfactor = topo / nodes.length
  123. e.innerHTML = meshfactor.toFixed(2)
  124. }
  125. );
  126. //]]></script>
  127. <div id="error" class="error"></div>
  128. <h2 name="content">OLSR <%:Overview%></h2>
  129. <fieldset class="cbi-section">
  130. <legend><%:Network%></legend>
  131. <table width="100%" cellspacing="10">
  132. <tr><td width="33%"><%:Interfaces%></td><td>
  133. <a href="<%=REQUEST_URI%>/interfaces">
  134. <span id="nr_ifaces">-<span>
  135. </a>
  136. </td></tr>
  137. <tr><td width="33%"><%:Neighbors%></td><td>
  138. <a href="<%=REQUEST_URI%>/neighbors">
  139. <span id="nr_neigh">-</span>
  140. </a>
  141. </td></tr>
  142. <tr><td width="33%"><%:Nodes%></td><td>
  143. <a href="<%=REQUEST_URI%>/topology">
  144. <span id="nr_nodes">-</span>
  145. </a>
  146. </td></tr>
  147. <tr><td width="33%"><%:HNA%></td><td>
  148. <a href="<%=REQUEST_URI%>/hna">
  149. <span id="nr_hna">-</span>
  150. </a>
  151. </td></tr>
  152. <tr><td width="33%"><%:Links total%></td><td>
  153. <a href="<%=REQUEST_URI%>/topology">
  154. <span id="nr_topo">-</span>
  155. </a>
  156. </td></tr>
  157. <tr><td width="33%"><%:Links per node (average)%></td><td>
  158. <span id="meshfactor">-</span>
  159. </td></tr>
  160. </table>
  161. </fieldset>
  162. <fieldset class="cbi-section">
  163. <legend>OLSR <%:Configuration%></legend>
  164. <table width="100%" cellspacing="10">
  165. <tr><td width="33%"><%:Version%></td><td>
  166. <span id="version">-<span>
  167. </td></tr>
  168. <tr><td width="33%"><%:Download Config%></td><td>
  169. <% if has_ipv4_conf then %>
  170. <a href="<%=REQUEST_URI%>?openwrt_v4">OpenWrt (IPv4)</a>,
  171. <% end %>
  172. <% if has_ipv6_conf then %>
  173. <a href="<%=REQUEST_URI%>?openwrt_v6">OpenWrt (IPv6)</a>,
  174. <% end %>
  175. <% if has_ipv4_conf then %>
  176. <a href="<%=REQUEST_URI%>?conf_v4">OLSRD (IPv4)</a>,
  177. <% end %>
  178. <% if has_ipv6_conf then %>
  179. <a href="<%=REQUEST_URI%>?conf_v6">OLSRD (IPv6)</a>
  180. <% end %>
  181. </td></tr>
  182. </table>
  183. </fieldset>
  184. <%+footer%>