forked from mirrors/amnezia-wg-easy
wip
This commit is contained in:
parent
d9901aa8a3
commit
0f220c1a78
14 changed files with 100 additions and 8 deletions
|
@ -3,6 +3,7 @@
|
|||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
|
||||
const debug = require('debug')('WireGuard');
|
||||
const uuid = require('uuid');
|
||||
const QRCode = require('qrcode');
|
||||
|
||||
|
@ -26,10 +27,12 @@ module.exports = class WireGuard {
|
|||
throw new Error('WG_HOST Environment Variable Not Set!');
|
||||
}
|
||||
|
||||
debug('Loading configuration...');
|
||||
let config;
|
||||
try {
|
||||
config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
|
||||
config = JSON.parse(config);
|
||||
debug('Configuration loaded');
|
||||
} catch (err) {
|
||||
config = {
|
||||
server: {
|
||||
|
@ -38,10 +41,14 @@ module.exports = class WireGuard {
|
|||
},
|
||||
clients: {},
|
||||
};
|
||||
await this.saveConfig();
|
||||
debug('New configuration saved');
|
||||
}
|
||||
|
||||
await this.__saveConfig(config);
|
||||
|
||||
debug('Starting...');
|
||||
await Util.exec('wg-quick up wg0');
|
||||
debug('Started');
|
||||
|
||||
return config;
|
||||
});
|
||||
|
@ -52,6 +59,10 @@ module.exports = class WireGuard {
|
|||
|
||||
async saveConfig() {
|
||||
const config = await this.getConfig();
|
||||
await this.__saveConfig(config);
|
||||
}
|
||||
|
||||
async __saveConfig(config) {
|
||||
let result = `
|
||||
# Note: Do not edit this file directly.
|
||||
# Your changes will be overwritten!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue