'require baseclass';
'require firewall';
-var proto_errors = {
+const proto_errors = {
CONNECT_FAILED: _('Connection attempt failed'),
INVALID_ADDRESS: _('IP address is invalid'),
INVALID_GATEWAY: _('Gateway address is invalid'),
PIN_FAILED: _('PIN code rejected')
};
-var iface_patterns_ignore = [
+const iface_patterns_ignore = [
/^wmaster\d+/,
/^wifi\d+/,
/^hwsim\d+/,
/^lo$/
];
-var iface_patterns_wireless = [
+const iface_patterns_wireless = [
/^wlan\d+/,
/^wl\d+/,
/^ath\d+/,
/^\w+\.network\d+/
];
-var iface_patterns_virtual = [ ];
+const iface_patterns_virtual = [ ];
-var callLuciNetworkDevices = rpc.declare({
+const callLuciNetworkDevices = rpc.declare({
object: 'luci-rpc',
method: 'getNetworkDevices',
expect: { '': {} }
});
-var callLuciWirelessDevices = rpc.declare({
+const callLuciWirelessDevices = rpc.declare({
object: 'luci-rpc',
method: 'getWirelessDevices',
expect: { '': {} }
});
-var callLuciBoardJSON = rpc.declare({
+const callLuciBoardJSON = rpc.declare({
object: 'luci-rpc',
method: 'getBoardJSON'
});
-var callLuciHostHints = rpc.declare({
+const callLuciHostHints = rpc.declare({
object: 'luci-rpc',
method: 'getHostHints',
expect: { '': {} }
});
-var callIwinfoAssoclist = rpc.declare({
+const callIwinfoAssoclist = rpc.declare({
object: 'iwinfo',
method: 'assoclist',
params: [ 'device', 'mac' ],
expect: { results: [] }
});
-var callIwinfoScan = rpc.declare({
+const callIwinfoScan = rpc.declare({
object: 'iwinfo',
method: 'scan',
params: [ 'device' ],
expect: { results: [] }
});
-var callNetworkInterfaceDump = rpc.declare({
+const callNetworkInterfaceDump = rpc.declare({
object: 'network.interface',
method: 'dump',
expect: { 'interface': [] }
});
-var callNetworkProtoHandlers = rpc.declare({
+const callNetworkProtoHandlers = rpc.declare({
object: 'network',
method: 'get_proto_handlers',
expect: { '': {} }
});
-var _init = null,
- _state = null,
- _protocols = {},
- _protospecs = {};
+let _init = null;
+let _state = null;
+const _protocols = {};
+const _protospecs = {};
-function getProtocolHandlers(cache) {
+function getProtocolHandlers() {
return callNetworkProtoHandlers().then(function(protos) {
/* Prevent attempt to load "protocol/bonding" */
delete protos.bonding;
}
function getWifiStateBySid(sid) {
- var s = uci.get('wireless', sid);
+ const s = uci.get('wireless', sid);
if (s != null && s['.type'] == 'wifi-iface') {
- for (var radioname in _state.radios) {
- for (var i = 0; i < _state.radios[radioname].interfaces.length; i++) {
- var netstate = _state.radios[radioname].interfaces[i];
+ for (let radioname in _state.radios) {
+ for (let netstate of _state.radios[radioname].interfaces) {
if (typeof(netstate.section) != 'string')
continue;
- var s2 = uci.get('wireless', netstate.section);
+ const s2 = uci.get('wireless', netstate.section);
if (s2 != null && s['.type'] == s2['.type'] && s['.name'] == s2['.name']) {
if (s2['.anonymous'] == false && netstate.section.charAt(0) == '@')
}
function getWifiStateByIfname(ifname) {
- for (var radioname in _state.radios) {
- for (var i = 0; i < _state.radios[radioname].interfaces.length; i++) {
- var netstate = _state.radios[radioname].interfaces[i];
+ for (let radioname in _state.radios) {
+ for (let netstate of _state.radios[radioname].interfaces) {
if (typeof(netstate.ifname) != 'string')
continue;
}
function isWifiIfname(ifname) {
- for (var i = 0; i < iface_patterns_wireless.length; i++)
- if (iface_patterns_wireless[i].test(ifname))
+ for (let ifp of iface_patterns_wireless)
+ if (ifp.test(ifname))
return true;
return false;
}
function getWifiSidByNetid(netid) {
- var m = /^(\w+)\.network(\d+)$/.exec(netid);
+ const m = /^(\w+)\.network(\d+)$/.exec(netid);
if (m) {
- var sections = uci.sections('wireless', 'wifi-iface');
- for (var i = 0, n = 0; i < sections.length; i++) {
- if (sections[i].device != m[1])
+ const sections = uci.sections('wireless', 'wifi-iface');
+ let n = 0;
+ for (let s of sections) {
+ if (s.device != m[1])
continue;
if (++n == +m[2])
- return sections[i]['.name'];
+ return s['.name'];
}
}
}
function getWifiSidByIfname(ifname) {
- var sid = getWifiSidByNetid(ifname);
+ const sid = getWifiSidByNetid(ifname);
if (sid != null)
return sid;
- var res = getWifiStateByIfname(ifname);
+ const res = getWifiStateByIfname(ifname);
if (res != null && L.isObject(res[2]) && typeof(res[2].section) == 'string')
return res[2].section;
}
function getWifiNetidBySid(sid) {
- var s = uci.get('wireless', sid);
+ const s = uci.get('wireless', sid);
if (s != null && s['.type'] == 'wifi-iface') {
- var radioname = s.device;
+ const radioname = s.device;
if (typeof(radioname) == 'string') {
- var sections = uci.sections('wireless', 'wifi-iface');
- for (var i = 0, n = 0; i < sections.length; i++) {
- if (sections[i].device != s.device)
+ const sections = uci.sections('wireless', 'wifi-iface');
+ let n = 0;
+ for (let s of sections) {
+ if (s.device != s.device)
continue;
n++;
- if (sections[i]['.name'] != s['.name'])
+ if (s['.name'] != s['.name'])
continue;
return [ '%s.network%d'.format(s.device, n), s.device ];
}
function getWifiNetidByNetname(name) {
- var sections = uci.sections('wireless', 'wifi-iface');
- for (var i = 0; i < sections.length; i++) {
- if (typeof(sections[i].network) != 'string')
+ const sections = uci.sections('wireless', 'wifi-iface');
+ for (let s of sections) {
+ if (typeof(s.network) != 'string')
continue;
- var nets = sections[i].network.split(/\s+/);
- for (var j = 0; j < nets.length; j++) {
- if (nets[j] != name)
+ const nets = s.network.split(/\s+/);
+ for (let n of nets) {
+ if (n != name)
continue;
- return getWifiNetidBySid(sections[i]['.name']);
+ return getWifiNetidBySid(s['.name']);
}
}
}
function isVirtualIfname(ifname) {
- for (var i = 0; i < iface_patterns_virtual.length; i++)
- if (iface_patterns_virtual[i].test(ifname))
+ for (let nfp of iface_patterns_virtual)
+ if (nfp.test(ifname))
return true;
return false;
}
function isIgnoredIfname(ifname) {
- for (var i = 0; i < iface_patterns_ignore.length; i++)
- if (iface_patterns_ignore[i].test(ifname))
+ for (let nfpi of iface_patterns_ignore)
+ if (nfpi.test(ifname))
return true;
return false;
}
function appendValue(config, section, option, value) {
- var values = uci.get(config, section, option),
- isArray = Array.isArray(values),
- rv = false;
+ let values = uci.get(config, section, option);
+ const isArray = Array.isArray(values);
+ let rv = false;
if (isArray == false)
values = L.toArray(values);
}
function removeValue(config, section, option, value) {
- var values = uci.get(config, section, option),
- isArray = Array.isArray(values),
- rv = false;
+ let values = uci.get(config, section, option);
+ const isArray = Array.isArray(values);
+ let rv = false;
if (isArray == false)
values = L.toArray(values);
- for (var i = values.length - 1; i >= 0; i--) {
+ for (let i = values.length - 1; i >= 0; i--) {
if (values[i] == value) {
values.splice(i, 1);
rv = true;
}
function prefixToMask(bits, v6) {
- var w = v6 ? 128 : 32,
- m = [];
+ const w = v6 ? 128 : 32;
+ const m = [];
if (bits > w)
return null;
- for (var i = 0; i < w / 16; i++) {
- var b = Math.min(16, bits);
+ for (let i = 0; i < w / 16; i++) {
+ const b = Math.min(16, bits);
m.push((0xffff << (16 - b)) & 0xffff);
bits -= b;
}
}
function maskToPrefix(mask, v6) {
- var m = v6 ? validation.parseIPv6(mask) : validation.parseIPv4(mask);
+ const m = v6 ? validation.parseIPv6(mask) : validation.parseIPv4(mask);
if (!m)
return null;
- var bits = 0;
+ let bits = 0;
- for (var i = 0, z = false; i < m.length; i++) {
+ for (let i = 0, z = false; i < m.length; i++) {
z = z || !m[i];
while (!z && (m[i] & (v6 ? 0x8000 : 0x80))) {
L.resolveDefault(uci.load('network')),
hasWifi ? L.resolveDefault(uci.load('wireless')) : L.resolveDefault(),
L.resolveDefault(uci.load('luci'))
- ]).then(function(data) {
- var netifd_ifaces = data[0],
- board_json = data[1],
- luci_devs = data[2];
+ ]).then(function([netifd_ifaces, board_json, luci_devs, radios, hosts]) {
- var s = {
+ const s = {
isTunnel: {}, isBridge: {}, isSwitch: {}, isWifi: {},
- ifaces: netifd_ifaces, radios: data[3], hosts: data[4],
+ ifaces: netifd_ifaces, radios: radios, hosts: hosts,
netdevs: {}, bridges: {}, switches: {}, hostapd: {}
};
- for (var name in luci_devs) {
- var dev = luci_devs[name];
+ for (let name in luci_devs) {
+ const dev = luci_devs[name];
if (isVirtualIfname(name))
s.isTunnel[name] = true;
};
if (Array.isArray(dev.ipaddrs))
- for (var i = 0; i < dev.ipaddrs.length; i++)
- s.netdevs[name].ipaddrs.push(dev.ipaddrs[i].address + '/' + dev.ipaddrs[i].netmask);
+ for (let ip of dev.ipaddrs)
+ s.netdevs[name].ipaddrs.push(ip.address + '/' + ip.netmask);
if (Array.isArray(dev.ip6addrs))
- for (var i = 0; i < dev.ip6addrs.length; i++)
- s.netdevs[name].ip6addrs.push(dev.ip6addrs[i].address + '/' + dev.ip6addrs[i].netmask);
+ for (let ip6 of dev.ip6addrs)
+ s.netdevs[name].ip6addrs.push(ip6.address + '/' + ip6.netmask);
}
- for (var name in luci_devs) {
- var dev = luci_devs[name];
+ for (let name in luci_devs) {
+ const dev = luci_devs[name];
if (!dev.bridge)
continue;
- var b = {
+ const b = {
name: name,
id: dev.id,
stp: dev.stp,
ifnames: []
};
- for (var i = 0; dev.ports && i < dev.ports.length; i++) {
- var subdev = s.netdevs[dev.ports[i]];
+ for (let port of dev.ports) {
+ const subdev = s.netdevs[port];
if (subdev == null)
continue;
s.isBridge[name] = true;
}
- for (var name in luci_devs) {
- var dev = luci_devs[name];
+ for (let name in luci_devs) {
+ const dev = luci_devs[name];
if (!dev.parent || dev.devtype != 'dsa')
continue;
}
if (L.isObject(board_json.switch)) {
- for (var switchname in board_json.switch) {
- var layout = board_json.switch[switchname],
- netdevs = {},
- nports = {},
- ports = [],
- pnum = null,
- role = null;
+ for (let switchname in board_json.switch) {
+ const layout = board_json.switch[switchname];
+ const netdevs = {};
+ const nports = {};
+ const ports = [];
+ let pnum = null;
+ let role = null;
if (L.isObject(layout) && Array.isArray(layout.ports)) {
- for (var i = 0, port; (port = layout.ports[i]) != null; i++) {
+ for (let port of layout.ports) {
if (typeof(port) == 'object' && typeof(port.num) == 'number' &&
(typeof(port.role) == 'string' || typeof(port.device) == 'string')) {
- var spec = {
+ const spec = {
num: port.num,
role: port.role || 'cpu',
index: (port.index != null) ? port.index : port.num
return L.naturalCompare(a.role, b.role) || L.naturalCompare(a.index, b.index);
});
- for (var i = 0, port; (port = ports[i]) != null; i++) {
+ for (let port of ports) {
if (port.role != role) {
role = port.role;
pnum = 1;
_init = null;
- var objects = [];
+ const objects = [];
if (L.isObject(s.radios))
- for (var radio in s.radios)
+ for (let radio in s.radios)
if (L.isObject(s.radios[radio]) && Array.isArray(s.radios[radio].interfaces))
- for (var i = 0; i < s.radios[radio].interfaces.length; i++)
- if (L.isObject(s.radios[radio].interfaces[i]) && s.radios[radio].interfaces[i].ifname)
- objects.push('hostapd.%s'.format(s.radios[radio].interfaces[i].ifname));
+ for (let ri of s.radios[radio].interfaces)
+ if (L.isObject(ri) && ri.ifname)
+ objects.push('hostapd.%s'.format(ri.ifname));
return (objects.length ? L.resolveDefault(rpc.list.apply(rpc, objects), {}) : Promise.resolve({})).then(function(res) {
- for (var k in res) {
- var m = k.match(/^hostapd\.(.+)$/);
+ for (let k in res) {
+ const m = k.match(/^hostapd\.(.+)$/);
if (m)
s.hostapd[m[1]] = res[k];
}
}
function deviceSort(a, b) {
- var typeWeigth = { wifi: 2, alias: 3 };
+ const typeWeight = { wifi: 2, alias: 3 };
- return L.naturalCompare(typeWeigth[a.getType()] || 1, typeWeigth[b.getType()] || 1) ||
+ return L.naturalCompare(typeWeight[a.getType()] || 1, typeWeight[b.getType()] || 1) ||
L.naturalCompare(a.getName(), b.getName());
}
if (!enc.enabled)
return 'None';
- var ciphers = Array.isArray(enc.ciphers)
+ const ciphers = Array.isArray(enc.ciphers)
? enc.ciphers.map(function(c) { return c.toUpperCase() }) : [ 'NONE' ];
if (Array.isArray(enc.wep)) {
- var has_open = false,
- has_shared = false;
+ let has_open = false;
+ let has_shared = false;
- for (var i = 0; i < enc.wep.length; i++)
- if (enc.wep[i] == 'open')
+ for (let wencr of enc.wep)
+ if (wencr == 'open')
has_open = true;
- else if (enc.wep[i] == 'shared')
+ else if (wencr == 'shared')
has_shared = true;
if (has_open && has_shared)
}
if (Array.isArray(enc.wpa)) {
- var versions = [],
- suites = Array.isArray(enc.authentication)
+ const versions = [];
+ const suites = Array.isArray(enc.authentication)
? enc.authentication.map(function(a) { return a.toUpperCase() }) : [ 'NONE' ];
- for (var i = 0; i < enc.wpa.length; i++)
- switch (enc.wpa[i]) {
+ for (let encr of enc.wpa)
+ switch (encr) {
case 1:
versions.push('WPA');
break;
default:
- versions.push('WPA%d'.format(enc.wpa[i]));
+ versions.push('WPA%d'.format(encr));
break;
}
}
function enumerateNetworks() {
- var uciInterfaces = uci.sections('network', 'interface'),
- networks = {};
+ const uciInterfaces = uci.sections('network', 'interface');
+ const networks = {};
- for (var i = 0; i < uciInterfaces.length; i++)
- networks[uciInterfaces[i]['.name']] = this.instantiateNetwork(uciInterfaces[i]['.name']);
+ for (let intf of uciInterfaces)
+ networks[intf['.name']] = this.instantiateNetwork(intf['.name']);
- for (var i = 0; i < _state.ifaces.length; i++)
- if (networks[_state.ifaces[i].interface] == null)
- networks[_state.ifaces[i].interface] =
- this.instantiateNetwork(_state.ifaces[i].interface, _state.ifaces[i].proto);
+ for (let ifstate of _state.ifaces)
+ if (networks[ifstate.interface] == null)
+ networks[ifstate.interface] =
+ this.instantiateNetwork(ifstate.interface, ifstate.proto);
- var rv = [];
+ const rv = [];
- for (var network in networks)
+ for (let network in networks)
if (networks.hasOwnProperty(network))
rv.push(networks[network]);
}
-var Hosts, Network, Protocol, Device, WifiDevice, WifiNetwork, WifiVlan;
+let Hosts, Network, Protocol, Device, WifiDevice, WifiNetwork, WifiVlan;
/**
* @namespace LuCI.network
* @returns {Promise<Object>}
* Returns a promise resolving to the internal network state object.
*/
- flushCache: function() {
+ flushCache() {
initNetworkState(true);
return _init;
},
* Returns the instantiated protocol back-end class or `null` if the given
* protocol isn't known.
*/
- getProtocol: function(protoname, netname) {
- var v = _protocols[protoname];
+ getProtocol(protoname, netname) {
+ const v = _protocols[protoname];
if (v != null)
return new v(netname || '__dummy__');
* @returns {Array<LuCI.network.Protocol>}
* Returns an array of protocol class instances.
*/
- getProtocols: function() {
- var rv = [];
+ getProtocols() {
+ const rv = [];
- for (var protoname in _protocols)
+ for (let protoname in _protocols)
rv.push(new _protocols[protoname]('__dummy__'));
return rv;
* @returns {LuCI.network.Protocol}
* Returns the new `Protocol` subclass.
*/
- registerProtocol: function(protoname, methods) {
- var spec = L.isObject(_protospecs) ? _protospecs[protoname] : null;
- var proto = Protocol.extend(Object.assign({
- getI18n: function() {
+ registerProtocol(protoname, methods) {
+ const spec = L.isObject(_protospecs) ? _protospecs[protoname] : null;
+ const proto = Protocol.extend(Object.assign({
+ getI18n() {
return protoname;
},
- isFloating: function() {
+ isFloating() {
return false;
},
- isVirtual: function() {
+ isVirtual() {
return (L.isObject(spec) && spec.no_device == true);
},
- renderFormOptions: function(section) {
+ renderFormOptions(section) {
}
}, methods, {
- __init__: function(name) {
+ __init__(name) {
this.sid = name;
},
- getProtocol: function() {
+ getProtocol() {
return protoname;
}
}));
* A `RegExp` instance to match a virtual interface name
* such as `6in4-wan` or `tun0`.
*/
- registerPatternVirtual: function(pat) {
+ registerPatternVirtual(pat) {
iface_patterns_virtual.push(pat);
},
* if either the arguments were invalid or if there already was a
* description for the given code.
*/
- registerErrorCode: function(code, message) {
+ registerErrorCode(code, message) {
if (typeof(code) == 'string' &&
typeof(message) == 'string' &&
!proto_errors.hasOwnProperty(code)) {
* was invalid or if a non-empty network of the given name already
* existed.
*/
- addNetwork: function(name, options) {
+ addNetwork(name, options) {
return this.getNetwork(name).then(L.bind(function(existingNetwork) {
if (name != null && /^[a-zA-Z0-9_]+$/.test(name) && existingNetwork == null) {
- var sid = uci.add('network', 'interface', name);
+ const sid = uci.add('network', 'interface', name);
if (sid != null) {
if (L.isObject(options))
- for (var key in options)
+ for (let key in options)
if (options.hasOwnProperty(key))
uci.set('network', sid, key, options[key]);
}
else if (existingNetwork != null && existingNetwork.isEmpty()) {
if (L.isObject(options))
- for (var key in options)
+ for (let key in options)
if (options.hasOwnProperty(key))
existingNetwork.set(key, options[key]);
* {@link LuCI.network.Protocol Protocol} subclass instance describing
* the network or `null` if the network did not exist.
*/
- getNetwork: function(name) {
+ getNetwork(name) {
return initNetworkState().then(L.bind(function() {
- var section = (name != null) ? uci.get('network', name) : null;
+ const section = (name != null) ? uci.get('network', name) : null;
if (section != null && section['.type'] == 'interface') {
return this.instantiateNetwork(name);
}
else if (name != null) {
- for (var i = 0; i < _state.ifaces.length; i++)
- if (_state.ifaces[i].interface == name)
- return this.instantiateNetwork(name, _state.ifaces[i].proto);
+ for (let ifc of _state.ifaces)
+ if (ifc.interface == name)
+ return this.instantiateNetwork(name, ifc.proto);
}
return null;
* {@link LuCI.network.Protocol Protocol} subclass instances
* describing all known networks.
*/
- getNetworks: function() {
+ getNetworks() {
return initNetworkState().then(L.bind(enumerateNetworks, this));
},
* references to it were successfully deleted from the configuration or
* `false` if the given network could not be found.
*/
- deleteNetwork: function(name) {
- var requireFirewall = Promise.resolve(L.require('firewall')).catch(function() {}),
- loadDHCP = L.resolveDefault(uci.load('dhcp')),
- network = this.instantiateNetwork(name);
+ deleteNetwork(name) {
+ const requireFirewall = Promise.resolve(L.require('firewall')).catch(function() {});
+ const loadDHCP = L.resolveDefault(uci.load('dhcp'));
+ const network = this.instantiateNetwork(name);
return Promise.all([ requireFirewall, loadDHCP, initNetworkState() ]).then(function(res) {
- var uciInterface = uci.get('network', name),
- firewall = res[0];
+ const uciInterface = uci.get('network', name);
+ const firewall = res[0];
if (uciInterface != null && uciInterface['.type'] == 'interface') {
return Promise.resolve(network ? network.deleteConfiguration() : null).then(function() {
});
uci.sections('wireless', 'wifi-iface', function(s) {
- var networks = L.toArray(s.network).filter(function(network) { return network != name });
+ const networks = L.toArray(s.network).filter(function(network) { return network != name });
if (networks.length > 0)
uci.set('wireless', s['.name'], 'network', networks.join(' '));
* a network with the new name already exists or if the network to
* rename could not be found.
*/
- renameNetwork: function(oldName, newName) {
+ renameNetwork(oldName, newName) {
return initNetworkState().then(function() {
if (newName == null || !/^[a-zA-Z0-9_]+$/.test(newName) || uci.get('network', newName) != null)
return false;
- var oldNetwork = uci.get('network', oldName);
+ const oldNetwork = uci.get('network', oldName);
if (oldNetwork == null || oldNetwork['.type'] != 'interface')
return false;
- var sid = uci.add('network', 'interface', newName);
+ const sid = uci.add('network', 'interface', newName);
- for (var key in oldNetwork)
+ for (let key in oldNetwork)
if (oldNetwork.hasOwnProperty(key) && key.charAt(0) != '.')
uci.set('network', sid, key, oldNetwork[key]);
});
uci.sections('wireless', 'wifi-iface', function(s) {
- var networks = L.toArray(s.network).map(function(network) { return (network == oldName ? newName : network) });
+ const networks = L.toArray(s.network).map(function(network) { return (network == oldName ? newName : network) });
if (networks.length > 0)
uci.set('wireless', s['.name'], 'network', networks.join(' '));
* the network device or `null` if the given device name could not
* be found.
*/
- getDevice: function(name) {
+ getDevice(name) {
return initNetworkState().then(L.bind(function() {
if (name == null)
return null;
if (_state.netdevs.hasOwnProperty(name))
return this.instantiateDevice(name);
- var netid = getWifiNetidBySid(name);
+ const netid = getWifiNetidBySid(name);
if (netid != null)
return this.instantiateDevice(netid[0]);
* Returns a promise resolving to a sorted array of `Device` class
* instances describing the network devices found on the system.
*/
- getDevices: function() {
+ getDevices() {
return initNetworkState().then(L.bind(function() {
- var devices = {};
+ const devices = {};
/* find simple devices */
- var uciInterfaces = uci.sections('network', 'interface');
- for (var i = 0; i < uciInterfaces.length; i++) {
- var ifnames = L.toArray(uciInterfaces[i].ifname);
+ const uciInterfaces = uci.sections('network', 'interface');
+ for (let uif of uciInterfaces) {
+ const ifnames = L.toArray(uif.ifname);
- for (var j = 0; j < ifnames.length; j++) {
- if (ifnames[j].charAt(0) == '@')
+ for (let ifn of ifnames) {
+ if (ifn.charAt(0) == '@')
continue;
- if (isIgnoredIfname(ifnames[j]) || isVirtualIfname(ifnames[j]) || isWifiIfname(ifnames[j]))
+ if (isIgnoredIfname(ifn) || isVirtualIfname(ifn) || isWifiIfname(ifn))
continue;
- devices[ifnames[j]] = this.instantiateDevice(ifnames[j]);
+ devices[ifn] = this.instantiateDevice(ifn);
}
}
- for (var ifname in _state.netdevs) {
+ for (let ifname in _state.netdevs) {
if (devices.hasOwnProperty(ifname))
continue;
}
/* find VLAN devices */
- var uciSwitchVLANs = uci.sections('network', 'switch_vlan');
- for (var i = 0; i < uciSwitchVLANs.length; i++) {
- if (typeof(uciSwitchVLANs[i].ports) != 'string' ||
- typeof(uciSwitchVLANs[i].device) != 'string' ||
- !_state.switches.hasOwnProperty(uciSwitchVLANs[i].device))
+ const uciSwitchVLANs = uci.sections('network', 'switch_vlan');
+ for (let sw of uciSwitchVLANs) {
+ if (typeof(sw.ports) != 'string' ||
+ typeof(sw.device) != 'string' ||
+ !_state.switches.hasOwnProperty(sw.device))
continue;
- var ports = uciSwitchVLANs[i].ports.split(/\s+/);
- for (var j = 0; j < ports.length; j++) {
- var m = ports[j].match(/^(\d+)([tu]?)$/);
+ const ports = sw.ports.split(/\s+/);
+ for (let p of ports) {
+ let m = p.match(/^(\d+)([tu]?)$/);
if (m == null)
continue;
- var netdev = _state.switches[uciSwitchVLANs[i].device].netdevs[m[1]];
+ let netdev = _state.switches[sw.device].netdevs[m[1]];
if (netdev == null)
continue;
if (m[2] != 't')
continue;
- var vid = uciSwitchVLANs[i].vid || uciSwitchVLANs[i].vlan;
+ let vid = sw.vid || sw.vlan;
vid = (vid != null ? +vid : null);
if (vid == null || vid < 0 || vid > 4095)
continue;
- var vlandev = '%s.%d'.format(netdev, vid);
+ const vlandev = '%s.%d'.format(netdev, vid);
if (!devices.hasOwnProperty(vlandev))
devices[vlandev] = this.instantiateDevice(vlandev);
}
/* find bridge VLAN devices */
- var uciBridgeVLANs = uci.sections('network', 'bridge-vlan');
- for (var i = 0; i < uciBridgeVLANs.length; i++) {
- var basedev = uciBridgeVLANs[i].device,
- local = uciBridgeVLANs[i].local,
- alias = uciBridgeVLANs[i].alias,
- vid = +uciBridgeVLANs[i].vlan,
- ports = L.toArray(uciBridgeVLANs[i].ports);
+ const uciBridgeVLANs = uci.sections('network', 'bridge-vlan');
+ for (let bvl of uciBridgeVLANs) {
+ const basedev = bvl.device;
+ const local = bvl.local;
+ const alias = bvl.alias;
+ const vid = +bvl.vlan;
+ const ports = L.toArray(bvl.ports);
if (local == '0')
continue;
if (isNaN(vid) || vid < 0 || vid > 4095)
continue;
- var vlandev = '%s.%s'.format(basedev, alias || vid);
+ const vlandev = '%s.%s'.format(basedev, alias || vid);
_state.isBridge[basedev] = true;
devices[vlandev] = this.instantiateDevice(vlandev);
ports.forEach(function(port_name) {
- var m = port_name.match(/^([^:]+)(?::[ut*]+)?$/),
- p = m ? m[1] : null;
+ const m = port_name.match(/^([^:]+)(?::[ut*]+)?$/);
+ const p = m ? m[1] : null;
if (!p)
return;
}
/* find wireless interfaces */
- var uciWifiIfaces = uci.sections('wireless', 'wifi-iface'),
- networkCount = {};
+ const uciWifiIfaces = uci.sections('wireless', 'wifi-iface');
+ const networkCount = {};
- for (var i = 0; i < uciWifiIfaces.length; i++) {
- if (typeof(uciWifiIfaces[i].device) != 'string')
+ for (let wf_if of uciWifiIfaces) {
+ if (typeof(wf_if.device) != 'string')
continue;
- networkCount[uciWifiIfaces[i].device] = (networkCount[uciWifiIfaces[i].device] || 0) + 1;
+ networkCount[wf_if.device] = (networkCount[wf_if.device] || 0) + 1;
- var netid = '%s.network%d'.format(uciWifiIfaces[i].device, networkCount[uciWifiIfaces[i].device]);
+ const netid = '%s.network%d'.format(wf_if.device, networkCount[wf_if.device]);
devices[netid] = this.instantiateDevice(netid);
}
/* find uci declared devices */
- var uciDevices = uci.sections('network', 'device');
+ const uciDevices = uci.sections('network', 'device');
- for (var i = 0; i < uciDevices.length; i++) {
- var type = uciDevices[i].type,
- name = uciDevices[i].name;
+ for (let d of uciDevices) {
+ const type = d.type;
+ const name = d.name;
if (!type || !name || devices.hasOwnProperty(name))
continue;
devices[name] = this.instantiateDevice(name);
}
- var rv = [];
+ const rv = [];
- for (var netdev in devices)
+ for (let netdev in devices)
if (devices.hasOwnProperty(netdev))
rv.push(devices[netdev]);
* Returns `true` if the given name is in the ignore-pattern list,
* else returns `false`.
*/
- isIgnoredDevice: function(name) {
+ isIgnoredDevice(name) {
return isIgnoredIfname(name);
},
* the underlying radio device or `null` if the wireless radio could not
* be found.
*/
- getWifiDevice: function(devname) {
+ getWifiDevice(devname) {
return initNetworkState().then(L.bind(function() {
- var existingDevice = uci.get('wireless', devname);
+ const existingDevice = uci.get('wireless', devname);
if (existingDevice == null || existingDevice['.type'] != 'wifi-device')
return null;
* The order of the array corresponds to the order of the radios in
* the configuration.
*/
- getWifiDevices: function() {
+ getWifiDevices() {
return initNetworkState().then(L.bind(function() {
- var uciWifiDevices = uci.sections('wireless', 'wifi-device'),
- rv = [];
+ const uciWifiDevices = uci.sections('wireless', 'wifi-device');
+ const rv = [];
- for (var i = 0; i < uciWifiDevices.length; i++) {
- var devname = uciWifiDevices[i]['.name'];
+ for (let wfd of uciWifiDevices) {
+ const devname = wfd['.name'];
rv.push(this.instantiateWifiDevice(devname, _state.radios[devname] || {}));
}
* the wireless network or `null` if the corresponding network could not
* be found.
*/
- getWifiNetwork: function(netname) {
+ getWifiNetwork(netname) {
return initNetworkState()
.then(L.bind(this.lookupWifiNetwork, this, netname));
},
* describing the wireless networks. The array will be empty if no networks
* are found.
*/
- getWifiNetworks: function() {
+ getWifiNetworks() {
return initNetworkState().then(L.bind(function() {
- var wifiIfaces = uci.sections('wireless', 'wifi-iface'),
- rv = [];
+ const wifiIfaces = uci.sections('wireless', 'wifi-iface');
+ const rv = [];
- for (var i = 0; i < wifiIfaces.length; i++)
- rv.push(this.lookupWifiNetwork(wifiIfaces[i]['.name']));
+ for (let wf_if of wifiIfaces)
+ rv.push(this.lookupWifiNetwork(wf_if['.name']));
rv.sort(function(a, b) {
return L.naturalCompare(a.getID(), b.getID());
* the newly added wireless network or `null` if the given options
* were invalid or if the associated radio device could not be found.
*/
- addWifiNetwork: function(options) {
+ addWifiNetwork(options) {
return initNetworkState().then(L.bind(function() {
if (options == null ||
typeof(options) != 'object' ||
typeof(options.device) != 'string')
return null;
- var existingDevice = uci.get('wireless', options.device);
+ const existingDevice = uci.get('wireless', options.device);
if (existingDevice == null || existingDevice['.type'] != 'wifi-device')
return null;
/* XXX: need to add a named section (wifinet#) here */
- var sid = uci.add('wireless', 'wifi-iface');
- for (var key in options)
+ const sid = uci.add('wireless', 'wifi-iface');
+ for (let key in options)
if (options.hasOwnProperty(key))
uci.set('wireless', sid, key, options[key]);
- var radioname = existingDevice['.name'],
- netid = getWifiNetidBySid(sid) || [];
+ const radioname = existingDevice['.name'];
+ const netid = getWifiNetidBySid(sid) || [];
return this.instantiateWifiNetwork(sid, radioname, _state.radios[radioname], netid[0], null);
}, this));
* successfully deleted from the configuration or `false` if it could not
* be found.
*/
- deleteWifiNetwork: function(netname) {
+ deleteWifiNetwork(netname) {
return initNetworkState().then(L.bind(function() {
- var sid = getWifiSidByIfname(netname);
+ const sid = getWifiSidByIfname(netname);
if (sid == null)
return false;
},
/* private */
- getStatusByRoute: function(addr, mask) {
+ getStatusByRoute(addr, mask) {
return initNetworkState().then(L.bind(function() {
- var rv = [];
+ const rv = [];
- for (var i = 0; i < _state.ifaces.length; i++) {
- if (!Array.isArray(_state.ifaces[i].route))
+ for (let sif of _state.ifaces) {
+ if (!Array.isArray(sif.route))
continue;
- for (var j = 0; j < _state.ifaces[i].route.length; j++) {
- if (typeof(_state.ifaces[i].route[j]) != 'object' ||
- typeof(_state.ifaces[i].route[j].target) != 'string' ||
- typeof(_state.ifaces[i].route[j].mask) != 'number')
+ for (let sifr of sif.route) {
+ if (typeof(sifr) != 'object' ||
+ typeof(sifr.target) != 'string' ||
+ typeof(sifr.mask) != 'number')
continue;
- if (_state.ifaces[i].route[j].table)
+ if (sifr.table)
continue;
- if (_state.ifaces[i].route[j].target != addr ||
- _state.ifaces[i].route[j].mask != mask)
+ if (sifr.target != addr ||
+ sifr.mask != mask)
continue;
- rv.push(_state.ifaces[i]);
+ rv.push(sif);
}
}
},
/* private */
- getStatusByAddress: function(addr) {
+ getStatusByAddress(addr) {
return initNetworkState().then(L.bind(function() {
- var rv = [];
-
- for (var i = 0; i < _state.ifaces.length; i++) {
- if (Array.isArray(_state.ifaces[i]['ipv4-address']))
- for (var j = 0; j < _state.ifaces[i]['ipv4-address'].length; j++)
- if (typeof(_state.ifaces[i]['ipv4-address'][j]) == 'object' &&
- _state.ifaces[i]['ipv4-address'][j].address == addr)
- return _state.ifaces[i];
-
- if (Array.isArray(_state.ifaces[i]['ipv6-address']))
- for (var j = 0; j < _state.ifaces[i]['ipv6-address'].length; j++)
- if (typeof(_state.ifaces[i]['ipv6-address'][j]) == 'object' &&
- _state.ifaces[i]['ipv6-address'][j].address == addr)
- return _state.ifaces[i];
-
- if (Array.isArray(_state.ifaces[i]['ipv6-prefix-assignment']))
- for (var j = 0; j < _state.ifaces[i]['ipv6-prefix-assignment'].length; j++)
- if (typeof(_state.ifaces[i]['ipv6-prefix-assignment'][j]) == 'object' &&
- typeof(_state.ifaces[i]['ipv6-prefix-assignment'][j]['local-address']) == 'object' &&
- _state.ifaces[i]['ipv6-prefix-assignment'][j]['local-address'].address == addr)
- return _state.ifaces[i];
+ for (let sif of _state.ifaces) {
+ if (Array.isArray(sif['ipv4-address']))
+ for (let a of sif['ipv4-address'])
+ if (typeof(a) == 'object' &&
+ a.address == addr)
+ return sif;
+
+ if (Array.isArray(sif['ipv6-address']))
+ for (let a of sif['ipv6-address'])
+ if (typeof(a) == 'object' &&
+ a.address == addr)
+ return sif;
+
+ if (Array.isArray(sif['ipv6-prefix-assignment']))
+ for (let a of sif['ipv6-prefix-assignment'])
+ if (typeof(a) == 'object' &&
+ typeof(a['local-address']) == 'object' &&
+ a['local-address'].address == addr)
+ return sif;
}
return null;
* Returns a promise resolving to an array of `Protocol` subclass
* instances describing the found default route interfaces.
*/
- getWANNetworks: function() {
+ getWANNetworks() {
return this.getStatusByRoute('0.0.0.0', 0).then(L.bind(function(statuses) {
- var rv = [], seen = {};
+ const rv = [], seen = {};
- for (var i = 0; i < statuses.length; i++) {
- if (!seen.hasOwnProperty(statuses[i].interface)) {
- rv.push(this.instantiateNetwork(statuses[i].interface, statuses[i].proto));
- seen[statuses[i].interface] = true;
+ for (let s of statuses) {
+ if (!seen.hasOwnProperty(s.interface)) {
+ rv.push(this.instantiateNetwork(s.interface, s.proto));
+ seen[s.interface] = true;
}
}
* Returns a promise resolving to an array of `Protocol` subclass
* instances describing the found IPv6 default route interfaces.
*/
- getWAN6Networks: function() {
+ getWAN6Networks() {
return this.getStatusByRoute('::', 0).then(L.bind(function(statuses) {
- var rv = [], seen = {};
+ const rv = [], seen = {};
- for (var i = 0; i < statuses.length; i++) {
- if (!seen.hasOwnProperty(statuses[i].interface)) {
- rv.push(this.instantiateNetwork(statuses[i].interface, statuses[i].proto));
- seen[statuses[i].interface] = true;
+ for (let s of statuses) {
+ if (!seen.hasOwnProperty(s.interface)) {
+ rv.push(this.instantiateNetwork(s.interface, s.proto));
+ seen[s.interface] = true;
}
}
* {@link LuCI.network.SwitchTopology SwitchTopology} objects describing
* the layout.
*/
- getSwitchTopologies: function() {
+ getSwitchTopologies() {
return initNetworkState().then(function() {
return _state.switches;
});
},
/* private */
- instantiateNetwork: function(name, proto) {
+ instantiateNetwork(name, proto) {
if (name == null)
return null;
proto = (proto == null ? (uci.get('network', name, 'proto') || 'none') : proto);
- var protoClass = _protocols[proto] || Protocol;
+ const protoClass = _protocols[proto] || Protocol;
return new protoClass(name);
},
/* private */
- instantiateDevice: function(name, network, extend) {
+ instantiateDevice(name, network, extend) {
if (extend != null)
return new (Device.extend(extend))(name, network);
},
/* private */
- instantiateWifiDevice: function(radioname, radiostate) {
+ instantiateWifiDevice(radioname, radiostate) {
return new WifiDevice(radioname, radiostate);
},
/* private */
- instantiateWifiNetwork: function(sid, radioname, radiostate, netid, netstate, hostapd) {
+ instantiateWifiNetwork(sid, radioname, radiostate, netid, netstate, hostapd) {
return new WifiNetwork(sid, radioname, radiostate, netid, netstate, hostapd);
},
/* private */
- lookupWifiNetwork: function(netname) {
- var sid, res, netid, radioname, radiostate, netstate;
+ lookupWifiNetwork(netname) {
+ let sid, res, netid, radioname, radiostate, netstate;
sid = getWifiSidByNetid(netname);
* Returns a string containing the device name or `null` if the given
* object could not be converted to a name.
*/
- getIfnameOf: function(obj) {
+ getIfnameOf(obj) {
return ifnameOf(obj);
},
* Returns a promise resolving to the type of the internal modem
* (e.g. `vdsl`) or to `null` if no internal modem is present.
*/
- getDSLModemType: function() {
+ getDSLModemType() {
return initNetworkState().then(function() {
return _state.hasDSLModem ? _state.hasDSLModem.type : null;
});
* @returns {Promise<LuCI.network.Hosts>}
* Returns a `Hosts` instance describing a host known on the system.
*/
- getHostHints: function() {
+ getHostHints() {
return initNetworkState().then(function() {
return new Hosts(_state.hosts);
});
* host information by different criteria.
*/
Hosts = baseclass.extend(/** @lends LuCI.network.Hosts.prototype */ {
- __init__: function(hosts) {
+ __init__(hosts) {
this.hosts = hosts;
},
* no matching host could be found or if no hostname is known for
* the corresponding host.
*/
- getHostnameByMACAddr: function(mac) {
+ getHostnameByMACAddr(mac) {
return this.hosts[mac]
? (this.hosts[mac].name || null)
: null;
* no matching host could be found or if no IPv4 address is known for
* the corresponding host.
*/
- getIPAddrByMACAddr: function(mac) {
+ getIPAddrByMACAddr(mac) {
return this.hosts[mac]
? (L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4)[0] || null)
: null;
* no matching host could be found or if no IPv6 address is known for
* the corresponding host.
*/
- getIP6AddrByMACAddr: function(mac) {
+ getIP6AddrByMACAddr(mac) {
return this.hosts[mac]
? (L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6)[0] || null)
: null;
* no matching host could be found or if no hostname is known for
* the corresponding host.
*/
- getHostnameByIPAddr: function(ipaddr) {
- for (var mac in this.hosts) {
+ getHostnameByIPAddr(ipaddr) {
+ for (let mac in this.hosts) {
if (this.hosts[mac].name == null)
continue;
- var addrs = L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4);
+ const addrs = L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4);
- for (var i = 0; i < addrs.length; i++)
- if (addrs[i] == ipaddr)
+ for (let a of addrs)
+ if (a == ipaddr)
return this.hosts[mac].name;
}
* no matching host could be found or if no MAC address is known for
* the corresponding host.
*/
- getMACAddrByIPAddr: function(ipaddr) {
- for (var mac in this.hosts) {
- var addrs = L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4);
+ getMACAddrByIPAddr(ipaddr) {
+ for (let mac in this.hosts) {
+ const addrs = L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4);
- for (var i = 0; i < addrs.length; i++)
- if (addrs[i] == ipaddr)
+ for (let a of addrs)
+ if (a == ipaddr)
return mac;
}
* no matching host could be found or if no hostname is known for
* the corresponding host.
*/
- getHostnameByIP6Addr: function(ip6addr) {
- for (var mac in this.hosts) {
+ getHostnameByIP6Addr(ip6addr) {
+ for (let mac in this.hosts) {
if (this.hosts[mac].name == null)
continue;
- var addrs = L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6);
+ const addrs = L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6);
- for (var i = 0; i < addrs.length; i++)
- if (addrs[i] == ip6addr)
+ for (let a of addrs)
+ if (a == ip6addr)
return this.hosts[mac].name;
}
* no matching host could be found or if no MAC address is known for
* the corresponding host.
*/
- getMACAddrByIP6Addr: function(ip6addr) {
- for (var mac in this.hosts) {
- var addrs = L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6);
+ getMACAddrByIP6Addr(ip6addr) {
+ for (let mac in this.hosts) {
+ const addrs = L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6);
- for (var i = 0; i < addrs.length; i++)
- if (addrs[i] == ip6addr)
+ for (let a of addrs)
+ if (a == ip6addr)
return mac;
}
* `preferIP6` flag specifies whether the IPv6 or the IPv4 address
* is used as hint.
*/
- getMACHints: function(preferIp6) {
- var rv = [];
+ getMACHints(preferIp6) {
+ const rv = [];
- for (var mac in this.hosts) {
- var hint = this.hosts[mac].name ||
+ for (let mac in this.hosts) {
+ const hint = this.hosts[mac].name ||
L.toArray(this.hosts[mac][preferIp6 ? 'ip6addrs' : 'ipaddrs'] || this.hosts[mac][preferIp6 ? 'ipv6' : 'ipv4'])[0] ||
L.toArray(this.hosts[mac][preferIp6 ? 'ipaddrs' : 'ip6addrs'] || this.hosts[mac][preferIp6 ? 'ipv4' : 'ipv6'])[0];
* interface` sections in `/etc/config/network`.
*/
Protocol = baseclass.extend(/** @lends LuCI.network.Protocol.prototype */ {
- __init__: function(name) {
+ __init__(name) {
this.sid = name;
},
- _get: function(opt) {
- var val = uci.get('network', this.sid, opt);
+ _get(opt) {
+ const val = uci.get('network', this.sid, opt);
if (Array.isArray(val))
return val.join(' ');
return val || '';
},
- _ubus: function(field) {
- for (var i = 0; i < _state.ifaces.length; i++) {
- if (_state.ifaces[i].interface != this.sid)
+ _ubus(field) {
+ for (let sif of _state.ifaces) {
+ if (sif.interface != this.sid)
continue;
- return (field != null ? _state.ifaces[i][field] : _state.ifaces[i]);
+ return (field != null ? sif[field] : sif);
}
},
* Returns the UCI option value or `null` if the requested option is
* not found.
*/
- get: function(opt) {
+ get(opt) {
return uci.get('network', this.sid, opt);
},
* configuration.
* @returns {null}
*/
- set: function(opt, val) {
+ set(opt, val) {
return uci.set('network', this.sid, opt, val);
},
* Returns the name of the associated network device or `null` if
* it could not be determined.
*/
- getIfname: function() {
- var ifname;
+ getIfname() {
+ let ifname;
if (this.isFloating())
ifname = this._ubus('l3_device');
if (ifname != null)
return ifname;
- var res = getWifiNetidByNetname(this.sid);
+ const res = getWifiNetidByNetname(this.sid);
return (res != null ? res[0] : null);
},
* Returns the name of the network protocol implementation, e.g.
* `static` or `dhcp`.
*/
- getProtocol: function() {
+ getProtocol() {
return null;
},
* @returns {string}
* Returns the description string.
*/
- getI18n: function() {
+ getI18n() {
switch (this.getProtocol()) {
case 'none': return _('Unmanaged');
case 'static': return _('Static address');
* Returns the value of the `type` option of the associated logical
* interface or `null` if no `type` option is set.
*/
- getType: function() {
+ getType() {
return this._get('type');
},
* @returns {string}
* Returns the logical interface name, such as `lan` or `wan`.
*/
- getName: function() {
+ getName() {
return this.sid;
},
* @returns {number}
* Returns the uptime of the associated interface in seconds.
*/
- getUptime: function() {
+ getUptime() {
return this._ubus('uptime') || 0;
},
* Returns the number of seconds until the lease expires or `-1`
* if it isn't applicable to the associated protocol.
*/
- getExpiry: function() {
- var u = this._ubus('uptime'),
- d = this._ubus('data'),
- v6_prefixes = this._ubus('ipv6-prefix'),
- v6_addresses = this._ubus('ipv6-address');
+ getExpiry() {
+ const u = this._ubus('uptime');
+ const d = this._ubus('data');
+ const v6_prefixes = this._ubus('ipv6-prefix');
+ const v6_addresses = this._ubus('ipv6-address');
if (typeof(u) == 'number' && d != null) {
// DHCPv4 or leasetime in data
if(typeof(d) == 'object' && typeof(d.leasetime) == 'number') {
- var r = d.leasetime - (u % d.leasetime);
+ const r = d.leasetime - (u % d.leasetime);
return (r > 0 ? r : 0);
}
// DHCPv6, we can have multiple IPs and prefixes
if (Array.isArray(v6_prefixes) || Array.isArray(v6_addresses)) {
- var prefixes = [...v6_prefixes, ...v6_addresses];
+ const prefixes = [...v6_prefixes, ...v6_addresses];
if(prefixes.length && typeof(prefixes[0].valid) == 'number') {
- var r = prefixes[0].valid;
+ const r = prefixes[0].valid;
return (r > 0 ? r : 0);
}
}
* Returns the current metric value used for device and network
* routes spawned by the associated logical interface.
*/
- getMetric: function() {
+ getMetric() {
return this._ubus('metric') || 0;
},
* `ubus` runtime information or `null` if the remote protocol
* handler didn't request a zone.
*/
- getZoneName: function() {
- var d = this._ubus('data');
+ getZoneName() {
+ const d = this._ubus('data');
if (L.isObject(d) && typeof(d.zone) == 'string')
return d.zone;
* Returns the primary IPv4 address registered by the protocol handler
* or `null` if no IPv4 addresses were set.
*/
- getIPAddr: function() {
- var addrs = this._ubus('ipv4-address');
+ getIPAddr() {
+ const addrs = this._ubus('ipv4-address');
return ((Array.isArray(addrs) && addrs.length) ? addrs[0].address : null);
},
* registered by the protocol handler. The order of the resulting array
* follows the order of the addresses in `ubus` runtime information.
*/
- getIPAddrs: function() {
- var addrs = this._ubus('ipv4-address'),
- rv = [];
+ getIPAddrs() {
+ const addrs = this._ubus('ipv4-address');
+ const rv = [];
if (Array.isArray(addrs))
- for (var i = 0; i < addrs.length; i++)
- rv.push('%s/%d'.format(addrs[i].address, addrs[i].mask));
+ for (let a of addrs)
+ rv.push('%s/%d'.format(a.address, a.mask));
return rv;
},
* Returns the netmask of the primary IPv4 address registered by the
* protocol handler or `null` if no IPv4 addresses were set.
*/
- getNetmask: function() {
- var addrs = this._ubus('ipv4-address');
+ getNetmask() {
+ const addrs = this._ubus('ipv4-address');
if (Array.isArray(addrs) && addrs.length)
return prefixToMask(addrs[0].mask, false);
},
* Returns a string containing the IPv4 nexthop address of the associated
* default route or `null` if no default route was found.
*/
- getGatewayAddr: function() {
- var routes = this._ubus('route');
+ getGatewayAddr() {
+ const routes = this._ubus('route');
if (Array.isArray(routes))
- for (var i = 0; i < routes.length; i++)
- if (typeof(routes[i]) == 'object' &&
- routes[i].target == '0.0.0.0' &&
- routes[i].mask == 0)
- return routes[i].nexthop;
+ for (let r of routes)
+ if (typeof(r) == 'object' &&
+ r.target == '0.0.0.0' &&
+ r.mask == 0)
+ return r.nexthop;
return null;
},
* Returns an array of IPv4 DNS servers registered by the remote
* protocol back-end.
*/
- getDNSAddrs: function() {
- var addrs = this._ubus('dns-server'),
- rv = [];
+ getDNSAddrs() {
+ const addrs = this._ubus('dns-server');
+ const rv = [];
if (Array.isArray(addrs))
- for (var i = 0; i < addrs.length; i++)
- if (!/:/.test(addrs[i]))
- rv.push(addrs[i]);
+ for (let a of addrs)
+ if (!/:/.test(a))
+ rv.push(a);
return rv;
},
* Returns the primary IPv6 address registered by the protocol handler
* in CIDR notation or `null` if no IPv6 addresses were set.
*/
- getIP6Addr: function() {
- var addrs = this._ubus('ipv6-address');
+ getIP6Addr() {
+ let addrs = this._ubus('ipv6-address');
if (Array.isArray(addrs) && L.isObject(addrs[0]))
return '%s/%d'.format(addrs[0].address, addrs[0].mask);
* registered by the protocol handler. The order of the resulting array
* follows the order of the addresses in `ubus` runtime information.
*/
- getIP6Addrs: function() {
- var addrs = this._ubus('ipv6-address'),
- rv = [];
+ getIP6Addrs() {
+ let addrs = this._ubus('ipv6-address');
+ const rv = [];
if (Array.isArray(addrs))
- for (var i = 0; i < addrs.length; i++)
- if (L.isObject(addrs[i]))
- rv.push('%s/%d'.format(addrs[i].address, addrs[i].mask));
+ for (let a of addrs)
+ if (L.isObject(a))
+ rv.push('%s/%d'.format(a.address, a.mask));
addrs = this._ubus('ipv6-prefix-assignment');
if (Array.isArray(addrs))
- for (var i = 0; i < addrs.length; i++)
- if (L.isObject(addrs[i]) && L.isObject(addrs[i]['local-address']))
- rv.push('%s/%d'.format(addrs[i]['local-address'].address, addrs[i]['local-address'].mask));
+ for (let a of addrs)
+ if (L.isObject(a) && L.isObject(a['local-address']))
+ rv.push('%s/%d'.format(a['local-address'].address, a['local-address'].mask));
return rv;
},
* Returns a string containing the IPv6 nexthop address of the associated
* default route or `null` if no default route was found.
*/
- getGateway6Addr: function() {
- var routes = this._ubus('route');
+ getGateway6Addr() {
+ const routes = this._ubus('route');
if (Array.isArray(routes))
- for (var i = 0; i < routes.length; i++)
- if (typeof(routes[i]) == 'object' &&
- routes[i].target == '::' &&
- routes[i].mask == 0)
- return routes[i].nexthop;
+ for (let r of routes)
+ if (typeof(r) == 'object' &&
+ r.target == '::' &&
+ r.mask == 0)
+ return r.nexthop;
return null;
},
* Returns an array of IPv6 DNS servers registered by the remote
* protocol back-end.
*/
- getDNS6Addrs: function() {
- var addrs = this._ubus('dns-server'),
- rv = [];
+ getDNS6Addrs() {
+ const addrs = this._ubus('dns-server');
+ const rv = [];
if (Array.isArray(addrs))
- for (var i = 0; i < addrs.length; i++)
- if (/:/.test(addrs[i]))
- rv.push(addrs[i]);
+ for (let a of addrs)
+ if (/:/.test(a))
+ rv.push(a);
return rv;
},
* Returns the routed IPv6 prefix registered by the remote protocol
* handler or `null` if no prefix is present.
*/
- getIP6Prefix: function() {
- var prefixes = this._ubus('ipv6-prefix');
+ getIP6Prefix() {
+ const prefixes = this._ubus('ipv6-prefix');
if (Array.isArray(prefixes) && L.isObject(prefixes[0]))
return '%s/%d'.format(prefixes[0].address, prefixes[0].mask);
* Returns an array of the routed IPv6 prefixes registered by the remote
* protocol handler or `null` if no prefixes are present.
*/
- getIP6Prefixes: function() {
- var prefixes = this._ubus('ipv6-prefix');
- var rv = [];
+ getIP6Prefixes() {
+ const prefixes = this._ubus('ipv6-prefix');
+ const rv = [];
if (Array.isArray(prefixes))
- for (var i = 0; i < prefixes.length; i++)
- if (L.isObject(prefixes[i]))
- rv.push('%s/%d'.format(prefixes[i].address, prefixes[i].mask));
+ for (let p of prefixes)
+ if (L.isObject(p))
+ rv.push('%s/%d'.format(p.address, p.mask));
return rv.length > 0 ? rv: null;
},
* @returns {string[]}
* Returns an array of translated interface error messages.
*/
- getErrors: function() {
- var errors = this._ubus('errors'),
- rv = null;
+ getErrors() {
+ const errors = this._ubus('errors');
+ let rv = null;
if (Array.isArray(errors)) {
- for (var i = 0; i < errors.length; i++) {
- if (!L.isObject(errors[i]) || typeof(errors[i].code) != 'string')
+ for (let e of errors) {
+ if (!L.isObject(e) || typeof(e.code) != 'string')
continue;
rv = rv || [];
- rv.push(proto_errors[errors[i].code] || _('Unknown error (%s)').format(errors[i].code));
+ rv.push(proto_errors[e.code] || _('Unknown error (%s)').format(e.code));
}
}
* and when the associated protocol implementation is not marked virtual
* or `false` when the logical interface is no bridge.
*/
- isBridge: function() {
+ isBridge() {
return (!this.isVirtual() && this.getType() == 'bridge');
},
* Returns the name of the package to download, required for the protocol to
* function, e.g. `odhcp6c` for the `dhcpv6` protocol.
*/
- getPackageName: function() {
+ getPackageName() {
return null;
},
* Returns a promise resolving if a new interface is creatable, else
* rejects with an error message string.
*/
- isCreateable: function(ifname) {
+ isCreateable(ifname) {
return Promise.resolve(null);
},
* @returns {boolean}
* Returns `true` if the protocol support is installed, else `false`.
*/
- isInstalled: function() {
+ isInstalled() {
return true;
},
* Returns a boolean indicating whether the underlying protocol spawns
* dynamic interfaces (`true`) or not (`false`).
*/
- isVirtual: function() {
+ isVirtual() {
return false;
},
* Returns a boolean indicating whether this protocol is floating (`true`)
* or not (`false`).
*/
- isFloating: function() {
+ isFloating() {
return false;
},
* Returns a boolean indicating whether this interface is dynamic (`true`)
* or not (`false`).
*/
- isDynamic: function() {
+ isDynamic() {
return (this._ubus('dynamic') == true);
},
* @returns {boolean}
* returns `true` when the interface is pending or `false` when it is not.
*/
- isPending: function() {
+ isPending() {
return (this._ubus('pending') == true);
},
* Returns the name of the parent interface if this logical interface
* is an alias or `null` if it is not an alias interface.
*/
- isAlias: function() {
- var ifnames = L.toArray(uci.get('network', this.sid, 'device')),
- parent = null;
+ isAlias() {
+ const ifnames = L.toArray(uci.get('network', this.sid, 'device'));
+ let parent = null;
- for (var i = 0; i < ifnames.length; i++)
- if (ifnames[i].charAt(0) == '@')
- parent = ifnames[i].substr(1);
+ for (let ifn of ifnames)
+ if (ifn.charAt(0) == '@')
+ parent = ifn.substr(1);
else if (parent != null)
parent = null;
* @returns {boolean}
* Returns `true` if this logical interface is empty, else `false`.
*/
- isEmpty: function() {
+ isEmpty() {
if (this.isFloating())
return false;
- var empty = true,
- device = this._get('device');
+ let empty = true;
+ const device = this._get('device');
if (device != null && device.match(/\S+/))
empty = false;
* @returns {boolean}
* Returns `true` when the interface is active or `false` when it is not.
*/
- isUp: function() {
+ isUp() {
return (this._ubus('up') == true);
},
* argument was invalid, if the device was already part of the logical
* interface or if the logical interface is virtual.
*/
- addDevice: function(device) {
+ addDevice(device) {
device = ifnameOf(device);
if (device == null || this.isFloating())
return false;
- var wif = getWifiSidByIfname(device);
+ const wif = getWifiSidByIfname(device);
if (wif != null)
return appendValue('wireless', wif, 'network', this.sid);
* argument was invalid, if the device was already part of the logical
* interface or if the logical interface is virtual.
*/
- deleteDevice: function(device) {
- var rv = false;
+ deleteDevice(device) {
+ let rv = false;
device = ifnameOf(device);
if (device == null || this.isFloating())
return false;
- var wif = getWifiSidByIfname(device);
+ const wif = getWifiSidByIfname(device);
if (wif != null)
rv = removeValue('wireless', wif, 'network', this.sid);
* Returns a `Network.Device` class instance representing the
* expected Linux network device according to the configuration.
*/
- getDevice: function() {
+ getDevice() {
if (this.isVirtual()) {
- var ifname = '%s-%s'.format(this.getProtocol(), this.sid);
+ const ifname = '%s-%s'.format(this.getProtocol(), this.sid);
_state.isTunnel[this.getProtocol() + '-' + this.sid] = true;
return Network.prototype.instantiateDevice(ifname, this);
}
else if (this.isBridge()) {
- var ifname = 'br-%s'.format(this.sid);
+ const ifname = 'br-%s'.format(this.sid);
_state.isBridge[ifname] = true;
return new Device(ifname, this);
}
else {
- var ifnames = L.toArray(uci.get('network', this.sid, 'device'));
+ const ifnames = L.toArray(uci.get('network', this.sid, 'device'));
- for (var i = 0; i < ifnames.length; i++) {
- var m = ifnames[i].match(/^([^:/]+)/);
+ for (let ifn of ifnames) {
+ const m = ifn.match(/^([^:/]+)/);
return ((m && m[1]) ? Network.prototype.instantiateDevice(m[1], this) : null);
}
- ifname = getWifiNetidByNetname(this.sid);
+ const ifname = getWifiNetidByNetname(this.sid);
return (ifname != null ? Network.prototype.instantiateDevice(ifname[0], this) : null);
}
* Returns a `Network.Device` class instance representing the Linux
* network device currently associated with the logical interface.
*/
- getL2Device: function() {
- var ifname = this._ubus('device');
+ getL2Device() {
+ const ifname = this._ubus('device');
return (ifname != null ? Network.prototype.instantiateDevice(ifname, this) : null);
},
* Returns a `Network.Device` class instance representing the Linux
* network device currently associated with the logical interface.
*/
- getL3Device: function() {
- var ifname = this._ubus('l3_device');
+ getL3Device() {
+ const ifname = this._ubus('l3_device');
return (ifname != null ? Network.prototype.instantiateDevice(ifname, this) : null);
},
* logical interface does not support sub-devices, e.g. because it is
* virtual and not a bridge.
*/
- getDevices: function() {
- var rv = [];
+ getDevices() {
+ const rv = [];
if (!this.isBridge() && !(this.isVirtual() && !this.isFloating()))
return null;
- var device = uci.get('network', this.sid, 'device');
+ const device = uci.get('network', this.sid, 'device');
if (device && device.charAt(0) != '@') {
- var m = device.match(/^([^:/]+)/);
+ const m = device.match(/^([^:/]+)/);
if (m != null)
rv.push(Network.prototype.instantiateDevice(m[1], this));
}
- var uciWifiIfaces = uci.sections('wireless', 'wifi-iface');
+ const uciWifiIfaces = uci.sections('wireless', 'wifi-iface');
- for (var i = 0; i < uciWifiIfaces.length; i++) {
- if (typeof(uciWifiIfaces[i].device) != 'string')
+ for (let wf_if of uciWifiIfaces) {
+ if (typeof(wf_if.device) != 'string')
continue;
- var networks = L.toArray(uciWifiIfaces[i].network);
+ const networks = L.toArray(wf_if.network);
- for (var j = 0; j < networks.length; j++) {
- if (networks[j] != this.sid)
+ for (let n of networks) {
+ if (n != this.sid)
continue;
- var netid = getWifiNetidBySid(uciWifiIfaces[i]['.name']);
+ const netid = getWifiNetidBySid(wf_if['.name']);
if (netid != null)
rv.push(Network.prototype.instantiateDevice(netid[0], this));
* Returns `true` when this logical interface contains the given network
* device or `false` if not.
*/
- containsDevice: function(device) {
+ containsDevice(device) {
device = ifnameOf(device);
if (device == null)
else if (this.isBridge() && 'br-%s'.format(this.sid) == device)
return true;
- var name = uci.get('network', this.sid, 'device');
+ const name = uci.get('network', this.sid, 'device');
if (name) {
- var m = name.match(/^([^:/]+)/);
+ const m = name.match(/^([^:/]+)/);
if (m != null && m[1] == device)
return true;
}
- var wif = getWifiSidByIfname(device);
+ const wif = getWifiSidByIfname(device);
if (wif != null) {
- var networks = L.toArray(uci.get('wireless', wif, 'network'));
+ const networks = L.toArray(uci.get('wireless', wif, 'network'));
- for (var i = 0; i < networks.length; i++)
- if (networks[i] == this.sid)
+ for (let n of networks)
+ if (n == this.sid)
return true;
}
* resolved promise value is ignored. If the returned promise is rejected,
* the interface removal will be aborted.
*/
- deleteConfiguration: function() {}
+ deleteConfiguration() {}
});
/**
* device and allows querying device details such as packet statistics or MTU.
*/
Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ {
- __init__: function(device, network) {
- var wif = getWifiSidByIfname(device);
+ __init__(device, network) {
+ const wif = getWifiSidByIfname(device);
if (wif != null) {
- var res = getWifiStateBySid(wif) || [],
- netid = getWifiNetidBySid(wif) || [];
+ const res = getWifiStateBySid(wif) || [];
+ const netid = getWifiNetidBySid(wif) || [];
this.wif = new WifiNetwork(wif, res[0], res[1], netid[0], res[2], { ifname: device });
this.device = this.wif.getIfname();
this.dev = Object.assign({}, _state.netdevs[this.device]);
this.network = network;
- var conf;
+ let conf;
uci.sections('network', 'device', function(s) {
if (s.name == device)
this.config = Object.assign({}, conf);
},
- _devstate: function(/* ... */) {
- var rv = this.dev;
+ _devstate(/* ... */) {
+ let rv = this.dev;
- for (var i = 0; i < arguments.length; i++)
+ for (let a of arguments)
if (L.isObject(rv))
- rv = rv[arguments[i]];
+ rv = rv[a];
else
return null;
* @returns {string}
* Returns the name of the device, e.g. `eth0` or `wlan0`.
*/
- getName: function() {
+ getName() {
return (this.wif != null ? this.wif.getIfname() : this.device);
},
* Returns the MAC address of the device or `null` if not applicable,
* e.g. for non-Ethernet tunnel devices.
*/
- getMAC: function() {
- var mac = this._devstate('macaddr');
+ getMAC() {
+ const mac = this._devstate('macaddr');
return mac ? mac.toUpperCase() : null;
},
* @returns {number}
* Returns the MTU of the device.
*/
- getMTU: function() {
+ getMTU() {
return this._devstate('mtu');
},
* @returns {string[]}
* Returns an array of IPv4 address strings.
*/
- getIPAddrs: function() {
- var addrs = this._devstate('ipaddrs');
+ getIPAddrs() {
+ const addrs = this._devstate('ipaddrs');
return (Array.isArray(addrs) ? addrs : []);
},
* @returns {string[]}
* Returns an array of IPv6 address strings.
*/
- getIP6Addrs: function() {
- var addrs = this._devstate('ip6addrs');
+ getIP6Addrs() {
+ const addrs = this._devstate('ip6addrs');
return (Array.isArray(addrs) ? addrs : []);
},
* - `switch` if it is a switch device (e.g.`eth1` connected to switch0)
* - `ethernet` for all other device types
*/
- getType: function() {
+ getType() {
if (this.device != null && this.device.charAt(0) == '@')
return 'alias';
else if (this.dev.devtype == 'wlan' || this.wif != null || isWifiIfname(this.device))
* Returns the device name for non-WiFi devices or a string containing
* the operation mode and SSID for WiFi devices.
*/
- getShortName: function() {
+ getShortName() {
if (this.wif != null)
return this.wif.getShortName();
* Returns a string containing the type description and device name
* for non-WiFi devices or operation mode and SSID for WiFi ones.
*/
- getI18n: function() {
+ getI18n() {
if (this.wif != null) {
return '%s: %s "%s"'.format(
_('Wireless Network'),
* Returns a string describing the type, e.g. "Wireless Adapter" or
* "Bridge".
*/
- getTypeI18n: function() {
+ getTypeI18n() {
switch (this.getType()) {
case 'alias':
return _('Alias Interface');
* (slave interfaces) of the bridge or `null` when this device isn't
* a Linux bridge.
*/
- getPorts: function() {
- var br = _state.bridges[this.device],
- rv = [];
+ getPorts() {
+ const br = _state.bridges[this.device];
+ const rv = [];
if (br == null || !Array.isArray(br.ifnames))
return null;
- for (var i = 0; i < br.ifnames.length; i++)
- rv.push(Network.prototype.instantiateDevice(br.ifnames[i].name));
+ for (let ifn of br.ifnames)
+ rv.push(Network.prototype.instantiateDevice(ifn.name));
rv.sort(deviceSort);
* Returns the ID of this network bridge or `null` if this network
* device is not a Linux bridge.
*/
- getBridgeID: function() {
- var br = _state.bridges[this.device];
+ getBridgeID() {
+ const br = _state.bridges[this.device];
return (br != null ? br.id : null);
},
* Returns `true` when this device is a Linux bridge and has `stp`
* enabled, else `false`.
*/
- getBridgeSTP: function() {
- var br = _state.bridges[this.device];
+ getBridgeSTP() {
+ const br = _state.bridges[this.device];
return (br != null ? !!br.stp : false);
},
* Returns `true` when the associated device is running or `false`
* when it is down or absent.
*/
- isUp: function() {
- var up = this._devstate('flags', 'up');
+ isUp() {
+ let up = this._devstate('flags', 'up');
if (up == null)
up = (this.getType() == 'alias');
* Returns `true` when the network device is present and a Linux bridge,
* else `false`.
*/
- isBridge: function() {
+ isBridge() {
return (this.getType() == 'bridge');
},
* Returns `true` when this network device is part of a bridge,
* else `false`.
*/
- isBridgePort: function() {
+ isBridgePort() {
return (this._devstate('bridge') != null);
},
* @returns {number}
* Returns the amount of bytes transmitted by the network device.
*/
- getTXBytes: function() {
- var stat = this._devstate('stats');
+ getTXBytes() {
+ const stat = this._devstate('stats');
return (stat != null ? stat.tx_bytes || 0 : 0);
},
* @returns {number}
* Returns the amount of bytes received by the network device.
*/
- getRXBytes: function() {
- var stat = this._devstate('stats');
+ getRXBytes() {
+ const stat = this._devstate('stats');
return (stat != null ? stat.rx_bytes || 0 : 0);
},
* @returns {number}
* Returns the amount of packets transmitted by the network device.
*/
- getTXPackets: function() {
- var stat = this._devstate('stats');
+ getTXPackets() {
+ const stat = this._devstate('stats');
return (stat != null ? stat.tx_packets || 0 : 0);
},
* @returns {number}
* Returns the amount of packets received by the network device.
*/
- getRXPackets: function() {
- var stat = this._devstate('stats');
+ getRXPackets() {
+ const stat = this._devstate('stats');
return (stat != null ? stat.rx_packets || 0 : 0);
},
* Returns true if the device has a carrier, e.g. when a cable is
* inserted into an Ethernet port of false if there is none.
*/
- getCarrier: function() {
- var link = this._devstate('link');
+ getCarrier() {
+ const link = this._devstate('link');
return (link != null ? link.carrier || false : false);
},
* If the device supports Ethernet speeds but has no carrier, -1 is
* returned.
*/
- getSpeed: function() {
- var link = this._devstate('link');
+ getSpeed() {
+ const link = this._devstate('link');
return (link != null ? link.speed || null : null);
},
* either "full" or "half" if the device supports duplex modes or
* null if the duplex mode is unknown or unsupported.
*/
- getDuplex: function() {
- var link = this._devstate('link'),
- duplex = link ? link.duplex : null;
+ getDuplex() {
+ const link = this._devstate('link');
+ const duplex = link ? link.duplex : null;
return (duplex != 'unknown') ? duplex : null;
},
* - priority: Current priority level
* - priorityMax: Maximum priority level
*/
- getPSE: function() {
+ getPSE() {
const pse = this._devstate('pse');
if (!pse)
return null;
* @returns {boolean}
* Returns true if PSE hardware is available on this device.
*/
- hasPSE: function() {
+ hasPSE() {
return this._devstate('pse') != null;
},
* interface this device is attached to or `null` if it is not
* assigned to any logical interface.
*/
- getNetwork: function() {
+ getNetwork() {
return this.getNetworks()[0];
},
* Returns an array of `Network.Protocol` instances representing the
* logical interfaces this device is assigned to.
*/
- getNetworks: function() {
+ getNetworks() {
if (this.networks == null) {
this.networks = [];
- var networks = enumerateNetworks.apply(L.network);
+ const networks = enumerateNetworks.apply(L.network);
- for (var i = 0; i < networks.length; i++)
- if (networks[i].containsDevice(this.device) || networks[i].getIfname() == this.device)
- this.networks.push(networks[i]);
+ for (let n of networks)
+ if (n.containsDevice(this.device) || n.getIfname() == this.device)
+ this.networks.push(n);
this.networks.sort(networkSort);
}
* network corresponding to this network device or `null` if this device
* is not a wireless device.
*/
- getWifiNetwork: function() {
+ getWifiNetwork() {
return (this.wif != null ? this.wif : null);
},
* `null` when this device has no parent, as it is the case for e.g.
* ordinary Ethernet interfaces.
*/
- getParent: function() {
+ getParent() {
if (this.dev.parent)
return Network.prototype.instantiateDevice(this.dev.parent);
* well as methods for enumerating related wireless networks.
*/
WifiDevice = baseclass.extend(/** @lends LuCI.network.WifiDevice.prototype */ {
- __init__: function(name, radiostate) {
- var uciWifiDevice = uci.get('wireless', name);
+ __init__(name, radiostate) {
+ const uciWifiDevice = uci.get('wireless', name);
if (uciWifiDevice != null &&
uciWifiDevice['.type'] == 'wifi-device' &&
},
/* private */
- ubus: function(/* ... */) {
- var v = this._ubusdata;
+ ubus(/* ... */) {
+ let v = this._ubusdata;
- for (var i = 0; i < arguments.length; i++)
+ for (let a of arguments)
if (L.isObject(v))
- v = v[arguments[i]];
+ v = v[a];
else
return null;
* Returns the UCI option value or `null` if the requested option is
* not found.
*/
- get: function(opt) {
+ get(opt) {
return uci.get('wireless', this.sid, opt);
},
* configuration.
* @returns {null}
*/
- set: function(opt, value) {
+ set(opt, value) {
return uci.set('wireless', this.sid, opt, value);
},
* runtime state or when the `disabled` option is set in the corresponding
* UCI configuration.
*/
- isDisabled: function() {
+ isDisabled() {
return this.ubus('dev', 'disabled') || this.get('disabled') == '1';
},
* radio configuration, which also serves as a unique logical identifier
* for the wireless phy.
*/
- getName: function() {
+ getName() {
return this.sid;
},
* - `ax` - IEEE 802.11ax mode, 2.4 or 5 GHz
* - 'be' - IEEE 802.11be mode, 2.4, 5 or 6 GHz
*/
- getHWModes: function() {
- var hwmodes = this.ubus('dev', 'iwinfo', 'hwmodes');
+ getHWModes() {
+ const hwmodes = this.ubus('dev', 'iwinfo', 'hwmodes');
return Array.isArray(hwmodes) ? hwmodes : [ 'b', 'g' ];
},
* - `EHT160` - applicable to IEEE 802.11be, 160 MHz wide channels
* - `EHT320` - applicable to IEEE 802.11be, 320 MHz wide channels
*/
- getHTModes: function() {
- var htmodes = this.ubus('dev', 'iwinfo', 'htmodes');
+ getHTModes() {
+ const htmodes = this.ubus('dev', 'iwinfo', 'htmodes');
return (Array.isArray(htmodes) && htmodes.length) ? htmodes : null;
},
* @returns {string}
* Returns the description string.
*/
- getI18n: function() {
- var hw = this.ubus('dev', 'iwinfo', 'hardware'),
- type = L.isObject(hw) ? hw.name : null;
- var modes = this.ubus('dev', 'iwinfo', 'hwmodes_text');
+ getI18n() {
+ const hw = this.ubus('dev', 'iwinfo', 'hardware');
+ let type = L.isObject(hw) ? hw.name : null;
+ const modes = this.ubus('dev', 'iwinfo', 'hwmodes_text');
if (this.ubus('dev', 'iwinfo', 'type') == 'wl')
type = 'Broadcom';
* Returns a promise resolving to an array of scan result objects
* describing the networks found in the vicinity.
*/
- getScanList: function() {
+ getScanList() {
return callIwinfoScan(this.sid);
},
* @returns {boolean}
* Returns `true` when the radio device is up, else `false`.
*/
- isUp: function() {
+ isUp() {
if (L.isObject(_state.radios[this.sid]))
return (_state.radios[this.sid].up == true);
* the given network could not be found or is not associated with
* this radio device.
*/
- getWifiNetwork: function(network) {
+ getWifiNetwork(network) {
return Network.prototype.getWifiNetwork(network).then(L.bind(function(networkInstance) {
- var uciWifiIface = (networkInstance.sid ? uci.get('wireless', networkInstance.sid) : null);
+ const uciWifiIface = (networkInstance.sid ? uci.get('wireless', networkInstance.sid) : null);
if (uciWifiIface == null || uciWifiIface['.type'] != 'wifi-iface' || uciWifiIface.device != this.sid)
return Promise.reject();
* instances representing the wireless networks associated with this
* radio device.
*/
- getWifiNetworks: function() {
+ getWifiNetworks() {
return Network.prototype.getWifiNetworks().then(L.bind(function(networks) {
- var rv = [];
+ const rv = [];
- for (var i = 0; i < networks.length; i++)
- if (networks[i].getWifiDeviceName() == this.getName())
- rv.push(networks[i]);
+ for (let n of networks)
+ if (n.getWifiDeviceName() == this.getName())
+ rv.push(n);
return rv;
}, this));
* the newly added wireless network or `null` if the given options
* were invalid.
*/
- addWifiNetwork: function(options) {
+ addWifiNetwork(options) {
if (!L.isObject(options))
options = {};
* network could not be found or if the found network was not associated
* with this wireless radio device.
*/
- deleteWifiNetwork: function(network) {
- var sid = null;
+ deleteWifiNetwork(network) {
+ let sid = null;
if (network instanceof WifiNetwork) {
sid = network.sid;
}
else {
- var uciWifiIface = uci.get('wireless', network);
+ const uciWifiIface = uci.get('wireless', network);
if (uciWifiIface == null || uciWifiIface['.type'] != 'wifi-iface')
sid = getWifiSidByIfname(network);
* such networks in parallel.
*/
WifiNetwork = baseclass.extend(/** @lends LuCI.network.WifiNetwork.prototype */ {
- __init__: function(sid, radioname, radiostate, netid, netstate, hostapd) {
+ __init__(sid, radioname, radiostate, netid, netstate, hostapd) {
this.sid = sid;
this.netid = netid;
this._ubusdata = {
};
},
- ubus: function(/* ... */) {
- var v = this._ubusdata;
+ ubus(/* ... */) {
+ let v = this._ubusdata;
- for (var i = 0; i < arguments.length; i++)
+ for (let a of arguments)
if (L.isObject(v))
- v = v[arguments[i]];
+ v = v[a];
else
return null;
* Returns the UCI option value or `null` if the requested option is
* not found.
*/
- get: function(opt) {
+ get(opt) {
return uci.get('wireless', this.sid, opt);
},
* configuration.
* @returns {null}
*/
- set: function(opt, value) {
+ set(opt, value) {
return uci.set('wireless', this.sid, opt, value);
},
* runtime state or when the `disabled` option is set in the corresponding
* UCI configuration.
*/
- isDisabled: function() {
+ isDisabled() {
return this.ubus('dev', 'disabled') || this.get('disabled') == '1';
},
* - `mesh` - Mesh (IEEE 802.11s) mode
* - `monitor` - Monitor mode
*/
- getMode: function() {
+ getMode() {
return this.ubus('net', 'config', 'mode') || this.get('mode') || 'ap';
},
* Returns the configured SSID value or `null` when this network is
* in mesh mode.
*/
- getSSID: function() {
+ getSSID() {
if (this.getMode() == 'mesh')
return null;
* Returns the configured mesh ID value or `null` when this network
* is not in mesh mode.
*/
- getMeshID: function() {
+ getMeshID() {
if (this.getMode() != 'mesh')
return null;
* @returns {null|string}
* Returns the BSSID value or `null` if none has been specified.
*/
- getBSSID: function() {
+ getBSSID() {
return this.ubus('net', 'config', 'bssid') || this.get('bssid');
},
* @returns {string[]}
* Returns an array of logical interface names.
*/
- getNetworkNames: function() {
+ getNetworkNames() {
return L.toArray(this.ubus('net', 'config', 'network') || this.get('network'));
},
* @returns {string}
* Returns the LuCI specific network ID.
*/
- getID: function() {
+ getID() {
return this.netid;
},
* @returns {string}
* Returns the corresponding UCI section ID of the network.
*/
- getName: function() {
+ getName() {
return this.sid;
},
* `ubus` runtime information or `null` if this network has no
* associated network device, e.g. when not configured or up.
*/
- getIfname: function() {
- var ifname = this.ubus('net', 'ifname') || this.ubus('net', 'iwinfo', 'ifname');
+ getIfname() {
+ let ifname = this.ubus('net', 'ifname') || this.ubus('net', 'iwinfo', 'ifname');
if (ifname == null || ifname.match(/^(wifi|radio)\d/))
ifname = this.netid;
* from `ubus` runtime information or empty array if this network
* has no associated VLAN network devices.
*/
- getVlanIfnames: function() {
- var vlans = L.toArray(this.ubus('net', 'vlans')),
- ifnames = [];
+ getVlanIfnames() {
+ const vlans = L.toArray(this.ubus('net', 'vlans'));
+ const ifnames = [];
- for (var i = 0; i < vlans.length; i++)
- ifnames.push(vlans[i]['ifname']);
+ for (let v of vlans)
+ ifnames.push(v['ifname']);
return ifnames;
},
* Returns the name of the radio device this network is configured on
* or `null` if it cannot be determined.
*/
- getWifiDeviceName: function() {
+ getWifiDeviceName() {
return this.ubus('radio') || this.get('device');
},
* WiFi radio device or `null` if the related radio device could not be
* found.
*/
- getWifiDevice: function() {
- var radioname = this.getWifiDeviceName();
+ getWifiDevice() {
+ const radioname = this.getWifiDeviceName();
if (radioname == null)
return Promise.reject();
* @returns {boolean}
* Returns `true` when the network is up, else `false`.
*/
- isUp: function() {
- var device = this.getDevice();
+ isUp() {
+ const device = this.getDevice();
if (device == null)
return false;
* - `P2P Go`
* - `Unknown`
*/
- getActiveMode: function() {
- var mode = this.ubus('net', 'iwinfo', 'mode') || this.getMode();
+ getActiveMode() {
+ const mode = this.ubus('net', 'iwinfo', 'mode') || this.getMode();
switch (mode) {
case 'ap': return 'Master';
* Returns the translated, human readable mode name as reported by
*`ubus` runtime state.
*/
- getActiveModeI18n: function() {
- var mode = this.getActiveMode();
+ getActiveModeI18n() {
+ const mode = this.getActiveMode();
switch (mode) {
case 'Master': return _('Access Point');
* Returns the current SSID or Mesh ID as reported by `ubus` runtime
* information.
*/
- getActiveSSID: function() {
+ getActiveSSID() {
return this.ubus('net', 'iwinfo', 'ssid') || this.ubus('net', 'config', 'ssid') || this.get('ssid');
},
* Returns the current BSSID or Mesh ID as reported by `ubus` runtime
* information.
*/
- getActiveBSSID: function() {
+ getActiveBSSID() {
return this.ubus('net', 'iwinfo', 'bssid') || this.ubus('net', 'config', 'bssid') || this.get('bssid');
},
* Returns a string describing the current encryption or `-` if the
* encryption state could not be found in `ubus` runtime information.
*/
- getActiveEncryption: function() {
+ getActiveEncryption() {
return formatWifiEncryption(this.ubus('net', 'iwinfo', 'encryption')) || '-';
},
* Returns a promise resolving to an array of wireless peers associated
* with this network.
*/
- getAssocList: function() {
- var tasks = [];
- var station;
+ getAssocList() {
+ const tasks = [];
+ let station;
for (let vlan of this.getVlans())
tasks.push(callIwinfoAssoclist(vlan.getIfname()).then(
* @returns {Array<LuCI.network.WifiVlan>}
* Returns an array of vlans for this network.
*/
- getVlans: function() {
- var vlans = [];
- var vlans_ubus = this.ubus('net', 'vlans');
+ getVlans() {
+ const vlans = [];
+ const vlans_ubus = this.ubus('net', 'vlans');
if (vlans_ubus)
for (let vlan of vlans_ubus)
* runtime information in GHz or `null` if the information is not
* available.
*/
- getFrequency: function() {
- var freq = this.ubus('net', 'iwinfo', 'frequency');
+ getFrequency() {
+ const freq = this.ubus('net', 'iwinfo', 'frequency');
if (freq != null && freq > 0)
return '%.03f'.format(freq / 1000);
* as reported by `ubus` runtime information or `null` if the information
* is not available.
*/
- getBitRate: function() {
- var rate = this.ubus('net', 'iwinfo', 'bitrate');
+ getBitRate() {
+ const rate = this.ubus('net', 'iwinfo', 'bitrate');
if (rate != null && rate > 0)
return (rate / 1000);
* Returns the wireless channel as reported by `ubus` runtime information
* or `null` if it cannot be determined.
*/
- getChannel: function() {
+ getChannel() {
return this.ubus('net', 'iwinfo', 'channel') || this.ubus('dev', 'config', 'channel') || this.get('channel');
},
* Returns the wireless signal in dBm as reported by `ubus` runtime
* information or `null` if it cannot be determined.
*/
- getSignal: function() {
+ getSignal() {
return this.ubus('net', 'iwinfo', 'signal') || 0;
},
* Returns the radio noise floor in dBm as reported by `ubus` runtime
* information or `0` if it cannot be determined.
*/
- getNoise: function() {
+ getNoise() {
return this.ubus('net', 'iwinfo', 'noise') || 0;
},
* Returns the wireless country code as reported by `ubus` runtime
* information or `00` if it cannot be determined.
*/
- getCountryCode: function() {
+ getCountryCode() {
return this.ubus('net', 'iwinfo', 'country') || this.ubus('dev', 'config', 'country') || '00';
},
* Returns the wireless network transmit power in dBm as reported by
* `ubus` runtime information or `null` if it cannot be determined.
*/
- getTXPower: function() {
+ getTXPower() {
return this.ubus('net', 'iwinfo', 'txpower');
},
* by `ubus` runtime information or `0` if there is no offset, or if it
* cannot be determined.
*/
- getTXPowerOffset: function() {
+ getTXPowerOffset() {
return this.ubus('net', 'iwinfo', 'txpower_offset') || 0;
},
* Returns the calculated signal level, which is the difference between
* noise and signal (SNR), divided by 5.
*/
- getSignalLevel: function(signal, noise) {
+ getSignalLevel(signal, noise) {
if (this.getActiveBSSID() == '00:00:00:00:00:00')
return -1;
noise = noise || this.getNoise();
if (signal < 0 && noise < 0) {
- var snr = -1 * (noise - signal);
+ const snr = -1 * (noise - signal);
return Math.floor(snr / 5);
}
* calculated from the `quality` and `quality_max` indicators reported
* by `ubus` runtime state.
*/
- getSignalPercent: function() {
- var qc = this.ubus('net', 'iwinfo', 'quality') || 0,
- qm = this.ubus('net', 'iwinfo', 'quality_max') || 0;
+ getSignalPercent() {
+ const qc = this.ubus('net', 'iwinfo', 'quality') || 0;
+ const qm = this.ubus('net', 'iwinfo', 'quality_max') || 0;
if (qc > 0 && qm > 0)
return Math.floor((100 / qm) * qc);
* active operation mode, followed by either the SSID, BSSID or
* internal network ID, depending on which information is available.
*/
- getShortName: function() {
+ getShortName() {
return '%s "%s"'.format(
this.getActiveModeI18n(),
this.getActiveSSID() || this.getActiveBSSID() || this.getID());
* the SSID, BSSID or internal network ID and the Linux network device
* name, depending on which information is available.
*/
- getI18n: function() {
+ getI18n() {
return '%s: %s "%s" (%s)'.format(
_('Wireless Network'),
this.getActiveModeI18n(),
* interface or `null` if this network is not attached to any logical
* interface.
*/
- getNetwork: function() {
+ getNetwork() {
return this.getNetworks()[0];
},
* Returns an array of `Network.Protocol` instances representing the
* logical interfaces this wireless network is attached to.
*/
- getNetworks: function() {
- var networkNames = this.getNetworkNames(),
- networks = [];
+ getNetworks() {
+ const networkNames = this.getNetworkNames();
+ const networks = [];
- for (var i = 0; i < networkNames.length; i++) {
- var uciInterface = uci.get('network', networkNames[i]);
+ for (let nn of networkNames) {
+ const uciInterface = uci.get('network', nn);
if (uciInterface == null || uciInterface['.type'] != 'interface')
continue;
- networks.push(Network.prototype.instantiateNetwork(networkNames[i]));
+ networks.push(Network.prototype.instantiateNetwork(nn));
}
networks.sort(networkSort);
* Returns a `Network.Device` instance representing the Linux network
* device associated with this wireless network.
*/
- getDevice: function() {
+ getDevice() {
return Network.prototype.instantiateDevice(this.getIfname());
},
* Returns `true` when this WiFi network instance supports forcibly
* de-authenticating clients, otherwise `false`.
*/
- isClientDisconnectSupported: function() {
+ isClientDisconnectSupported() {
return L.isObject(this.ubus('hostapd', 'del_client'));
},
* The promise might reject with an error in case invalid arguments
* are passed.
*/
- disconnectClient: function(mac, deauth, reason, ban_time) {
+ disconnectClient(mac, deauth, reason, ban_time) {
if (reason == null || reason == 0)
reason = 1;
* A `Network.WifiVlan` class instance represents a vlan on a WifiNetwork.
*/
WifiVlan = baseclass.extend(/** @lends LuCI.network.WifiVlan.prototype */ {
- __init__: function(vlan) {
+ __init__(vlan) {
this.ifname = vlan.ifname;
if (L.isObject(vlan.config)) {
this.vid = vlan.config.vid;
* @returns {string}
* Returns the name.
*/
- getName: function() {
+ getName() {
return this.name;
},
* @returns {number}
* Returns the vlan id.
*/
- getVlanId: function() {
+ getVlanId() {
return this.vid;
},
* @returns {string}
* Returns the network.
*/
- getNetwork: function() {
+ getNetwork() {
return this.network;
},
* @returns {string}
* Returns the current network device name for this wifi vlan.
*/
- getIfname: function() {
+ getIfname() {
return this.ifname;
},
* Returns a string containing the vlan id and the vlan name,
* if it is different than the vlan id
*/
- getI18n: function() {
- var name = this.name && this.name != this.vid ? ' (' + this.name + ')' : '';
+ getI18n() {
+ const name = this.name && this.name != this.vid ? ' (' + this.name + ')' : '';
return 'vlan %d%s'.format(this.vid, name);
},
});