2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
18 local sys = require "luci.sys"
19 local wba = require "luci.tools.webadmin"
20 local uci = require "luci.model.uci".cursor_state()
21 local fs = require "nixio.fs"
23 local bridge_ifs = { }
24 local single_ifs = { }
26 local devinfo = sys.net.deviceinfo()
28 uci:foreach("network", "interface",
30 if s['.name'] ~= "loopback" then
31 if s.type == "bridge" then
32 bridge_ifs[#bridge_ifs+1] = s
34 single_ifs[#single_ifs+1] = s
39 uci:foreach("wireless", "wifi-iface",
41 wifi_ifs[s.network or s.device] = true
48 or i:match("^wlan%d+")
51 function get_ifname(s)
52 return s.ifname and s.ifname:match("%S+")
55 function get_ifnames(s)
58 for n in s.ifname:gmatch("%S+") do
66 return i and i:match("^%w+%.(%d+)$")
69 function get_vlan_ports(i)
71 local d = i:match("(%d+)%.%d+$")
74 uci:foreach("network", "switch",
76 local d2 = s['.name']:match("%d+$")
77 if d2 == d and s["vlan"..x] then
78 for pt in s["vlan"..x]:gmatch("%S+") do
87 function get_switch_driver(i)
88 local n, d = i:match("([a-z]+)(%d+)%.%d+$")
89 local hw = fs.readfile("/proc/switch/%s%s/driver" %{ n, d })
90 or fs.readfile("/proc/switch/%s/driver" % d )
92 return hw and hw:match("%S+")
96 for l in luci.util.execi("ifconfig %q" % i) do
97 if l:find("HWaddr ") then
98 return l:match("HWaddr (%S+)")
101 return "00:00:00:00:00:00"
104 function get_aliases(s)
106 uci:foreach("network", "alias",
108 if s2.interface == s['.name'] then
115 function get_iwinfo(i)
117 uci:foreach("wireless", "wifi-iface",
119 if s.ifname == i then
120 w.type = uci:get("wireless", s.device, "type")
121 w.channel = uci:get("wireless", s.device, "channel")
122 w.mode = ( s.wds == "1" ) and s.mode .. "wds" or s.mode
124 w.type = w.type and w.type:gsub("^([a-z])", string.upper)
130 function get_iwmode(w)
132 ap = translate("Master"),
133 sta = translate("Client"),
134 wds = translate("WDS"),
135 stawds = translate("Client + WDS"),
136 apwds = translate("Master + WDS"),
137 adhoc = translate("Ad-Hoc"),
138 ahdemo = translate("Pseudo Ad-Hoc")
141 return m[w.mode] or w.mode
144 function get_brinfo(s)
147 for l in luci.util.execi("brctl show") do
148 if not l:match("STP") then
149 if m and l:match("^[a-z]") then
151 elseif m or l:match("^br%%-%s" % s['.name']) then
153 local r = luci.util.split(l, "%s+", nil, true)
157 b.stp = r[3] == "yes"
160 b.ifnames[#b.ifnames+1] = r[2]
172 <h2><a id="content" name="content"><%:Interface Status%></a></h2>
174 <form method="post" action="<%=REQUEST_URI%>">
175 <div class="cbi-map">
176 <fieldset class="cbi-section">
177 <% for _, i in ipairs(single_ifs) do
181 if dev and devinfo and devinfo[dev] then
183 <h3><%:Interface%> <%=i['.name']%></h3>
184 <p style="font-size:90%;padding-left:1em">
186 <strong><%:Device%>:</strong>
187 <%=dev%> (<%:MAC%> <%=get_mac(dev)%>)<br />
189 <strong><%:Type%>:</strong>
190 <% if is_wifi(dev) then iw = get_iwinfo(dev) -%>
191 <%:Wireless Adapter%> (<%=iw.type%>)<br />
193 └ <strong><%:Mode%>:</strong> <%=get_iwmode(iw)%><br />
194 └ <strong><%:SSID%>:</strong> <%=iw.ssid%><br />
195 └ <strong><%:Channel%>:</strong> <%=iw.channel%>
199 <%:Ethernet Switch%> (<%=get_switch_driver(dev)%>)<br />
200 └ <strong><%:VLAN%>:</strong> <%=get_vlan(dev)%> (<%:Ports%> <%=table.concat(get_vlan_ports(dev), ", ")%>)
202 <%:Ethernet Adapter%>
206 <strong><%:Transfer%></strong><br />
207 └ <strong><%:RX%>:</strong> <%=devinfo[dev][2]%> <%:Pkts.%> (<%=wba.byte_format(tonumber(devinfo[dev][1]))%>)<br />
208 └ <strong><%:TX%>:</strong> <%=devinfo[dev][10]%> <%:Pkts.%> (<%=wba.byte_format(tonumber(devinfo[dev][9]))%>)<br />
210 <%- if ( i.ipaddr and #i.ipaddr > 0 ) or ( i.ip6addr and #i.ip6addr > 0 ) then -%>
211 <strong><%:IP Configuration%></strong><br />
212 └ <strong><%:Primary%>:</strong>
213 <% if i.ipaddr and #i.ipaddr > 0 then %>
214 <%=i.ipaddr%>/<%=i.netmask%>
215 <% if i.proto == "dhcp" then -%>
219 <em><%:Not configured%></em>
222 <% for i, a in ipairs(get_aliases(i)) do %>
223 └ <strong><%:Alias%> #<%=i%>:</strong>
224 <%=a.ipaddr%>/<%=a.netmask%> (<%:Device%> <%=dev%>:<%=i%>) <br />
227 <% if i.ip6addr and #i.ip6addr > 0 then %>
228 └ <strong><%:IPv6%>:</strong> <%=i.ip6addr%><br />
235 <% for _, b in ipairs(bridge_ifs) do
239 if br and devinfo and devinfo[dev] then
241 <h3><%:Bridge%> <%=br.name%></h3>
242 <p style="font-size:90%;padding-left:1em">
244 <strong><%:Device%>:</strong>
245 <%=dev%> (<%:MAC%> <%=get_mac(dev)%>)<br />
247 <strong><%:Type%>:</strong>
248 <%:Ethernet Bridge%><br />
250 └ <strong><%:ID%>:</strong> <%=br.id%><br />
251 └ <strong><%:STP%>:</strong> <%=br.stp and "enabled" or "disabled"%><br />
253 <strong><%:Transfer%></strong><br />
254 └ <strong><%:RX%>:</strong> <%=devinfo[dev][2]%> Pkts. (<%=wba.byte_format(tonumber(devinfo[dev][1]))%>)<br />
255 └ <strong><%:TX%>:</strong> <%=devinfo[dev][10]%> Pkts. (<%=wba.byte_format(tonumber(devinfo[dev][9]))%>)<br />
257 <%- if ( b.ipaddr and #b.ipaddr > 0 ) or ( b.ip6addr and #b.ip6addr > 0 ) then -%>
258 <strong><%:IP Configuration%></strong><br />
259 └ <strong><%:Primary%>:</strong>
260 <% if b.ipaddr and #b.ipaddr > 0 then %>
261 <%=b.ipaddr%>/<%=b.netmask%>
262 <% if b.proto == "dhcp" then -%>
266 <em><%:Not configured%></em>
269 <% for i, a in ipairs(get_aliases(b)) do %>
270 └ <strong><%:Alias%> #<%=i%>:</strong>
271 <%=a.ipaddr%>/<%=a.netmask%> (<%:Device%> <%=dev%>:<%=i%>) <br />
274 <% if b.ip6addr and #b.ip6addr > 0 then %>
275 └ <strong><%:IPv6%>:</strong> <%=b.ip6addr%><br />
279 <% for n, i in ipairs(br.ifnames) do
283 <strong><%:Bridge Port%> <%=n%></strong><br />
285 └ <strong><%:Device%>:</strong>
286 <%=dev%> (<%:MAC%> <%=get_mac(dev)%>)<br />
288 └ <strong><%:Type%>:</strong>
289 <% if is_wifi(dev) then iw = get_iwinfo(dev) -%>
290 <%:Wireless Adapter%> (<%=iw.type%>)<br />
292 └ <strong><%:Mode%>:</strong> <%=get_iwmode(iw)%><br />
293 └ <strong><%:SSID%>:</strong> <%=iw.ssid%><br />
294 └ <strong><%:Channel%>:</strong> <%=iw.channel%>
298 <%:Ethernet Switch%> (<%=get_switch_driver(dev)%>)<br />
299 └ <strong><%:VLAN%>:</strong>
300 <%=get_vlan(dev)%> (<%:Ports%> <%=table.concat(get_vlan_ports(dev), ", ")%>)
302 <%:Ethernet Adapter%>