feat: add amneziawg support (#2102)

* feat: detect wireguard executable

* feat: add amneziawg-tools to container

* feat: enhance AWG detection and configuration handling

* refactor: change env name

* refactor: change env values
This commit is contained in:
Alexander Chepurnoy
2025-08-14 14:10:18 +07:00
committed by GitHub
parent c10daa2fd4
commit ef463d3d85
4 changed files with 49 additions and 10 deletions
+10
View File
@@ -12,6 +12,8 @@ export const OLD_ENV = {
PASSWORD_HASH: process.env.PASSWORD_HASH,
};
const OVERRIDE_AUTO_AWG = process.env.OVERRIDE_AUTO_AWG?.toLowerCase();
export const WG_ENV = {
/** UI is hosted on HTTP instead of HTTPS */
INSECURE: process.env.INSECURE === 'true',
@@ -19,6 +21,14 @@ export const WG_ENV = {
PORT: assertEnv('PORT'),
/** If IPv6 should be disabled */
DISABLE_IPV6: process.env.DISABLE_IPV6 === 'true',
/** Override automatic detection */
OVERRIDE_AUTO_AWG:
OVERRIDE_AUTO_AWG === ('wg' as const) ||
OVERRIDE_AUTO_AWG === ('awg' as const)
? OVERRIDE_AUTO_AWG
: undefined,
/** TODO: delete on next major version */
EXPERIMENTAL_AWG: process.env.EXPERIMENTAL_AWG === 'true',
};
export const WG_INITIAL_ENV = {
+25 -9
View File
@@ -9,6 +9,18 @@ type Options = {
enableIpv6?: boolean;
};
let wgExecutable: 'awg' | 'wg' = 'wg';
if (WG_ENV.EXPERIMENTAL_AWG) {
if (WG_ENV.OVERRIDE_AUTO_AWG !== undefined) {
wgExecutable = WG_ENV.OVERRIDE_AUTO_AWG;
} else {
wgExecutable = await exec('modinfo amneziawg')
.then(() => 'awg' as const)
.catch(() => 'wg' as const);
}
}
export const wg = {
generateServerPeer: (
client: Omit<ClientType, 'createdAt' | 'updatedAt'>,
@@ -107,37 +119,41 @@ Endpoint = ${userConfig.host}:${userConfig.port}`;
},
generatePrivateKey: () => {
return exec('wg genkey');
return exec(`${wgExecutable} genkey`);
},
getPublicKey: (privateKey: string) => {
return exec(`echo ${privateKey} | wg pubkey`, {
log: 'echo ***hidden*** | wg pubkey',
return exec(`echo ${privateKey} | ${wgExecutable} pubkey`, {
log: `echo ***hidden*** | ${wgExecutable} pubkey`,
});
},
generatePreSharedKey: () => {
return exec('wg genpsk');
return exec(`${wgExecutable} genpsk`);
},
up: (infName: string) => {
return exec(`wg-quick up ${infName}`);
return exec(`${wgExecutable}-quick up ${infName}`);
},
down: (infName: string) => {
return exec(`wg-quick down ${infName}`);
return exec(`${wgExecutable}-quick down ${infName}`);
},
restart: (infName: string) => {
return exec(`wg-quick down ${infName}; wg-quick up ${infName}`);
return exec(
`${wgExecutable}-quick down ${infName}; ${wgExecutable}-quick up ${infName}`
);
},
sync: (infName: string) => {
return exec(`wg syncconf ${infName} <(wg-quick strip ${infName})`);
return exec(
`${wgExecutable} syncconf ${infName} <(${wgExecutable}-quick strip ${infName})`
);
},
dump: async (infName: string) => {
const rawDump = await exec(`wg show ${infName} dump`, {
const rawDump = await exec(`${wgExecutable} show ${infName} dump`, {
log: false,
});