-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi.js
56 lines (55 loc) · 1.77 KB
/
wifi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const {exec} = require('child_process');
module.exports = {
scanForWifiNetworks() {
return new Promise((resolve, reject) => {
exec(`ubus call onion wifi-scan "{'device':'ra0'}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error Code: ${error.code}, Error Signal: ${error.signal}`);
reject(stderr.toString());
} else {
resolve(JSON.parse(stdout.toString()).results);
}
});
});
},
getConfiguredWifiNetworks() {
return new Promise((resolve, reject) => {
exec('wifisetup list', (error, stdout, stderr) => {
if (error) {
console.error(`Error Code: ${error.code}, Error Signal: ${error.signal}`);
reject(stderr.toString());
} else {
resolve(JSON.parse(stdout.toString()).results.map(network => ({
ssid: network.ssid,
enabled: network.enabled,
encryption: network.encryption,
})));
}
});
});
},
removeConfiguredWifiNetwork(ssid) {
return new Promise((resolve, reject) => {
exec(`wifisetup remove -ssid "${ssid}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error Code: ${error.code}, Error Signal: ${error.signal}`);
reject(stderr.toString());
} else {
resolve();
}
});
});
},
addWifiConfiguration(ssid, encryption, password) {
return new Promise((resolve, reject) => {
exec(`wifisetup add -ssid "${ssid}" -encr "${encryption}" -password "${password}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error Code: ${error.code}, Error Signal: ${error.signal}`);
reject(stderr.toString());
} else {
resolve();
}
});
});
}
}