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", "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.authenticated = true;
req.session.save(); req.session.save();
debug(`New Session: ${req.session.id})`); console.log(`New Session: ${req.session.id})`);
})) }))
// WireGuard // WireGuard
@ -84,7 +84,7 @@ module.exports = class Server {
req.session.destroy(); req.session.destroy();
debug(`Deleted Session: ${sessionId}`); console.log(`Deleted Session: ${sessionId}`);
})) }))
.get('/api/wireguard/hardened', Util.promisify(async req => { .get('/api/wireguard/hardened', Util.promisify(async req => {
return WireGuard.areClientsHardened(); return WireGuard.areClientsHardened();
@ -138,7 +138,7 @@ module.exports = class Server {
})) }))
.listen(PORT, () => { .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!'); throw new Error('WG_HOST Environment Variable Not Set!');
} }
debug('Loading configuration...'); console.log('Loading configuration...');
let config; let config;
try { try {
config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8'); config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
config = JSON.parse(config); config = JSON.parse(config);
debug('Configuration loaded.'); console.log('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`, privateKey); const publicKey = await Util.exec(`echo ${privateKey} | wg pubkey`, privateKey);
@ -52,7 +52,7 @@ module.exports = class WireGuard {
}, },
clients: {}, clients: {},
}; };
debug('Configuration generated.'); console.log('Configuration generated.');
} }
await this.__saveConfig(config); await this.__saveConfig(config);
@ -110,20 +110,20 @@ PresharedKey = ${client.preSharedKey}
AllowedIPs = ${client.address}/32`; 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), { await fs.writeFile(path.join(WG_PATH, 'wg0.json'), JSON.stringify(config, false, 2), {
mode: 0o660, mode: 0o660,
}); });
await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result, { await fs.writeFile(path.join(WG_PATH, 'wg0.conf'), result, {
mode: 0o600, mode: 0o600,
}); });
debug('Config saved.'); console.log('Config saved.');
} }
async __syncConfig() { async __syncConfig() {
debug('Config syncing...'); console.log('Config syncing...');
await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)'); await Util.exec('wg syncconf wg0 <(wg-quick strip wg0)');
debug('Config synced.'); console.log('Config synced.');
} }
async getDns() { async getDns() {

Loading…
Cancel
Save