'require tools.firewall as fwtool';
'require tools.widgets as widgets';
-function skeys(obj, key, mode) {
- if (obj == null || typeof(obj) != 'object')
- return [];
-
- return Object.keys(obj).map(function(e) {
- var v = (key != null) ? obj[e][key] : e;
-
- switch (mode) {
- case 'addr':
- v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g,
- function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null;
- break;
-
- case 'num':
- v = (v != null) ? +v : null;
- break;
- }
-
- return [ e, v ];
- }).filter(function(e) {
- return (e[1] != null);
- }).sort(function(a, b) {
- return (a[1] > b[1]);
- }).map(function(e) {
- return e[0];
- });
-}
-
function fmt(fmt /*, ...*/) {
var repl = [], wrap = false;
o.rmempty = true;
o.datatype = 'neg(macaddr)';
o.placeholder = E('em', _('any'));
- skeys(hosts).forEach(function(mac) {
+ L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, '%s (%s)'.format(
mac,
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
o.rmempty = true;
o.datatype = 'neg(ipmask4)';
o.placeholder = E('em', _('any'));
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
o.rmempty = true;
o.datatype = 'neg(ipmask4)';
o.placeholder = E('em', _('any'));
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
o.modalonly = true;
o.rmempty = true;
o.datatype = 'ipmask4';
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
function getWifiState() {
if (_cache.wifi == null)
return callNetworkWirelessStatus().then(function(state) {
- if (!isObject(state))
+ if (!L.isObject(state))
throw !1;
return (_cache.wifi = state);
}).catch(function() {
function getDeviceState() {
if (_cache.devicedump == null)
return callNetworkDeviceStatus().then(function(state) {
- if (!isObject(state))
+ if (!L.isObject(state))
throw !1;
return (_cache.devicedump = state);
}).catch(function() {
function getNetdevState() {
if (_cache.devices == null)
return callLuciNetdevs().then(function(state) {
- if (!isObject(state))
+ if (!L.isObject(state))
throw !1;
return (_cache.devices = state);
}).catch(function() {
function getBoardState() {
if (_cache.board == null)
return callLuciBoardjson().then(function(state) {
- if (!isObject(state))
+ if (!L.isObject(state))
throw !1;
return (_cache.board = state);
}).catch(function() {
devstate = info[1],
phyonly = forcePhyOnly || !devstate[ifname] || (devstate[ifname].type != 1);
- if (isObject(iwinfo)) {
+ if (L.isObject(iwinfo)) {
if (phyonly) {
delete iwinfo.bitrate;
delete iwinfo.quality;
var res = getWifiStateByIfname(ifname);
- if (res != null && isObject(res[2]) && typeof(res[2].section) == 'string')
+ if (res != null && L.isObject(res[2]) && typeof(res[2].section) == 'string')
return res[2].section;
return null;
return false;
}
-function isObject(val) {
- return (val != null && typeof(val) == 'object')
-}
-
function appendValue(config, section, option, value) {
var values = uci.get(config, section, option),
isArray = Array.isArray(values),
return rv;
}
-function toArray(val) {
- if (val == null)
- return [];
-
- if (Array.isArray(val))
- return val;
-
- var s = String(val).trim();
-
- if (s == '')
- return [];
-
- return s.split(/\s+/);
-}
-
function prefixToMask(bits, v6) {
var w = v6 ? 128 : 32,
m = [];
}
}
- if (isObject(board.switch)) {
+ if (L.isObject(board.switch)) {
for (var switchname in board.switch) {
var layout = board.switch[switchname],
netdevs = {},
pnum = null,
role = null;
- if (isObject(layout) && Array.isArray(layout.ports)) {
+ if (L.isObject(layout) && Array.isArray(layout.ports)) {
for (var i = 0, port; (port = layout.ports[i]) != null; i++) {
if (typeof(port) == 'object' && typeof(port.num) == 'number' &&
(typeof(port.role) == 'string' || typeof(port.device) == 'string')) {
var sid = uci.add('network', 'interface', name);
if (sid != null) {
- if (isObject(options))
+ if (L.isObject(options))
for (var key in options)
if (options.hasOwnProperty(key))
uci.set('network', sid, key, options[key]);
}
}
else if (existingNetwork != null && existingNetwork.isEmpty()) {
- if (isObject(options))
+ if (L.isObject(options))
for (var key in options)
if (options.hasOwnProperty(key))
existingNetwork.set(key, options[key]);
});
uci.sections('wireless', 'wifi-iface', function(s) {
- var networks = toArray(s.network).filter(function(network) { return network != name });
+ var networks = L.toArray(s.network).filter(function(network) { return network != name });
if (networks.length > 0)
uci.set('wireless', s['.name'], 'network', networks.join(' '));
});
uci.sections('wireless', 'wifi-iface', function(s) {
- var networks = toArray(s.network).map(function(network) { return (network == oldName ? newName : network) });
+ var 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(' '));
/* find simple devices */
var uciInterfaces = uci.sections('network', 'interface');
for (var i = 0; i < uciInterfaces.length; i++) {
- var ifnames = toArray(uciInterfaces[i].ifname);
+ var ifnames = L.toArray(uciInterfaces[i].ifname);
for (var j = 0; j < ifnames.length; j++) {
if (ifnames[j].charAt(0) == '@')
var rv = [];
for (var i = 0; i < deviceNames.length; i++)
- if (isObject(iwinfos[i]))
+ if (L.isObject(iwinfos[i]))
rv.push(this.instantiateWifiDevice(deviceNames[i], iwinfos[i]));
rv.sort(function(a, b) { return a.getName() < b.getName() });
getZoneName: function() {
var d = this._ubus('data');
- if (isObject(d) && typeof(d.zone) == 'string')
+ if (L.isObject(d) && typeof(d.zone) == 'string')
return d.zone;
return null;
getIP6Addr: function() {
var addrs = this._ubus('ipv6-address');
- if (Array.isArray(addrs) && isObject(addrs[0]))
+ if (Array.isArray(addrs) && L.isObject(addrs[0]))
return '%s/%d'.format(addrs[0].address, addrs[0].mask);
addrs = this._ubus('ipv6-prefix-assignment');
- if (Array.isArray(addrs) && isObject(addrs[0]) && isObject(addrs[0]['local-address']))
+ if (Array.isArray(addrs) && L.isObject(addrs[0]) && L.isObject(addrs[0]['local-address']))
return '%s/%d'.format(addrs[0]['local-address'].address, addrs[0]['local-address'].mask);
return null;
if (Array.isArray(addrs))
for (var i = 0; i < addrs.length; i++)
- if (isObject(addrs[i]))
+ if (L.isObject(addrs[i]))
rv.push('%s/%d'.format(addrs[i].address, addrs[i].mask));
addrs = this._ubus('ipv6-prefix-assignment');
if (Array.isArray(addrs))
for (var i = 0; i < addrs.length; i++)
- if (isObject(addrs[i]) && isObject(addrs[i]['local-address']))
+ 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));
return rv;
getIP6Prefix: function() {
var prefixes = this._ubus('ipv6-prefix');
- if (Array.isArray(prefixes) && isObject(prefixes[0]))
+ if (Array.isArray(prefixes) && L.isObject(prefixes[0]))
return '%s/%d'.format(prefixes[0].address, prefixes[0].mask);
return null;
if (Array.isArray(errors)) {
for (var i = 0; i < errors.length; i++) {
- if (!isObject(errors[i]) || typeof(errors[i].code) != 'string')
+ if (!L.isObject(errors[i]) || typeof(errors[i].code) != 'string')
continue;
rv = rv || [];
},
isAlias: function() {
- var ifnames = toArray(uci.get('network', this.sid, 'ifname')),
+ var ifnames = L.toArray(uci.get('network', this.sid, 'ifname')),
parent = null;
for (var i = 0; i < ifnames.length; i++)
if (ifname != null)
return L.network.instantiateDevice(ifname, this);
- var ifnames = toArray(uci.get('network', this.sid, 'ifname'));
+ var ifnames = L.toArray(uci.get('network', this.sid, 'ifname'));
for (var i = 0; i < ifnames.length; i++) {
var m = ifnames[i].match(/^([^:/]+)/);
if (!this.isBridge() && !(this.isVirtual() && !this.isFloating()))
return null;
- var ifnames = toArray(uci.get('network', this.sid, 'ifname'));
+ var ifnames = L.toArray(uci.get('network', this.sid, 'ifname'));
for (var i = 0; i < ifnames.length; i++) {
if (ifnames[i].charAt(0) == '@')
if (typeof(uciWifiIfaces[i].device) != 'string')
continue;
- var networks = toArray(uciWifiIfaces[i].network);
+ var networks = L.toArray(uciWifiIfaces[i].network);
for (var j = 0; j < networks.length; j++) {
if (networks[j] != this.sid)
else if (this.isBridge() && 'br-%s'.format(this.sid) == ifname)
return true;
- var ifnames = toArray(uci.get('network', this.sid, 'ifname'));
+ var ifnames = L.toArray(uci.get('network', this.sid, 'ifname'));
for (var i = 0; i < ifnames.length; i++) {
var m = ifnames[i].match(/^([^:/]+)/);
var wif = getWifiSidByIfname(ifname);
if (wif != null) {
- var networks = toArray(uci.get('wireless', wif, 'network'));
+ var networks = L.toArray(uci.get('wireless', wif, 'network'));
for (var i = 0; i < networks.length; i++)
if (networks[i] == this.sid)
},
getHWModes: function() {
- if (isObject(this.iwinfo.hwmodelist))
+ if (L.isObject(this.iwinfo.hwmodelist))
for (var k in this.iwinfo.hwmodelist)
return this.iwinfo.hwmodelist;
},
isUp: function() {
- if (isObject(_cache.wifi[this.sid]))
+ if (L.isObject(_cache.wifi[this.sid]))
return (_cache.wifi[this.sid].up == true);
return false;
},
addWifiNetwork: function(options) {
- if (!isObject(options))
+ if (!L.isObject(options))
options = {};
options.device = this.sid;
var v = this._ubusdata;
for (var i = 0; i < arguments.length; i++)
- if (isObject(v))
+ if (L.isObject(v))
v = v[arguments[i]];
else
return null;
},
getNetworkNames: function() {
- return toArray(this.ubus('net', 'config', 'network') || this.get('network'));
+ return L.toArray(this.ubus('net', 'config', 'network') || this.get('network'));
},
getID: function() {
getActiveEncryption: function() {
var encryption = this.iwinfo.encryption;
- return (isObject(encryption) ? encryption.description || '-' : '-');
+ return (L.isObject(encryption) ? encryption.description || '-' : '-');
},
getAssocList: function() {
'require network';
'require firewall';
-function toArray(x) {
- if (x == null)
- return [];
- else if (Array.isArray(x))
- return x.map(String);
- else if (typeof(x) == 'object')
- return [ x ];
-
- var s = String(x).trim();
-
- if (s == '')
- return [];
-
- return s.split(/\s+/);
-}
-
var CBIZoneSelect = form.ListValue.extend({
__name__: 'CBI.ZoneSelect',
},
renderWidget: function(section_id, option_index, cfgvalue) {
- var values = toArray((cfgvalue != null) ? cfgvalue : this.default),
+ var values = L.toArray((cfgvalue != null) ? cfgvalue : this.default),
choices = {};
if (this.allowlocal) {
'class': 'ifacebadge' + (network.getName() == this.network ? ' ifacebadge-active' : '')
}, network.getName() + ': ');
- var devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice());
+ var devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice());
for (var k = 0; k < devices.length; k++) {
span.appendChild(E('img', {
'class': 'ifacebadge' + (network.getName() == this.network ? ' ifacebadge-active' : '')
}, network.getName() + ': ');
- var devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice());
+ var devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice());
for (var k = 0; k < devices.length && devices[k]; k++) {
span.appendChild(E('img', {
renderIfaceBadge: function(network) {
var span = E('span', { 'class': 'ifacebadge' }, network.getName() + ': '),
- devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice());
+ devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice());
for (var j = 0; j < devices.length && devices[j]; j++) {
span.appendChild(E('img', {
},
renderWidget: function(section_id, option_index, cfgvalue) {
- var values = toArray((cfgvalue != null) ? cfgvalue : this.default),
+ var values = L.toArray((cfgvalue != null) ? cfgvalue : this.default),
choices = {},
checked = {};
textvalue: function(section_id) {
var cfgvalue = this.cfgvalue(section_id),
- values = toArray((cfgvalue != null) ? cfgvalue : this.default),
+ values = L.toArray((cfgvalue != null) ? cfgvalue : this.default),
rv = E([]);
for (var i = 0; i < (this.networks || []).length; i++) {