iface_overview.htm 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. (new XHR()).post('<%=url('admin/network')%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, { token: '<%=token%>' },
  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. function iface_delete(id) {
  61. 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.%>'))
  62. return;
  63. (new XHR()).post('<%=url('admin/network/iface_delete')%>/' + id, { token: '<%=token%>' },
  64. function(x) {
  65. location.href = '<%=url('admin/network/network')%>';
  66. }
  67. );
  68. }
  69. var iwxhr = new XHR();
  70. var wifidevs = <%=luci.http.write_json(netdevs)%>;
  71. var arptable = <%=luci.http.write_json(arpcache)%>;
  72. XHR.poll(5, '<%=url('admin/network/iface_status', table.concat(ifaces, ","))%>', null,
  73. function(x, ifcs)
  74. {
  75. if (ifcs)
  76. {
  77. for (var idx = 0; idx < ifcs.length; idx++)
  78. {
  79. var ifc = ifcs[idx];
  80. var html = '';
  81. var s = document.getElementById(ifc.id + '-ifc-devices');
  82. if (s)
  83. {
  84. var stat = String.format(
  85. '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
  86. ifc.type,
  87. ifc.is_up ? '' : '_disabled'
  88. );
  89. if (ifc.subdevices && ifc.subdevices.length)
  90. {
  91. stat += ' <strong>(';
  92. for (var j = 0; j < ifc.subdevices.length; j++)
  93. {
  94. var sif = ifc.subdevices[j];
  95. stat += String.format(
  96. '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
  97. sif.type,
  98. sif.is_up ? '' : '_disabled',
  99. sif.name
  100. );
  101. }
  102. stat += ')</strong>';
  103. }
  104. stat += String.format(
  105. '<br /><small>%h</small>',
  106. ifc.name
  107. );
  108. s.innerHTML = stat;
  109. }
  110. var d = document.getElementById(ifc.id + '-ifc-description');
  111. if (d && ifc.proto && ifc.ifname)
  112. {
  113. if (ifc.is_up)
  114. {
  115. html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
  116. }
  117. if (ifc.macaddr)
  118. {
  119. html += String.format('<strong><%:MAC-Address%>:</strong> %s<br />', ifc.macaddr);
  120. }
  121. html += String.format(
  122. '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
  123. '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
  124. ifc.rx_bytes, ifc.rx_packets,
  125. ifc.tx_bytes, ifc.tx_packets
  126. );
  127. if (ifc.ipaddrs && ifc.ipaddrs.length)
  128. {
  129. for (var i = 0; i < ifc.ipaddrs.length; i++)
  130. html += String.format(
  131. '<strong><%:IPv4%>:</strong> %s<br />',
  132. ifc.ipaddrs[i]
  133. );
  134. }
  135. if (ifc.ip6addrs && ifc.ip6addrs.length)
  136. {
  137. for (var i = 0; i < ifc.ip6addrs.length; i++)
  138. html += String.format(
  139. '<strong><%:IPv6%>:</strong> %s<br />',
  140. ifc.ip6addrs[i]
  141. );
  142. }
  143. d.innerHTML = html;
  144. }
  145. else if (d && !ifc.proto)
  146. {
  147. var e = document.getElementById(ifc.id + '-ifc-edit');
  148. if (e)
  149. e.disabled = true;
  150. d.innerHTML = String.format(
  151. '<em><%:Unsupported protocol type.%></em><br />' +
  152. '<a href="%h"><%:Install protocol extensions...%></a>',
  153. '<%=url("admin/system/packages")%>?query=luci-proto&display=available'
  154. );
  155. }
  156. else if (d && !ifc.ifname)
  157. {
  158. d.innerHTML = String.format(
  159. '<em><%:Network without interfaces.%></em><br />' +
  160. '<a href="<%=url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',
  161. ifc.name, ifc.name
  162. );
  163. }
  164. else if (d)
  165. {
  166. d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
  167. }
  168. }
  169. }
  170. }
  171. );
  172. //]]></script>
  173. <fieldset class="cbi-section" style="display:none">
  174. <legend><%:Reconnecting interface%></legend>
  175. <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
  176. <span id="ifc-rc-status"><%:Waiting for changes to be applied...%></span>
  177. </fieldset>
  178. <div class="cbi-map">
  179. <fieldset class="cbi-section">
  180. <legend><%:Interface Overview%></legend>
  181. <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
  182. <tr class="cbi-section-table-titles">
  183. <th class="cbi-section-table-cell"><%:Network%></th>
  184. <th class="cbi-section-table-cell" style="text-align:left"><%:Status%></th>
  185. <th class="cbi-section-table-cell"><%:Actions%></th>
  186. </tr>
  187. <%
  188. for i, net in ipairs(netlist) do
  189. local z = net[3]
  190. local c = z and z:get_color() or "#EEEEEE"
  191. local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
  192. %>
  193. <tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
  194. <td class="cbi-value-field" style="padding:3px">
  195. <div class="ifacebox">
  196. <div class="ifacebox-head" style="background-color:<%=c%>" title="<%=pcdata(t)%>">
  197. <strong><%=net[1]:upper()%></strong>
  198. </div>
  199. <div class="ifacebox-body" id="<%=net[1]%>-ifc-devices">
  200. <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
  201. <small>?</small>
  202. </div>
  203. </div>
  204. </td>
  205. <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net[1]%>-ifc-description">
  206. <em><%:Collecting data...%></em>
  207. </td>
  208. <td style="width:420px">
  209. <input type="button" class="cbi-button cbi-button-reload" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', true)" title="<%:Reconnect this interface%>" value="<%:Connect%>" />
  210. <input type="button" class="cbi-button cbi-button-reset" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', false)" title="<%:Shutdown this interface%>" value="<%:Stop%>" />
  211. <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=url("admin/network/network", net[1])%>'" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit" />
  212. <input type="button" class="cbi-button cbi-button-remove" style="width:100px" onclick="iface_delete('<%=net[1]%>')" value="<%:Delete%>" />
  213. </td>
  214. </tr>
  215. <% end %>
  216. </table>
  217. <input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=url("admin/network/iface_add")%>'" />
  218. </fieldset>
  219. </div>