1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
<%#
LuCI - Lua Configuration Interface
Copyright 2008-2009 Steven Barth <steven@midlink.org>
Copyright 2008-2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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("a_s_if_iwmode_ap", "Master"),
sta = translate("a_s_if_iwmode_sta", "Client"),
wds = translate("a_s_if_iwmode_wds", "WDS"),
stawds = translate("a_s_if_iwmode_stawds", "Client + WDS"),
apwds = translate("a_s_if_iwmode_apwds", "Master + WDS"),
adhoc = translate("a_s_if_iwmode_adhoc", "Ad-Hoc"),
ahdemo = translate("a_s_if_iwmode_ahdemo", "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%>
<h2><a id="content" name="content"><%:a_s_if_status Interface Status%></a></h2>
<form method="post" action="<%=REQUEST_URI%>">
<div class="cbi-map">
<fieldset class="cbi-section">
<% for _, i in ipairs(single_ifs) do
dev = get_ifname(i)
vlan = get_vlan(dev)
if dev and devinfo and devinfo[dev] then
%>
<h3><%:a_s_if_interface Interface%> <%=i['.name']%></h3>
<p style="font-size:90%;padding-left:1em">
<strong><%:a_s_if_device Device%>:</strong>
<%=dev%> (<%:a_s_if_mac MAC%> <%=get_mac(dev)%>)<br />
<strong><%:a_s_if_type Type%>:</strong>
<% if is_wifi(dev) then iw = get_iwinfo(dev) -%>
<%:a_s_if_wifidev Wireless Adapter%> (<%=iw.type%>)<br />
<% if iw then %>
└ <strong><%:a_s_if_iwmode Mode%>:</strong> <%=get_iwmode(iw)%><br />
└ <strong><%:a_s_if_iwssid SSID%>:</strong> <%=iw.ssid%><br />
└ <strong><%:a_s_if_iwchannel Channel%>:</strong> <%=iw.channel%>
<% end %>
<% else -%>
<% if vlan then %>
<%:a_s_if_ethswitch Ethernet Switch%> (<%=get_switch_driver(dev)%>)<br />
└ <strong><%:a_s_if_vlan VLAN%>:</strong> <%=get_vlan(dev)%> (<%:a_s_if_vlanports Ports%> <%=table.concat(get_vlan_ports(dev), ", ")%>)
<% else %>
<%:a_s_if_ethdev Ethernet Adapter%>
<% end %>
<% end -%><br />
<strong><%:a_s_if_transfer Transfer%></strong><br />
└ <strong><%:a_s_if_transfer_rx RX%>:</strong> <%=devinfo[dev][2]%> <%:a_s_if_pkts Pkts.%> (<%=wba.byte_format(tonumber(devinfo[dev][1]))%>)<br />
└ <strong><%:a_s_if_transfer_tx TX%>:</strong> <%=devinfo[dev][10]%> <%:a_s_if_pkts Pkts.%> (<%=wba.byte_format(tonumber(devinfo[dev][9]))%>)<br />
<%- if ( i.ipaddr and #i.ipaddr > 0 ) or ( i.ip6addr and #i.ip6addr > 0 ) then -%>
<strong><%:a_s_if_ipconfig IP Configuration%></strong><br />
└ <strong><%:a_s_if_ipconfig_primary Primary%>:</strong>
<% if i.ipaddr and #i.ipaddr > 0 then %>
<%=i.ipaddr%>/<%=i.netmask%>
<% if i.proto == "dhcp" then -%>
(<%:a_s_if_ipconfig_dhcp DHCP assigned%>)
<%- end %>
<% else %>
<em><%:a_s_if_ipconfig_none Not configured%></em>
<% end %><br />
<% for i, a in ipairs(get_aliases(i)) do %>
└ <strong><%:a_s_if_ipconfig_alias Alias%> #<%=i%>:</strong>
<%=a.ipaddr%>/<%=a.netmask%> (<%:a_s_if_device Device%> <%=dev%>:<%=i%>) <br />
<% end %>
<% if i.ip6addr and #i.ip6addr > 0 then %>
└ <strong><%:a_s_if_ipconfig_ipv6 IPv6%>:</strong> <%=i.ip6addr%><br />
<% end %>
<%- end -%>
<br /></p>
<% 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
%>
<h3><%:a_s_if_bridge Bridge%> <%=br.name%></h3>
<p style="font-size:90%;padding-left:1em">
<strong><%:a_s_if_device Device%>:</strong>
<%=dev%> (<%:a_s_if_mac MAC%> <%=get_mac(dev)%>)<br />
<strong><%:a_s_if_type Type%>:</strong>
<%:a_s_if_ethbridge Ethernet Bridge%><br />
└ <strong><%:a_s_if_bridge_id ID%>:</strong> <%=br.id%><br />
└ <strong><%:a_s_if_bridge_stp STP%>:</strong> <%=br.stp and "enabled" or "disabled"%><br />
<strong><%:a_s_if_transfer Transfer%></strong><br />
└ <strong><%:a_s_if_transfer_rx RX%>:</strong> <%=devinfo[dev][2]%> Pkts. (<%=wba.byte_format(tonumber(devinfo[dev][1]))%>)<br />
└ <strong><%:a_s_if_transfer_tx TX%>:</strong> <%=devinfo[dev][10]%> Pkts. (<%=wba.byte_format(tonumber(devinfo[dev][9]))%>)<br />
<%- if ( b.ipaddr and #b.ipaddr > 0 ) or ( b.ip6addr and #b.ip6addr > 0 ) then -%>
<strong><%:a_s_if_ipconfig IP Configuration%></strong><br />
└ <strong><%:a_s_if_ipconfig_primary Primary%>:</strong>
<% if b.ipaddr and #b.ipaddr > 0 then %>
<%=b.ipaddr%>/<%=b.netmask%>
<% if b.proto == "dhcp" then -%>
(<%:a_s_if_ipconfig_dhcp DHCP assigned%>)
<%- end %>
<% else %>
<em><%:a_s_if_ipconfig_none Not configured%></em>
<% end %><br />
<% for i, a in ipairs(get_aliases(b)) do %>
└ <strong><%:a_s_if_ipconfig_alias Alias%> #<%=i%>:</strong>
<%=a.ipaddr%>/<%=a.netmask%> (<%:a_s_if_device Device%> <%=dev%>:<%=i%>) <br />
<% end %>
<% if b.ip6addr and #b.ip6addr > 0 then %>
└ <strong><%:a_s_if_ipconfig_ipv6 IPv6%>:</strong> <%=b.ip6addr%><br />
<% end %>
<%- end -%>
<% for n, i in ipairs(br.ifnames) do
dev = i
vlan = get_vlan(dev)
%>
<strong><%:a_s_if_bridge_port Bridge Port%> <%=n%></strong><br />
└ <strong><%:a_s_if_device Device%>:</strong>
<%=dev%> (<%:a_s_if_mac MAC%> <%=get_mac(dev)%>)<br />
└ <strong><%:a_s_if_type Type%>:</strong>
<% if is_wifi(dev) then iw = get_iwinfo(dev) -%>
<%:a_s_if_wifidev Wireless Adapter%> (<%=iw.type%>)<br />
<% if iw then %>
└ <strong><%:a_s_if_iwmode Mode%>:</strong> <%=get_iwmode(iw)%><br />
└ <strong><%:a_s_if_iwssid SSID%>:</strong> <%=iw.ssid%><br />
└ <strong><%:a_s_if_iwchannel Channel%>:</strong> <%=iw.channel%>
<% end %>
<% else -%>
<% if vlan then %>
<%:a_s_if_ethswitch Ethernet Switch%> (<%=get_switch_driver(dev)%>)<br />
└ <strong><%:a_s_if_vlan VLAN%>:</strong>
<%=get_vlan(dev)%> (<%:a_s_if_vlan_ports Ports%> <%=table.concat(get_vlan_ports(dev), ", ")%>)
<% else %>
<%:a_s_if_ethdev Ethernet Adapter%>
<% end %>
<% end -%><br />
<% end %>
<br /></p>
<% end end %>
</fieldset>
</div>
</form>
<%+footer%>
|