Skip to content

Commit 29fe3f5

Browse files
tobiaswaldvogelsystemcrash
authored andcommitted
luci: show wifi vlan in the associated wireless stations list
This patch adds a badge to the associated wireless stations with the vlan id and name. It is displayed in the same color as the network, to which it is bridged, so the color corresponds to the color in the network configuration page. Signed-off-by: Tobias Waldvogel <tobias.waldvogel@gmail.com>
1 parent 33d41d4 commit 29fe3f5

File tree

3 files changed

+153
-9
lines changed
  • modules
    • luci-base/htdocs/luci-static/resources
    • luci-mod-network/htdocs/luci-static/resources/view/network
    • luci-mod-status/htdocs/luci-static/resources/view/status/include

3 files changed

+153
-9
lines changed

modules/luci-base/htdocs/luci-static/resources/network.js

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ function enumerateNetworks() {
639639
}
640640

641641

642-
var Hosts, Network, Protocol, Device, WifiDevice, WifiNetwork;
642+
var Hosts, Network, Protocol, Device, WifiDevice, WifiNetwork, WifiVlan;
643643

644644
/**
645645
* @class network
@@ -4150,16 +4150,42 @@ WifiNetwork = baseclass.extend(/** @lends LuCI.network.WifiNetwork.prototype */
41504150
*/
41514151
getAssocList: function() {
41524152
var tasks = [];
4153-
var ifnames = [ this.getIfname() ].concat(this.getVlanIfnames());
4153+
var station;
41544154

4155-
for (var i = 0; i < ifnames.length; i++)
4156-
tasks.push(callIwinfoAssoclist(ifnames[i]));
4155+
for (let vlan of this.getVlans())
4156+
tasks.push(callIwinfoAssoclist(vlan.getIfname()).then(
4157+
function(stations) {
4158+
for (station of stations)
4159+
station.vlan = vlan;
4160+
4161+
return stations;
4162+
})
4163+
);
4164+
4165+
tasks.push(callIwinfoAssoclist(this.getIfname()));
41574166

41584167
return Promise.all(tasks).then(function(values) {
41594168
return Array.prototype.concat.apply([], values);
41604169
});
41614170
},
41624171

4172+
/**
4173+
* Fetch the vlans for this network.
4174+
*
4175+
* @returns {Array<LuCI.network.WifiVlan>}
4176+
* Returns an array of vlans for this network.
4177+
*/
4178+
getVlans: function() {
4179+
var vlans = [];
4180+
var vlans_ubus = this.ubus('net', 'vlans');
4181+
4182+
if (vlans_ubus)
4183+
for (let vlan of vlans_ubus)
4184+
vlans.push(new WifiVlan(vlan));
4185+
4186+
return vlans;
4187+
},
4188+
41634189
/**
41644190
* Query the current operating frequency of the wireless network.
41654191
*
@@ -4436,4 +4462,77 @@ WifiNetwork = baseclass.extend(/** @lends LuCI.network.WifiNetwork.prototype */
44364462
}
44374463
});
44384464

4465+
/**
4466+
* @class
4467+
* @memberof LuCI.network
4468+
* @hideconstructor
4469+
* @classdesc
4470+
*
4471+
* A `Network.WifiVlan` class instance represents a vlan on a WifiNetwork.
4472+
*/
4473+
WifiVlan = baseclass.extend(/** @lends LuCI.network.WifiVlan.prototype */ {
4474+
__init__: function(vlan) {
4475+
this.ifname = vlan.ifname;
4476+
if (L.isObject(vlan.config)) {
4477+
this.vid = vlan.config.vid;
4478+
this.name = vlan.config.name;
4479+
4480+
if (Array.isArray(vlan.config.network) && vlan.config.network.length)
4481+
this.network = vlan.config.network[0];
4482+
}
4483+
},
4484+
4485+
/**
4486+
* Get the name of the wifi vlan.
4487+
*
4488+
* @returns {string}
4489+
* Returns the name.
4490+
*/
4491+
getName: function() {
4492+
return this.name;
4493+
},
4494+
4495+
/**
4496+
* Get the vlan id of the wifi vlan.
4497+
*
4498+
* @returns {number}
4499+
* Returns the vlan id.
4500+
*/
4501+
getVlanId: function() {
4502+
return this.vid;
4503+
},
4504+
4505+
/**
4506+
* Get the network of the wifi vlan.
4507+
*
4508+
* @returns {string}
4509+
* Returns the network.
4510+
*/
4511+
getNetwork: function() {
4512+
return this.network;
4513+
},
4514+
4515+
/**
4516+
* Get the Linux network device name of the wifi vlan.
4517+
*
4518+
* @returns {string}
4519+
* Returns the current network device name for this wifi vlan.
4520+
*/
4521+
getIfname: function() {
4522+
return this.ifname;
4523+
},
4524+
4525+
/**
4526+
* Get a long description string for the wifi vlan.
4527+
*
4528+
* @returns {string}
4529+
* Returns a string containing the vlan id and the vlan name,
4530+
* if it is different than the vlan id
4531+
*/
4532+
getI18n: function() {
4533+
var name = this.name && this.name != this.vid ? ' (' + this.name + ')' : '';
4534+
return 'vlan %d%s'.format(this.vid, name);
4535+
},
4536+
});
4537+
44394538
return Network;

modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,25 @@ return view.extend({
765765
])
766766
];
767767

768+
var zones = data[4];
769+
if (bss.vlan) {
770+
var desc = bss.vlan.getI18n();
771+
var vlan_network = bss.vlan.getNetwork();
772+
var vlan_zone;
773+
774+
if (vlan_network && zones)
775+
for (let zone of zones)
776+
if (zone.getNetworks().includes(vlan_network))
777+
vlan_zone = zone;
778+
779+
row[0].insertBefore(
780+
E('div', {
781+
'class' : 'zonebadge',
782+
'title' : desc,
783+
'style' : firewall.getZoneColorStyle(vlan_zone)
784+
}, [ desc ]), row[0].firstChild);
785+
}
786+
768787
if (bss.network.isClientDisconnectSupported()) {
769788
if (table.firstElementChild.childNodes.length < 6)
770789
table.firstElementChild.appendChild(E('th', { 'class': 'th cbi-section-actions'}));
@@ -803,7 +822,8 @@ return view.extend({
803822
return Promise.all([
804823
uci.changes(),
805824
uci.load('wireless'),
806-
uci.load('system')
825+
uci.load('system'),
826+
firewall.getZones(),
807827
]);
808828
},
809829

@@ -823,11 +843,11 @@ return view.extend({
823843
params: [ 'config', 'section', 'name' ]
824844
}),
825845

826-
render: function() {
846+
render: function(data) {
827847
if (this.checkAnonymousSections())
828848
return this.renderMigration();
829849
else
830-
return this.renderOverview();
850+
return this.renderOverview(data[3]);
831851
},
832852

833853
handleMigration: function(ev) {
@@ -862,7 +882,7 @@ return view.extend({
862882
]);
863883
},
864884

865-
renderOverview: function() {
885+
renderOverview: function(zones) {
866886
var m, s, o;
867887

868888
m = new form.Map('wireless');
@@ -2404,6 +2424,10 @@ return view.extend({
24042424
return hosts_radios_wifis;
24052425
});
24062426
}, network))
2427+
.then(L.bind(function(zones, data) {
2428+
data.push(zones);
2429+
return data;
2430+
}, network, zones))
24072431
.then(L.bind(this.poll_status, this, nodes));
24082432
}, this), 5);
24092433

modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/60_wifi.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'require uci';
66
'require fs';
77
'require rpc';
8+
'require firewall';
89

910
return baseclass.extend({
1011
title: _('Wireless'),
@@ -184,6 +185,7 @@ return baseclass.extend({
184185
network.getHostHints(),
185186
this.callSessionAccess('access-group', 'luci-mod-status-index-wifi', 'read'),
186187
this.callSessionAccess('access-group', 'luci-mod-status-index-wifi', 'write'),
188+
firewall.getZones(),
187189
L.hasSystemFeature('wifi') ? L.resolveDefault(uci.load('wireless')) : L.resolveDefault(),
188190
]).then(L.bind(function(data) {
189191
var tasks = [],
@@ -216,7 +218,8 @@ return baseclass.extend({
216218
networks = data[1],
217219
hosthints = data[2],
218220
hasReadPermission = data[3],
219-
hasWritePermission = data[4];
221+
hasWritePermission = data[4],
222+
zones = data[5];
220223

221224
var table = E('div', { 'class': 'network-status-table' });
222225

@@ -326,6 +329,24 @@ return baseclass.extend({
326329
])
327330
];
328331

332+
if (bss.vlan) {
333+
var desc = bss.vlan.getI18n();
334+
var vlan_network = bss.vlan.getNetwork();
335+
var vlan_zone;
336+
337+
if (vlan_network)
338+
for (let zone of zones)
339+
if (zone.getNetworks().includes(vlan_network))
340+
vlan_zone = zone;
341+
342+
row[0].insertBefore(
343+
E('div', {
344+
'class' : 'zonebadge',
345+
'title' : desc,
346+
'style' : firewall.getZoneColorStyle(vlan_zone)
347+
}, [ desc ]), row[0].firstChild);
348+
}
349+
329350
if (networks[i].isClientDisconnectSupported() && hasWritePermission) {
330351
if (assoclist.firstElementChild.childNodes.length < 6)
331352
assoclist.firstElementChild.appendChild(E('th', { 'class': 'th cbi-section-actions' }));

0 commit comments

Comments
 (0)