feat: load configuration from file

* import json config file & update the config (restore)
* export the config and save it to json file (backup)
This commit is contained in:
tetuaoro 2024-07-09 17:06:12 +02:00 committed by pheiduck
parent 94d87681c3
commit 03b7d8e537
6 changed files with 134 additions and 39 deletions

View file

@ -111,7 +111,7 @@ PostDown = ${WG_POST_DOWN}
[Peer]
PublicKey = ${client.publicKey}
${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
}AllowedIPs = ${client.address}/32`;
}AllowedIPs = ${client.address}/32`;
}
debug('Config saving...');
@ -206,7 +206,7 @@ ${WG_MTU ? `MTU = ${WG_MTU}\n` : ''}\
[Peer]
PublicKey = ${config.server.publicKey}
${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
}AllowedIPs = ${WG_ALLOWED_IPS}
}AllowedIPs = ${WG_ALLOWED_IPS}
PersistentKeepalive = ${WG_PERSISTENT_KEEPALIVE}
Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
}
@ -319,6 +319,17 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
await this.saveConfig();
}
async uploadConfiguration(config) {
const _config = JSON.parse(config);
await this.__saveConfig(_config);
await this.__syncConfig();
}
async downloadConfiguration() {
const config = await this.getConfig();
return JSON.stringify(config, null, 2);
}
// Shutdown wireguard
async Shutdown() {
await Util.exec('wg-quick down wg0').catch(() => { });