iface_overview.htm 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <%#
  2. Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  3. Licensed to the public under the Apache License 2.0.
  4. -%>
  5. <%-
  6. local ntm = require "luci.model.network".init()
  7. local fwm = require "luci.model.firewall".init()
  8. local net
  9. local ifaces = { }
  10. local netlist = { }
  11. for _, net in ipairs(ntm:get_networks()) do
  12. if net:name() ~= "loopback" then
  13. local z = fwm:get_zone_by_network(net:name())
  14. ifaces[#ifaces+1] = net:name()
  15. netlist[#netlist+1] = {
  16. net:name(), z and z:name() or "-", z
  17. }
  18. end
  19. end
  20. table.sort(netlist,
  21. function(a, b)
  22. if a[2] ~= b[2] then
  23. return a[2] < b[2]
  24. else
  25. return a[1] < b[1]
  26. end
  27. end)
  28. -%>
  29. <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
  30. <script type="text/javascript">//<![CDATA[
  31. function iface_shutdown(id, reconnect) {
  32. if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this device if you are connected via this interface.%>', id)))
  33. return;
  34. var d = document.getElementById(id + '-ifc-description');
  35. if (d)
  36. d.innerHTML = reconnect
  37. ? '<em><%:Interface is reconnecting...%></em>'
  38. : '<em><%:Interface is shutting down...%></em>';
  39. var s = document.getElementById('ifc-rc-status');
  40. if (s)
  41. {
  42. s.parentNode.style.display = 'block';
  43. s.innerHTML = '<%:Waiting for changes to be applied...%>';
  44. }
  45. XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
  46. function(x)
  47. {
  48. if (s)
  49. {
  50. s.innerHTML = reconnect
  51. ? '<%:Interface reconnected%>'
  52. : '<%:Interface shut down%>';
  53. window.setTimeout(function() {
  54. s.parentNode.style.display = 'none';
  55. }, 1000);
  56. }
  57. }
  58. );
  59. }
  60. var iwxhr = new XHR();
  61. var wifidevs = <%=luci.http.write_json(netdevs)%>;
  62. var arptable = <%=luci.http.write_json(arpcache)%>;
  63. XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(ifaces, ","))%>', null,
  64. function(x, ifcs)
  65. {
  66. if (ifcs)
  67. {
  68. for (var idx = 0; idx < ifcs.length; idx++)
  69. {
  70. var ifc = ifcs[idx];
  71. var html = '';
  72. var s = document.getElementById(ifc.id + '-ifc-devices');
  73. if (s)
  74. {
  75. var stat = String.format(
  76. '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
  77. ifc.type,
  78. ifc.is_up ? '' : '_disabled'
  79. );
  80. if (ifc.subdevices && ifc.subdevices.length)
  81. {
  82. stat += ' <strong>(';
  83. for (var j = 0; j < ifc.subdevices.length; j++)
  84. {
  85. var sif = ifc.subdevices[j];
  86. stat += String.format(
  87. '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
  88. sif.type,
  89. sif.is_up ? '' : '_disabled',
  90. sif.name
  91. );
  92. }
  93. stat += ')</strong>';
  94. }
  95. stat += String.format(
  96. '<br /><small>%h</small>',
  97. ifc.name
  98. );
  99. s.innerHTML = stat;
  100. }
  101. var d = document.getElementById(ifc.id + '-ifc-description');
  102. if (d && ifc.proto && ifc.ifname)
  103. {
  104. if (ifc.is_up)
  105. {
  106. html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
  107. }
  108. if (ifc.type != 'tunnel')
  109. {
  110. html += String.format('<strong><%:MAC-Address%>:</strong> %s<br />', ifc.macaddr);
  111. }
  112. html += String.format(
  113. '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
  114. '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
  115. ifc.rx_bytes, ifc.rx_packets,
  116. ifc.tx_bytes, ifc.tx_packets
  117. );
  118. if (ifc.ipaddrs && ifc.ipaddrs.length)
  119. {
  120. html += '<strong><%:IPv4%>: </strong>';
  121. for (var i = 0; i < ifc.ipaddrs.length; i++)
  122. html += String.format(
  123. '%s%s/%d',
  124. i ? ', ' : '',
  125. ifc.ipaddrs[i].addr,
  126. ifc.ipaddrs[i].prefix
  127. );
  128. html += '<br />';
  129. }
  130. if (ifc.ip6addrs && ifc.ip6addrs.length)
  131. {
  132. html += '<strong><%:IPv6%>: </strong>';
  133. for (var i = 0; i < ifc.ip6addrs.length; i++)
  134. html += String.format(
  135. '%s%s/%d',
  136. i ? ', ' : '',
  137. ifc.ip6addrs[i].addr.toUpperCase(),
  138. ifc.ip6addrs[i].prefix
  139. );
  140. html += '<br />';
  141. }
  142. d.innerHTML = html;
  143. }
  144. else if (d && !ifc.proto)
  145. {
  146. var e = document.getElementById(ifc.id + '-ifc-edit');
  147. if (e)
  148. e.disabled = true;
  149. d.innerHTML = String.format(
  150. '<em><%:Unsupported protocol type.%></em><br />' +
  151. '<a href="%h"><%:Install protocol extensions...%></a>',
  152. '<%=luci.dispatcher.build_url("admin/system/packages")%>?query=luci-proto&display=available'
  153. );
  154. }
  155. else if (d && !ifc.ifname)
  156. {
  157. d.innerHTML = String.format(
  158. '<em><%:Network without interfaces.%></em><br />' +
  159. '<a href="<%=luci.dispatcher.build_url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',
  160. ifc.name, ifc.name
  161. );
  162. }
  163. else if (d)
  164. {
  165. d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
  166. }
  167. }
  168. }
  169. }
  170. );
  171. //]]></script>
  172. <fieldset class="cbi-section" style="display:none">
  173. <legend><%:Reconnecting interface%></legend>
  174. <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
  175. <span id="ifc-rc-status"><%:Waiting for changes to be applied...%></span>
  176. </fieldset>
  177. <div class="cbi-map">
  178. <fieldset class="cbi-section">
  179. <legend><%:Interface Overview%></legend>
  180. <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
  181. <tr class="cbi-section-table-titles">
  182. <th class="cbi-section-table-cell"><%:Network%></th>
  183. <th class="cbi-section-table-cell" style="text-align:left"><%:Status%></th>
  184. <th class="cbi-section-table-cell"><%:Actions%></th>
  185. </tr>
  186. <%
  187. for i, net in ipairs(netlist) do
  188. local z = net[3]
  189. local c = z and z:get_color() or "#EEEEEE"
  190. local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
  191. %>
  192. <tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
  193. <td class="cbi-value-field" style="padding:3px">
  194. <div class="ifacebox">
  195. <div class="ifacebox-head" style="background-color:<%=c%>" title="<%=pcdata(t)%>">
  196. <strong><%=net[1]:upper()%></strong>
  197. </div>
  198. <div class="ifacebox-body" id="<%=net[1]%>-ifc-devices">
  199. <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
  200. <small>?</small>
  201. </div>
  202. </div>
  203. </td>
  204. <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net[1]%>-ifc-description">
  205. <em><%:Collecting data...%></em>
  206. </td>
  207. <td style="width:420px">
  208. <input type="button" class="cbi-button cbi-button-reload" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', true)" title="<%:Reconnect this interface%>" value="<%:Connect%>" />
  209. <input type="button" class="cbi-button cbi-button-reset" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', false)" title="<%:Shutdown this interface%>" value="<%:Stop%>" />
  210. <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/network", net[1])%>'" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit" />
  211. <input type="button" class="cbi-button cbi-button-remove" style="width:100px" onclick="if (confirm('<%:Really delete this interface? The deletion cannot be undone!\nYou might lose access to this device if you are connected via this interface.%>')) location.href='<%=luci.dispatcher.build_url("admin/network/iface_delete", net[1])%>'" title="<%:Delete this interface%>" value="<%:Delete%>" />
  212. </td>
  213. </tr>
  214. <% end %>
  215. </table>
  216. <input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/iface_add")%>'" />
  217. </fieldset>
  218. </div>