Browse Source

invalidate cache to make restoreConfig work

pull/1244/head
Bernd Storath 12 months ago
parent
commit
cc673785de
  1. 16
      src/server/utils/WireGuard.ts

16
src/server/utils/WireGuard.ts

@ -45,6 +45,8 @@ class WireGuard {
} }
debug('Loading configuration...'); debug('Loading configuration...');
// TODO: Better way to invalidate cache
this.#configCache = null;
try { try {
const config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8'); const config = await fs.readFile(path.join(WG_PATH, 'wg0.json'), 'utf8');
const parsedConfig = JSON.parse(config); const parsedConfig = JSON.parse(config);
@ -77,7 +79,7 @@ class WireGuard {
const config = await this.__buildConfig(); const config = await this.__buildConfig();
await this.__saveConfig(config); await this.__saveConfig(config);
await exec('wg-quick down wg0').catch(() => {}); await exec('wg-quick down wg0').catch(() => { });
await exec('wg-quick up wg0').catch((err) => { await exec('wg-quick up wg0').catch((err) => {
if ( if (
err && err &&
@ -130,9 +132,8 @@ PostDown = ${WG_POST_DOWN}
# Client: ${client.name} (${clientId}) # Client: ${client.name} (${clientId})
[Peer] [Peer]
PublicKey = ${client.publicKey} PublicKey = ${client.publicKey}
${ ${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : '' }AllowedIPs = ${client.address}/32`;
}AllowedIPs = ${client.address}/32`;
} }
debug('Config saving...'); debug('Config saving...');
@ -233,9 +234,8 @@ ${WG_MTU ? `MTU = ${WG_MTU}\n` : ''}\
[Peer] [Peer]
PublicKey = ${config.server.publicKey} PublicKey = ${config.server.publicKey}
${ ${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : '' }AllowedIPs = ${WG_ALLOWED_IPS}
}AllowedIPs = ${WG_ALLOWED_IPS}
PersistentKeepalive = ${WG_PERSISTENT_KEEPALIVE} PersistentKeepalive = ${WG_PERSISTENT_KEEPALIVE}
Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`; Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
} }
@ -387,7 +387,7 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
// Shutdown wireguard // Shutdown wireguard
async Shutdown() { async Shutdown() {
await exec('wg-quick down wg0').catch(() => {}); await exec('wg-quick down wg0').catch(() => { });
} }
} }

Loading…
Cancel
Save