Add environment variables to override admin panel interface settings

Co-authored-by: kaaax0815 <32197462+kaaax0815@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-14 13:01:39 +00:00
parent 5d6c35b183
commit e444936c04
5 changed files with 87 additions and 15 deletions
+22 -13
View File
@@ -14,8 +14,9 @@ class WireGuard {
*/
async saveConfig() {
const wgInterface = await Database.interfaces.get();
await this.#saveWireguardConfig(wgInterface);
await this.#syncWireguardConfig(wgInterface);
const wgInterfaceWithOverrides = applyInterfaceOverrides(wgInterface);
await this.#saveWireguardConfig(wgInterfaceWithOverrides);
await this.#syncWireguardConfig(wgInterfaceWithOverrides);
}
/**
@@ -151,6 +152,7 @@ class WireGuard {
async getClientConfiguration({ clientId }: { clientId: ID }) {
const wgInterface = await Database.interfaces.get();
const wgInterfaceWithOverrides = applyInterfaceOverrides(wgInterface);
const userConfig = await Database.userConfigs.get();
const client = await Database.clients.get(clientId);
@@ -159,9 +161,14 @@ class WireGuard {
throw new Error('Client not found');
}
return wg.generateClientConfig(wgInterface, userConfig, client, {
enableIpv6: !WG_ENV.DISABLE_IPV6,
});
return wg.generateClientConfig(
wgInterfaceWithOverrides,
userConfig,
client,
{
enableIpv6: !WG_ENV.DISABLE_IPV6,
}
);
}
async getClientQRCodeSVG({ clientId }: { clientId: ID }) {
@@ -217,25 +224,27 @@ class WireGuard {
Database.interfaces.update(wgInterface);
}
WG_DEBUG(`Starting Wireguard Interface ${wgInterface.name}...`);
await this.#saveWireguardConfig(wgInterface);
await wg.down(wgInterface.name).catch(() => {});
await wg.up(wgInterface.name).catch((err) => {
const wgInterfaceWithOverrides = applyInterfaceOverrides(wgInterface);
WG_DEBUG(`Starting Wireguard Interface ${wgInterfaceWithOverrides.name}...`);
await this.#saveWireguardConfig(wgInterfaceWithOverrides);
await wg.down(wgInterfaceWithOverrides.name).catch(() => {});
await wg.up(wgInterfaceWithOverrides.name).catch((err) => {
if (
err &&
err.message &&
err.message.includes(`Cannot find device "${wgInterface.name}"`)
err.message.includes(`Cannot find device "${wgInterfaceWithOverrides.name}"`)
) {
throw new Error(
`WireGuard exited with the error: Cannot find device "${wgInterface.name}"\nThis usually means that your host's kernel does not support WireGuard!`,
`WireGuard exited with the error: Cannot find device "${wgInterfaceWithOverrides.name}"\nThis usually means that your host's kernel does not support WireGuard!`,
{ cause: err.message }
);
}
throw err;
});
await this.#syncWireguardConfig(wgInterface);
WG_DEBUG(`Wireguard Interface ${wgInterface.name} started successfully.`);
await this.#syncWireguardConfig(wgInterfaceWithOverrides);
WG_DEBUG(`Wireguard Interface ${wgInterfaceWithOverrides.name} started successfully.`);
WG_DEBUG('Starting Cron Job...');
await this.startCronJob();