<%# LuCI - Lua Configuration Interface Copyright 2008-2009 Steven Barth Copyright 2008-2009 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ -%> <%- local sys = require "luci.sys" local wba = require "luci.tools.webadmin" local uci = require "luci.model.uci".cursor_state() local fs = require "nixio.fs" local bridge_ifs = { } local single_ifs = { } local wifi_ifs = { } local devinfo = sys.net.deviceinfo() uci:foreach("network", "interface", function(s) if s['.name'] ~= "loopback" then if s.type == "bridge" then bridge_ifs[#bridge_ifs+1] = s else single_ifs[#single_ifs+1] = s end end end) uci:foreach("wireless", "wifi-iface", function(s) wifi_ifs[s.network or s.device] = true end) function is_wifi(i) return wifi_ifs[i] or i:match("^wl%d+") or i:match("^ath%d+") or i:match("^wlan%d+") end function get_ifname(s) return s.ifname and s.ifname:match("%S+") end function get_ifnames(s) local l = { } if s.ifname then for n in s.ifname:gmatch("%S+") do l[#l+1] = n end end return l end function get_vlan(i) return i and i:match("^%w+%.(%d+)$") end function get_vlan_ports(i) local x = get_vlan(i) local d = i:match("(%d+)%.%d+$") local p = { } uci:foreach("network", "switch", function(s) local d2 = s['.name']:match("%d+$") if d2 == d and s["vlan"..x] then for pt in s["vlan"..x]:gmatch("%S+") do p[#p+1] = pt end end end) return p end function get_switch_driver(i) local n, d = i:match("([a-z]+)(%d+)%.%d+$") local hw = fs.readfile("/proc/switch/%s%s/driver" %{ n, d }) or fs.readfile("/proc/switch/%s/driver" % d ) return hw and hw:match("%S+") end function get_mac(i) for l in luci.util.execi("ifconfig %q" % i) do if l:find("HWaddr ") then return l:match("HWaddr (%S+)") end end return "00:00:00:00:00:00" end function get_aliases(s) local a = { } uci:foreach("network", "alias", function(s2) if s2.interface == s['.name'] then a[#a+1] = s2 end end) return a end function get_iwinfo(i) local w = { } uci:foreach("wireless", "wifi-iface", function(s) if s.ifname == i then w.type = uci:get("wireless", s.device, "type") w.channel = uci:get("wireless", s.device, "channel") w.mode = ( s.wds == "1" ) and s.mode .. "wds" or s.mode w.ssid = s.ssid w.type = w.type and w.type:gsub("^([a-z])", string.upper) end end) return w end function get_iwmode(w) local m = { ap = translate("Master"), sta = translate("Client"), wds = translate("WDS"), stawds = translate("Client + WDS"), apwds = translate("Master + WDS"), adhoc = translate("Ad-Hoc"), ahdemo = translate("Pseudo Ad-Hoc") } return m[w.mode] or w.mode end function get_brinfo(s) local b = { } local m = false for l in luci.util.execi("brctl show") do if not l:match("STP") then if m and l:match("^[a-z]") then break elseif m or l:match("^br%%-%s" % s['.name']) then m = true local r = luci.util.split(l, "%s+", nil, true) if #r > 2 then b.name = r[1] b.id = r[2] b.stp = r[3] == "yes" b.ifnames = { r[4] } else b.ifnames[#b.ifnames+1] = r[2] end end end end return b end -%> <%+header%>

<%:Interface Status%>

<% for _, i in ipairs(single_ifs) do dev = get_ifname(i) vlan = get_vlan(dev) if dev and devinfo and devinfo[dev] then %>

<%:Interface%> <%=i['.name']%>

<%:Device%>: <%=dev%> (<%:MAC%> <%=get_mac(dev)%>)
<%:Type%>: <% if is_wifi(dev) then iw = get_iwinfo(dev) -%> <%:Wireless Adapter%> (<%=iw.type%>)
<% if iw then %>   └ <%:Mode%>: <%=get_iwmode(iw)%>
  └ <%:SSID%>: <%=iw.ssid%>
  └ <%:Channel%>: <%=iw.channel%> <% end %> <% else -%> <% if vlan then %> <%:Ethernet Switch%> (<%=get_switch_driver(dev)%>)
  └ <%:VLAN%>: <%=get_vlan(dev)%> (<%:Ports%> <%=table.concat(get_vlan_ports(dev), ", ")%>) <% else %> <%:Ethernet Adapter%> <% end %> <% end -%>
<%:Transfer%>
  └ <%:RX%>: <%=devinfo[dev][2]%> <%:Pkts.%> (<%=wba.byte_format(tonumber(devinfo[dev][1]))%>)
  └ <%:TX%>: <%=devinfo[dev][10]%> <%:Pkts.%> (<%=wba.byte_format(tonumber(devinfo[dev][9]))%>)
<%- if ( i.ipaddr and #i.ipaddr > 0 ) or ( i.ip6addr and #i.ip6addr > 0 ) then -%> <%:IP Configuration%>
  └ <%:Primary%>: <% if i.ipaddr and #i.ipaddr > 0 then %> <%=i.ipaddr%>/<%=i.netmask%> <% if i.proto == "dhcp" then -%> (<%:DHCP assigned%>) <%- end %> <% else %> <%:Not configured%> <% end %>
<% for i, a in ipairs(get_aliases(i)) do %>   └ <%:Alias%> #<%=i%>: <%=a.ipaddr%>/<%=a.netmask%> (<%:Device%> <%=dev%>:<%=i%>)
<% end %> <% if i.ip6addr and #i.ip6addr > 0 then %>   └ <%:IPv6%>: <%=i.ip6addr%>
<% end %> <%- end -%>

<% end end %> <% for _, b in ipairs(bridge_ifs) do br = get_brinfo(b) dev = br and br.name if br and devinfo and devinfo[dev] then %>

<%:Bridge%> <%=br.name%>

<%:Device%>: <%=dev%> (<%:MAC%> <%=get_mac(dev)%>)
<%:Type%>: <%:Ethernet Bridge%>
  └ <%:ID%>: <%=br.id%>
  └ <%:STP%>: <%=br.stp and "enabled" or "disabled"%>
<%:Transfer%>
  └ <%:RX%>: <%=devinfo[dev][2]%> Pkts. (<%=wba.byte_format(tonumber(devinfo[dev][1]))%>)
  └ <%:TX%>: <%=devinfo[dev][10]%> Pkts. (<%=wba.byte_format(tonumber(devinfo[dev][9]))%>)
<%- if ( b.ipaddr and #b.ipaddr > 0 ) or ( b.ip6addr and #b.ip6addr > 0 ) then -%> <%:IP Configuration%>
  └ <%:Primary%>: <% if b.ipaddr and #b.ipaddr > 0 then %> <%=b.ipaddr%>/<%=b.netmask%> <% if b.proto == "dhcp" then -%> (<%:DHCP assigned%>) <%- end %> <% else %> <%:Not configured%> <% end %>
<% for i, a in ipairs(get_aliases(b)) do %>   └ <%:Alias%> #<%=i%>: <%=a.ipaddr%>/<%=a.netmask%> (<%:Device%> <%=dev%>:<%=i%>)
<% end %> <% if b.ip6addr and #b.ip6addr > 0 then %>   └ <%:IPv6%>: <%=b.ip6addr%>
<% end %> <%- end -%> <% for n, i in ipairs(br.ifnames) do dev = i vlan = get_vlan(dev) %> <%:Bridge Port%> <%=n%>
  └ <%:Device%>: <%=dev%> (<%:MAC%> <%=get_mac(dev)%>)
  └ <%:Type%>: <% if is_wifi(dev) then iw = get_iwinfo(dev) -%> <%:Wireless Adapter%> (<%=iw.type%>)
<% if iw then %>       └ <%:Mode%>: <%=get_iwmode(iw)%>
      └ <%:SSID%>: <%=iw.ssid%>
      └ <%:Channel%>: <%=iw.channel%> <% end %> <% else -%> <% if vlan then %> <%:Ethernet Switch%> (<%=get_switch_driver(dev)%>)
      └ <%:VLAN%>: <%=get_vlan(dev)%> (<%:Ports%> <%=table.concat(get_vlan_ports(dev), ", ")%>) <% else %> <%:Ethernet Adapter%> <% end %> <% end -%>
<% end %>

<% end end %>
<%+footer%>