better logging (fixes #100)

This commit is contained in:
Emile Nijssen 2021-11-12 21:20:28 +00:00
parent 5895b986fc
commit c19cb72b6d
2 changed files with 18 additions and 7 deletions

View File

@ -52,9 +52,16 @@ module.exports = class Util {
};
}
static async exec(cmd) {
static async exec(cmd, {
log = true,
} = {}) {
if (typeof log === 'string') {
// eslint-disable-next-line no-console
console.log(`$ ${log}`);
} else if (log === true) {
// eslint-disable-next-line no-console
console.log(`$ ${cmd}`);
}
if (process.platform !== 'linux') {
return '';

View File

@ -37,7 +37,9 @@ module.exports = class WireGuard {
debug('Configuration loaded.');
} catch (err) {
const privateKey = await Util.exec('wg genkey');
const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`);
const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`, {
log: `echo ***hidden*** | wg pubkey`
});
const address = WG_DEFAULT_ADDRESS.replace('x', '1');
config = {
@ -127,7 +129,9 @@ AllowedIPs = ${client.address}/32`;
}));
// Loop WireGuard status
const dump = await Util.exec('wg show wg0 dump');
const dump = await Util.exec('wg show wg0 dump', {
log: false,
});
dump
.trim()
.split('\n')