Browse Source

Logging

pull/238/head
joshuakraitberg 4 years ago
parent
commit
ce6309fe19
  1. 10
      package-lock.json
  2. 6
      src/lib/Server.js
  3. 14
      src/lib/WireGuard.js

10
package-lock.json

@ -1,4 +1,12 @@
{
"name": "wg-easy",
"version": "1.0.0",
"lockfileVersion": 1
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "wg-easy",
"version": "1.0.0"
}
}
}

6
src/lib/Server.js

@ -62,7 +62,7 @@ module.exports = class Server {
req.session.authenticated = true;
req.session.save();
debug(`New Session: ${req.session.id})`);
console.log(`New Session: ${req.session.id})`);
}))
// WireGuard
@ -84,7 +84,7 @@ module.exports = class Server {
req.session.destroy();
debug(`Deleted Session: ${sessionId}`);
console.log(`Deleted Session: ${sessionId}`);
}))
.get('/api/wireguard/hardened', Util.promisify(async req => {
return WireGuard.areClientsHardened();
@ -138,7 +138,7 @@ module.exports = class Server {
}))
.listen(PORT, () => {
debug(`Listening on http://0.0.0.0:${PORT}`);
console.log(`Listening on http://0.0.0.0:${PORT}`);
});
}

14
src/lib/WireGuard.js

@ -33,12 +33,12 @@ module.exports = class WireGuard {
throw new Error('WG_HOST Environment Variable Not Set!');
}
debug('Loading configuration...');
console.log('Loading configuration...');
let config;
try {
config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
config = JSON.parse(config);
debug('Configuration loaded.');
console.log('Configuration loaded.');
} catch (err) {
const privateKey = await Util.exec('wg genkey');
const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`, privateKey);
@ -52,7 +52,7 @@ module.exports = class WireGuard {
},
clients: {},
};
debug('Configuration generated.');
console.log('Configuration generated.');
}
await this.__saveConfig(config);
@ -110,20 +110,20 @@ PresharedKey = ${client.preSharedKey}
AllowedIPs = ${client.address}/32`;
}
debug('Config saving...');
console.log('Config saving...');
await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2), {
mode: 0o660,
});
await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result, {
mode: 0o600,
});
debug('Config saved.');
console.log('Config saved.');
}
async __syncConfig() {
debug('Config syncing...');
console.log('Config syncing...');
await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)');
debug('Config synced.');
console.log('Config synced.');
}
async getDns() {

Loading…
Cancel
Save