Browse Source

better logging (fixes #100)

pull/114/head
Emile Nijssen 3 years ago
parent
commit
c19cb72b6d
  1. 9
      src/lib/Util.js
  2. 8
      src/lib/WireGuard.js

9
src/lib/Util.js

@ -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 // eslint-disable-next-line no-console
console.log(`$ ${cmd}`); console.log(`$ ${cmd}`);
}
if (process.platform !== 'linux') { if (process.platform !== 'linux') {
return ''; return '';

8
src/lib/WireGuard.js

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

Loading…
Cancel
Save