Update
This commit is contained in:
@ -1,20 +1,80 @@
|
||||
import {WiFiNetwork} from "./IPCConstants";
|
||||
import {spawn, exec} from 'node:child_process';
|
||||
import * as dns from "dns";
|
||||
import * as process from "process";
|
||||
import * as path from "path";
|
||||
|
||||
const wifiScan = require("node-wifi-scanner");
|
||||
|
||||
|
||||
export default class OSHandler {
|
||||
static getKnownWifis(): Promise<WiFiNetwork[]> {
|
||||
return new Promise<WiFiNetwork[]>((resolve, reject) => {
|
||||
exec("sudo touch /etc/wpa_supplicant/wpa_supplicant-monopoly.conf && sudo cat /etc/wpa_supplicant/wpa_supplicant-monopoly.conf", (err, stdout) => {
|
||||
if(err)
|
||||
return reject(err);
|
||||
|
||||
let lines = stdout.split("\n");
|
||||
let wifis: WiFiNetwork[] = [];
|
||||
|
||||
|
||||
let inBlock = false;
|
||||
let currentNetwork: WiFiNetwork = {ssid: "", psk: "", isSecured: false};
|
||||
for(let line of lines)
|
||||
{
|
||||
if(line.includes("network={"))
|
||||
inBlock = true;
|
||||
|
||||
if(line.includes("}")) {
|
||||
inBlock = false;
|
||||
currentNetwork.isSecured = !!currentNetwork.psk;
|
||||
if(currentNetwork.ssid)
|
||||
wifis.push(currentNetwork);
|
||||
currentNetwork.ssid = "";
|
||||
currentNetwork.psk = "";
|
||||
currentNetwork.isSecured = false;
|
||||
}
|
||||
|
||||
if(inBlock && line.includes("ssid"))
|
||||
currentNetwork.ssid = line.substring(line.indexOf('"')+1, line.lastIndexOf('"'));
|
||||
if(inBlock && line.includes("psk"))
|
||||
currentNetwork.psk = line.substring(line.indexOf('"')+1, line.lastIndexOf('"'));
|
||||
}
|
||||
|
||||
resolve(wifis);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
static addWifi(wifi: string, passkey: string | null) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
let p = path.resolve(process.cwd(), "/scripts/addWifi.sh");
|
||||
exec(p + ` -s "${wifi}" -p "${passkey}"`, (err, stdout) => {
|
||||
if(err)
|
||||
return reject(err);
|
||||
if(stdout == "ok")
|
||||
resolve();
|
||||
else
|
||||
reject("no-return");
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
static connectToWifi(ssid: string)
|
||||
{
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
|
||||
let p = path.resolve(process.cwd(), "/scripts/connectToWifi.sh");
|
||||
exec(p + ``)
|
||||
});
|
||||
}
|
||||
|
||||
static disableAllWifis() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
static addWifi(wifi: WiFiNetwork, passkey: string|null) {
|
||||
return new Promise<WiFiNetwork>((resolve, reject) => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
static scanWifis() {
|
||||
return new Promise<WiFiNetwork[]>((resolve, reject) => {
|
||||
@ -66,7 +126,6 @@ export default class OSHandler {
|
||||
if (x.ssid == ele.ssid) {
|
||||
return i == index;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
@ -78,11 +137,6 @@ export default class OSHandler {
|
||||
})
|
||||
}
|
||||
|
||||
static disableAllWifis() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
static checkForSudo() {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
@ -102,12 +156,12 @@ export default class OSHandler {
|
||||
|
||||
static checkForInternet() {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
exec("ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error", (error, stdout, stderr) => {
|
||||
if (error)
|
||||
dns.lookup("google.de", 4, (err, address, family) => {
|
||||
if (err)
|
||||
resolve(false);
|
||||
else
|
||||
resolve(stdout == "1");
|
||||
});
|
||||
resolve(true);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user