overview.htm 5.8 KB

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