fixes wifi
This commit is contained in:
parent
ac29803f03
commit
b15d09dde2
44
lib/wifi.js
44
lib/wifi.js
@ -119,7 +119,7 @@ function ifaceListLinux() {
|
|||||||
const all = execSync(cmd).toString().split('\n').map(line => line.trim()).join('\n');
|
const all = execSync(cmd).toString().split('\n').map(line => line.trim()).join('\n');
|
||||||
const parts = all.split('\nInterface ');
|
const parts = all.split('\nInterface ');
|
||||||
parts.shift();
|
parts.shift();
|
||||||
parts.foreach(ifaceDetails => {
|
parts.forEach(ifaceDetails => {
|
||||||
const lines = ifaceDetails.split('\n');
|
const lines = ifaceDetails.split('\n');
|
||||||
const iface = lines[0];
|
const iface = lines[0];
|
||||||
const id = util.toInt(util.getValue(lines, 'ifindex', ' '));
|
const id = util.toInt(util.getValue(lines, 'ifindex', ' '));
|
||||||
@ -142,13 +142,14 @@ function nmiDeviceLinux(iface) {
|
|||||||
const cmd = 'nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ' + iface;
|
const cmd = 'nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ' + iface;
|
||||||
try {
|
try {
|
||||||
const lines = execSync(cmd).toString().split('\n');
|
const lines = execSync(cmd).toString().split('\n');
|
||||||
|
const ssid = util.getValue(lines, 'GENERAL.CONNECTION');
|
||||||
return {
|
return {
|
||||||
iface,
|
iface,
|
||||||
type: util.getValue(lines, 'GENERAL.TYPE'),
|
type: util.getValue(lines, 'GENERAL.TYPE'),
|
||||||
vendor: util.getValue(lines, 'GENERAL.VENDOR'),
|
vendor: util.getValue(lines, 'GENERAL.VENDOR'),
|
||||||
product: util.getValue(lines, 'GENERAL.PRODUCT'),
|
product: util.getValue(lines, 'GENERAL.PRODUCT'),
|
||||||
mac: util.getValue(lines, 'GENERAL.HWADDR').toLowerCase(),
|
mac: util.getValue(lines, 'GENERAL.HWADDR').toLowerCase(),
|
||||||
ssid: util.getValue(lines, 'GENERAL.CONNECTION'),
|
ssid: ssid !== '--' ? ssid : null
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {};
|
return {};
|
||||||
@ -156,16 +157,17 @@ function nmiDeviceLinux(iface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function nmiConnectionLinux(ssid) {
|
function nmiConnectionLinux(ssid) {
|
||||||
const cmd = 'nmcli -t --show-secrets connection show ' + ssid;
|
const cmd = `nmcli -t --show-secrets connection ${ssid} ssid 2>/dev/null`;
|
||||||
try {
|
try {
|
||||||
const lines = execSync(cmd).toString().split('\n');
|
const lines = execSync(cmd).toString().split('\n');
|
||||||
|
const bssid = util.getValue(lines, '802-11-wireless.seen-bssids').toLowerCase();
|
||||||
return {
|
return {
|
||||||
ssid,
|
ssid: ssid !== '--' ? ssid : null,
|
||||||
uuid: util.getValue(lines, 'connection.uuid'),
|
uuid: util.getValue(lines, 'connection.uuid'),
|
||||||
type: util.getValue(lines, 'connection.type'),
|
type: util.getValue(lines, 'connection.type'),
|
||||||
autoconnect: util.getValue(lines, 'connection.autoconnect') === 'yes',
|
autoconnect: util.getValue(lines, 'connection.autoconnect') === 'yes',
|
||||||
security: util.getValue(lines, '802-11-wireless-security.key-mgmt'),
|
security: util.getValue(lines, '802-11-wireless-security.key-mgmt'),
|
||||||
bssid: util.getValue(lines, '802-11-wireless.seen-bssids').toLowerCase()
|
bssid: bssid !== '--' ? bssid : null
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {};
|
return {};
|
||||||
@ -173,7 +175,7 @@ function nmiConnectionLinux(ssid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wpaConnectionLinux(iface) {
|
function wpaConnectionLinux(iface) {
|
||||||
const cmd = `wpa_cli -i ${iface} status`;
|
const cmd = `wpa_cli -i ${iface} status 2>&1`;
|
||||||
try {
|
try {
|
||||||
const lines = execSync(cmd).toString().split('\n');
|
const lines = execSync(cmd).toString().split('\n');
|
||||||
return {
|
return {
|
||||||
@ -216,6 +218,7 @@ function getWifiNetworkListNmi() {
|
|||||||
rsnFlags: rsnFlags && rsnFlags !== 'none' ? rsnFlags.split(' ') : []
|
rsnFlags: rsnFlags && rsnFlags !== 'none' ? rsnFlags.split(' ') : []
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -479,19 +482,22 @@ function wifiConnections(callback) {
|
|||||||
const network = networkList.filter(nw => nw.ssid === ssid);
|
const network = networkList.filter(nw => nw.ssid === ssid);
|
||||||
const nmiConnection = nmiConnectionLinux(ssid);
|
const nmiConnection = nmiConnectionLinux(ssid);
|
||||||
const channel = network && network.length && network[0].channel ? network[0].channel : null;
|
const channel = network && network.length && network[0].channel ? network[0].channel : null;
|
||||||
result.push({
|
const bssid = network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails && wpaDetails.bssid ? wpaDetails.bssid : null);
|
||||||
id: ifaceDetail.id,
|
if (ssid && bssid) {
|
||||||
iface: ifaceDetail.iface,
|
result.push({
|
||||||
model: nmiDetails.product,
|
id: ifaceDetail.id,
|
||||||
ssid,
|
iface: ifaceDetail.iface,
|
||||||
bssid: network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails && wpaDetails.bssid ? wpaDetails.bssid : null),
|
model: nmiDetails.product,
|
||||||
channel,
|
ssid,
|
||||||
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
|
bssid: network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails && wpaDetails.bssid ? wpaDetails.bssid : null),
|
||||||
type: nmiConnection && nmiConnection.type ? nmiConnection.type : '802.11',
|
channel,
|
||||||
security: nmiConnection && nmiConnection.security ? nmiConnection.security : (wpaDetails && wpaDetails.security ? wpaDetails.security : null),
|
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
|
||||||
signalLevel: network && network.length && network[0].signalLevel ? network[0].signalLevel : null,
|
type: nmiConnection && nmiConnection.type ? nmiConnection.type : '802.11',
|
||||||
txRate: null
|
security: nmiConnection && nmiConnection.security ? nmiConnection.security : (wpaDetails && wpaDetails.security ? wpaDetails.security : null),
|
||||||
});
|
signalLevel: network && network.length && network[0].signalLevel ? network[0].signalLevel : null,
|
||||||
|
txRate: null
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result);
|
callback(result);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user